pclib  2.3.2
Lightweight PHP framework
Public Member Functions | Data Fields | Protected Member Functions
App Class Reference

Gives global access to web application. More...

Inheritance diagram for App:
BaseObject

Public Member Functions

 __construct ($name)
 Load config and sessions, read route. More...
 
 setContent ($content)
 Set content of the webpage to be displayed. More...
 
 setLayout ($path)
 Set layout template of the application. More...
 
 log ($category, $message_id, $message=null, $item_id=null)
 Store message to log, using application Logger. More...
 
 setService ($name, IService $service)
 Register application service such as Db or Logger. More...
 
 addConfig ($source)
 Load application configuration. More...
 
 environmentIp (array $env)
 Set $app->environment variable by server ip-address. More...
 
 redirect ($route, $code=null)
 Perform redirect to $route. More...
 
 setLanguage ($language, $useDefault=true, $useFile=true)
 Initialize application Translator and enable translation to the $language. More...
 
 t ($s)
 Translate string $s. More...
 
 message ($message, $cssClass=null)
 Display flash message. More...
 
 warning ($message, $cssClass=null)
 Display warning message. More...
 
 error ($message, $cssClass=null)
 Display error message and exit application. More...
 
 httpError ($code, $message, $cssClass=null)
 Display error message with http response code header and exit application. More...
 
 getSession ($name, $ns=null)
 Get application session variable. More...
 
 setSession ($name, $value, $ns=null)
 Set application session variable. More...
 
 deleteSession ($name=null, $ns=null)
 Delete application session variable. More...
 
 run ($rs=null)
 Execute method of the controller. More...
 
 out ()
 Display webpage. More...
 
- Public Member Functions inherited from BaseObject
 loadDefaults ($className=null)
 Load default parameters of class $className into object instance.
 
 setProperties (array $defaults)
 Set public properties of object from the array. More...
 
 addEvent ($name, $callback)
 Add event handler to $object->$name property. More...
 
 toArray ()
 Convert object to array. More...
 

Data Fields

 $name
 Name of the aplication.
 
 $config = array()
 Application configuration. More...
 
 $paths
 application base paths (webroot, basedir, baseurl and pclib)
 
 $layout
 Master template of the website. More...
 
 $services = array()
 Storage of the global services - Db, Auth, Logger etc. More...
 
 $environment
 Current environment (such as 'develop','test','production'). More...
 
 $debugMode = false
 Enabling debugMode will display debug-toolbar. More...
 
 $errorHandler
 var ErrorHandler
 
 $onError
 Occurs when App.error() method is called. More...
 
 $onBeforeRun
 Occurs before loading and running Controller. More...
 
 $onAfterRun
 Occurs after Controller has been executed. More...
 
 $onBeforeOut
 Occurs before application output. More...
 
 $onAfterOut
 Occurs after application output. More...
 
- Data Fields inherited from BaseObject
 $onNewInstance
 Occurs when new instance of the class is created. More...
 
 $onMissingMethod
 Occurs when called method does not exist. More...
 
 $serviceLocator
 var function() Return service object when requested with service(). More...
 

Protected Member Functions

 createDefaultService ($serviceName)
 Return default service object or null, if service must be created by user. More...
 
- Protected Member Functions inherited from BaseObject
 fireEvent ($name, array $args=array())
 Run all event handlers in $object->$name property. More...
 
 service ($service, $default=null)
 Try acquire $service and load it into property $this->$service. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from BaseObject
static defaults ()
 Set or retireve default parameters of the object. More...
 

Detailed Description

Gives global access to web application.

It is facade for application services and general datastructures. Features:

Constructor & Destructor Documentation

__construct (   $name)

Load config and sessions, read route.

Parameters
string$nameUnique name of the application.

Member Function Documentation

addConfig (   $source)

Load application configuration.

$source must be valid php-file which containing array $config or $config array itself. Can be called more than once - configurations will be merged. Set $config variable.

Parameters
string | array$sourcePath to configuration file or array of config-parameters.
createDefaultService (   $serviceName)
protected

Return default service object or null, if service must be created by user.

Parameters
string$serviceName
Returns
IService $service
deleteSession (   $name = null,
  $ns = null 
)

Delete application session variable.

Without parameters, it will delete whole application session.

See also
getSession()
Parameters
string$namename of variable
string$ns(optional) Namespace
environmentIp ( array  $env)

Set $app->environment variable by server ip-address.

Parameters
array$envArray of ipAddress:environmentName pairs.
error (   $message,
  $cssClass = null 
)

Display error message and exit application.

See also
message()
getSession (   $name,
  $ns = null 
)

Get application session variable.

Session variables are stored in their own namespace $ns. By default it is application name, so sessions for different applications does not collide. Variable name can be plain: 'user' or with group: 'pclib.user'. All system variables uses group 'pclib'.

Parameters
string$nameVariable name.
string$ns(optional) Namespace.
Returns
mixed Session variable value.
httpError (   $code,
  $message,
  $cssClass = null 
)

Display error message with http response code header and exit application.

See also
message()
log (   $category,
  $message_id,
  $message = null,
  $item_id = null 
)

Store message to log, using application Logger.

If application has no Logger service, this method does nothing. For the parameters see Logger::log()

message (   $message,
  $cssClass = null 
)

Display flash message.

Layout template must contains messages tag. In message %s arguments can be used. Messages are also translated with Translator. You can call message() even before redirect. Example: $app->message('File %s not found', $fileName);

Parameters
string$message
string$cssClassCss-class of the message div
mixed$argsVariable number of message arguments
out ( )

Display webpage.

Get $layout template populated with content and display it. You must setup layout and content first.

See also
setContent(), setLayout()
redirect (   $route,
  $code = null 
)

Perform redirect to $route.

Example: $app->redirect("products/edit/id:$id");

Parameters
string | array$route
htttpcode (e.g. 301 Moved Permanently) See also PClib route
run (   $rs = null)

Execute method of the controller.

Without parameters, route is read from current url. Route 'products/add' means: call method ProductsController->addAction();

Parameters
string$rsRoute string. See PClib route
setContent (   $content)

Set content of the webpage to be displayed.

It replaces {CONTENT} placeholder in layout. Call out() for displaying website with content.

Parameters
string$contentContent placed into layout.
setLanguage (   $language,
  $useDefault = true,
  $useFile = true 
)

Initialize application Translator and enable translation to the $language.

You can access current language as $app->language.

Parameters
string$languageLanguage code such as 'en' or 'source'.
bool$useDefaultPreload default texts?
bool$useFileTry load texts from php file?
setLayout (   $path)

Set layout template of the application.

Any page added with function setContent() will be put inside layout template. Example: $app->setLayout('tpl/website.tpl');

Parameters
string$pathPath to website template.
setService (   $name,
IService  $service 
)

Register application service such as Db or Logger.

Services can be accessed and used by other objects. You can access service as $app->serviceName e.g. $app->db->select("table").

Parameters
IService$serviceService object.
setSession (   $name,
  $value,
  $ns = null 
)

Set application session variable.

See also
getSession()
Parameters
string$namename of session variable
mixed$valuevalue of variable
string$ns(optional) Namespace
t (   $s)

Translate string $s.

Uses Translator service if present, otherwise return unmodified $s. Example: $app->t('File %s not found.', $fileName);

Parameters
string$sString to be translated.
mixed$argsVariable number of arguments.
warning (   $message,
  $cssClass = null 
)

Display warning message.

Deprecated:
Use app->message($message, 'warning');
See also
message()

Field Documentation

$config = array()

Application configuration.

$debugMode = false

Enabling debugMode will display debug-toolbar.

$environment

Current environment (such as 'develop','test','production').

$layout

Master template of the website.

See also
setLayout()
$onAfterOut

Occurs after application output.

$onAfterRun

Occurs after Controller has been executed.

$onBeforeOut

Occurs before application output.

$onBeforeRun

Occurs before loading and running Controller.

$onError

Occurs when App.error() method is called.

$services = array()

Storage of the global services - Db, Auth, Logger etc.


The documentation for this class was generated from the following file: