pclib  3.0.0
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)
 Initialize application Translator and enable translation to the $language. More...
 
 path ($path)
 Replace path variables e.g. More...
 
 text ($s)
 Translate string $s. More...
 
 message ($message, $cssClass=null)
 Display flash 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...
 
 toArray ()
 Convert object to array. More...
 

Data Fields

 $name
 Name of the aplication.
 
 $config = array()
 Application configuration.
 
 $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.
 
 $environment = ''
 Current environment (such as 'develop','test','production').
 
 $debugMode = false
 Enabling debugMode will display debug-toolbar.
 
 $errorHandler
 var ErrorHandler
 
- Data Fields inherited from BaseObject
 $serviceLocator
 var function() Return service object when requested with service().
 

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
 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()

__construct (   $name)

Load config and sessions, read route.

Parameters
string$nameUnique name of the application.

Member Function Documentation

◆ addConfig()

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()

createDefaultService (   $serviceName)
protected

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

Parameters
string$serviceName
Returns
IService $service

◆ deleteSession()

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()

environmentIp ( array  $env)

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

Parameters
array$envArray of ipAddress:environmentName pairs.

◆ error()

error (   $message,
  $cssClass = null 
)

Display error message and exit application.

See also
message()

◆ getSession()

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()

httpError (   $code,
  $message,
  $cssClass = null 
)

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

See also
message()

◆ log()

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 (   $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()

out ( )

Display webpage.

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

See also
setContent(), setLayout()

◆ path()

path (   $path)

Replace path variables e.g.

{basedir}

◆ redirect()

redirect (   $route,
  $code = null 
)

Perform redirect to $route.

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

Parameters
string | array$route
httpcode (e.g. 301 Moved Permanently) See also PClib route

◆ run()

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()

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()

setLanguage (   $language)

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'.

◆ setLayout()

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()

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()

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

◆ text()

text (   $s)

Translate string $s.

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

Parameters
string$sString to be translated.
mixed$argsVariable number of arguments.

Field Documentation

◆ $layout

$layout

Master template of the website.

See also
setLayout()

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