final class 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 Application $_app
protected Config_Abstract $config
protected 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 $envrion = null)

No description

run()

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

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

This method is typically used to run \Yaf\Application in a crontab work.

static Application|null
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(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

clearLastError()

No description

__destruct()

No description

Details

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

No description

Parameters

string|array $config

A ini config file path, or a config array

If is a ini config file, there should be a section named as the one defined by yaf.environ, which is "product" by default.


Note:

If you use a ini configuration file as your application's config container. you would open the yaf.cache_config to improve performance.

And the config entry(and there default value) list blow:

Example #1 A ini config file example
[product]
;this one should always be defined, and have no default value
application.directory=APPLICATION_PATH

;following configs have default value, you may no need to define them
application.library = APPLICATION_PATH . "/library"
application.dispatcher.throwException=1
application.dispatcher.catchException=1

application.baseUri=""

;the php script ext name
ap.ext=php

;the view template ext name
ap.view.ext=phtml

ap.dispatcher.defaultModule=Index
ap.dispatcher.defaultController=Index
ap.dispatcher.defaultAction=index

;defined modules
ap.modules=Index

string $envrion

Which section will be loaded as the final config

Exceptions

StartupError

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.

Exceptions

StartupError

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

static Application|null app()

Retrieve the \Yaf\Application instance, alternatively, we also could use \Yaf\Dispatcher::getApplication().

Return Value

Application|null

an \Yaf\Application instance, if no \Yaf\Application initialized before, NULL will be returned.

string environ()

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

Return Value

string

Application bootstrap(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

Bootstrap_Abstract $bootstrap

A \Yaf\Bootstrap_Abstract instance

Return Value

Application

Config_Abstract getConfig()

No description

Return Value

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

Dispatcher getDispatcher()

No description

Return Value

Dispatcher

Application setAppDirectory(string $directory)

Since: 2.1.4

Change the application directory

Parameters

string $directory

Return Value

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

clearLastError()

Since: 2.1.2

No description

__destruct()

No description