final class Yaf_Application (View source)

Yaf_Application provides a bootstrapping facility for applications which provides reusable resources, common- and module-based bootstrap classes and dependency checking.


Note:

Yaf_Application implements the singleton pattern, and Yaf_Application can not be serialized or un-serialized which will cause problem when you try to use PHPUnit to write some test case for Yaf.
You may use @backupGlobals annotation of PHPUnit to control the backup and restore operations for global variables. thus can solve this problem.

Properties

static protected Yaf_Application $_app
protected Yaf_Config_Abstract $config
protected Yaf_Dispatcher $dispatcher
protected array $_modules
protected string $_running
protected string $_environ
protected int Since: 2.1.2
$_err_no
protected string Since: 2.1.2
$_err_msg

Methods

__construct(string|array $config, string $environ = null)

No description

getInstance()

No description

void
run()

Run a Yaf_Application, let the Yaf_Application accept a request, and route the request, dispatch to controller/action, and render response.

void
execute(callable $entry, string ...$_)

This method is typically used to run Yaf_Application in a crontab work.

static Yaf_Application
app()

Retrieve the Yaf_Application instance, alternatively, we also could use Yaf_Dispatcher::getApplication().

string
environ()

Retrieve environ which was defined in yaf.environ which has a default value "product".

bootstrap(Yaf_Bootstrap_Abstract $bootstrap = null)

Run a Bootstrap, all the methods defined in the Bootstrap and named with prefix "_init" will be called according to their declaration order, if the parameter bootstrap is not supplied, Yaf will look for a Bootstrap under application.directory.

getConfig()

No description

array
getModules()

Get the modules list defined in config, if no one defined, there will always be a module named "Index".

getDispatcher()

No description

setAppDirectory(string $directory)

Change the application directory

string
getAppDirectory()

No description

int
getLastErrorNo()

No description

string
getLastErrorMsg()

No description

void
clearLastError()

No description

__destruct()

No description

Details

__construct(string|array $config, string $environ = null)

No description

Parameters

string|array $config

A ini config file path, or a config array

string $environ

Which section will be loaded as the final config

Exceptions

Yaf_Exception_StartupError

Yaf_Application getInstance()

No description

Return Value

Yaf_Application

void run()

Run a Yaf_Application, let the Yaf_Application accept a request, and route the request, dispatch to controller/action, and render response.

return response to client finally.

Return Value

void

Exceptions

Yaf_Exception_StartupError

void execute(callable $entry, string ...$_)

This method is typically used to run Yaf_Application in a crontab work.

Make the crontab work can also use the autoloader and Bootstrap mechanism.

Parameters

callable $entry

a valid callback

string ...$_

parameters will pass to the callback

Return Value

void

static Yaf_Application app()

Retrieve the Yaf_Application instance, alternatively, we also could use Yaf_Dispatcher::getApplication().

Return Value

Yaf_Application

string environ()

Retrieve environ which was defined in yaf.environ which has a default value "product".

Return Value

string

Yaf_Application bootstrap(Yaf_Bootstrap_Abstract $bootstrap = null)

Run a Bootstrap, all the methods defined in the Bootstrap and named with prefix "_init" will be called according to their declaration order, if the parameter bootstrap is not supplied, Yaf will look for a Bootstrap under application.directory.

Parameters

Yaf_Bootstrap_Abstract $bootstrap

A Yaf_Bootstrap_Abstract instance

Return Value

Yaf_Application

Yaf_Config_Abstract getConfig()

No description

Return Value

Yaf_Config_Abstract

array getModules()

Get the modules list defined in config, if no one defined, there will always be a module named "Index".

Return Value

array

Yaf_Dispatcher getDispatcher()

No description

Return Value

Yaf_Dispatcher

Yaf_Application setAppDirectory(string $directory)

Since: 2.1.4

Change the application directory

Parameters

string $directory

Return Value

Yaf_Application

string getAppDirectory()

Since: 2.1.4

No description

Return Value

string

int getLastErrorNo()

Since: 2.1.2

No description

Return Value

int

string getLastErrorMsg()

Since: 2.1.2

No description

Return Value

string

void clearLastError()

Since: 2.1.2

No description

Return Value

void

__destruct()

No description