PHP Class PPI\Framework\App

This class sets various app settings, and allows you to override classes used in the bootup process.
Author: Paul Dragoonis ([email protected])
Author: Vítor Brandão ([email protected])
Inheritance: implements PPI\Framework\AppInterface
Datei anzeigen Open project: ppi/framework Class Usage Examples

Protected Properties

Property Type Description
$booted boolean
$configManager PPI\Framework\Config\ConfigManager Configuration loader.
$debug boolean
$environment string Application environment: "dev|development" vs "prod|production".
$errorReportingLevel
$logger Psr\Log\LoggerInterface
$matchedRoute null | array
$moduleManager Zend\ModuleManager\ModuleManager The Module Manager.
$name string
$resolver PPI\Framework\Module\Controller\ControllerResolver
$rootDir null | string Path to the application root dir aka the "app" directory.
$serviceManager PPI\Framework\ServiceManager\ServiceManager Service Manager.
$startTime float Unix timestamp with microseconds.

Public Methods

Method Description
__clone ( )
__construct ( array $options = [] ) App constructor.
boot ( ) Run the boot process, load our modules and their dependencies.
dispatch ( PPI\Framework\Http\Request $request, PPI\Framework\Http\Response $response ) : PPI\Framework\Http\Response Decide on a route to use and dispatch our module's controller action.
getCacheDir ( ) : string Gets the cache directory.
getCharset ( ) : string Gets the charset of the application.
getConfig ( ) : array | object Returns the application configuration.
getConfigManager ( ) : PPI\Framework\Config\ConfigManager Returns a ConfigManager instance.
getContainer ( ) : null | PPI\Framework\ServiceManager\ServiceManager
getEnvironment ( ) : string Get the environment mode the application is in.
getLogDir ( ) : string Gets the log directory.
getModuleManager ( ) : Zend\ModuleManager\ModuleManager Returns the Module Manager.
getModules ( ) : array Get an array of the loaded modules.
getName ( ) : string Gets the name of the application.
getRootDir ( ) : string Gets the application root dir.
getServiceManager ( ) : PPI\Framework\ServiceManager\ServiceManager Get the service manager.
getStartTime ( ) : integer Gets the request start time (not available if debug is disabled).
getVersion ( ) : string Gets the version of the application.
isDebug ( ) : boolean Checks if debug mode is enabled.
isEnvironment ( $env ) : boolean
loadConfig ( $resource, null $type = null ) : App Loads a configuration file or PHP array.
locateResource ( string $name, string $dir = null, boolean $first = true ) : string | array
run ( PPI\Framework\Http\Request $request = null, PPI\Framework\Http\Response $response = null ) : PPI\Framework\Http\Response Run the application and send the response.
serialize ( ) : string
setSymfonyKernel ( Symfony\Component\HttpKernel\KernelInterface $kernel )
unserialize ( $data )

Protected Methods

Method Description
buildServiceManager ( ) : PPI\Framework\ServiceManager\ServiceManager Creates and initializes a ServiceManager instance.
getAppParameters ( ) : array Returns the application parameters.
getEnvParameters ( ) : array Gets the environment parameters.
handleRouting ( PPI\Framework\Http\Request $request ) : array Perform the matching of a route and return a set of routing parameters if a valid one is found.
log ( mixed $level, string $message, array $context = [] ) Logs with an arbitrary level.

Method Details

__clone() public method

public __clone ( )

__construct() public method

App constructor.
public __construct ( array $options = [] )
$options array

boot() public method

This method is automatically called by dispatch(), but you can use it to build all services when not handling a request.
public boot ( )

buildServiceManager() protected method

Creates and initializes a ServiceManager instance.
protected buildServiceManager ( ) : PPI\Framework\ServiceManager\ServiceManager
return PPI\Framework\ServiceManager\ServiceManager The compiled service manager

dispatch() public method

Decide on a route to use and dispatch our module's controller action.
public dispatch ( PPI\Framework\Http\Request $request, PPI\Framework\Http\Response $response ) : PPI\Framework\Http\Response
$request PPI\Framework\Http\Request
$response PPI\Framework\Http\Response
return PPI\Framework\Http\Response

getAppParameters() protected method

Returns the application parameters.
protected getAppParameters ( ) : array
return array An array of application parameters

getCacheDir() public method

Gets the cache directory.
public getCacheDir ( ) : string
return string The cache directory

getCharset() public method

Gets the charset of the application.
public getCharset ( ) : string
return string The charset

getConfig() public method

Returns the application configuration.
public getConfig ( ) : array | object
return array | object

getConfigManager() public method

Returns a ConfigManager instance.
public getConfigManager ( ) : PPI\Framework\Config\ConfigManager
return PPI\Framework\Config\ConfigManager

getContainer() public method

public getContainer ( ) : null | PPI\Framework\ServiceManager\ServiceManager
return null | PPI\Framework\ServiceManager\ServiceManager

getEnvParameters() protected method

Only the parameters starting with "PPI__" are considered.
protected getEnvParameters ( ) : array
return array An array of parameters

getEnvironment() public method

Get the environment mode the application is in.
public getEnvironment ( ) : string
return string The current environment

getLogDir() public method

Gets the log directory.
public getLogDir ( ) : string
return string The log directory

getModuleManager() public method

Returns the Module Manager.
public getModuleManager ( ) : Zend\ModuleManager\ModuleManager
return Zend\ModuleManager\ModuleManager

getModules() public method

Get an array of the loaded modules.
public getModules ( ) : array
return array An array of Module objects, keyed by module name

getName() public method

Gets the name of the application.
public getName ( ) : string
return string The application name

getRootDir() public method

Gets the application root dir.
public getRootDir ( ) : string
return string The application root dir

getServiceManager() public method

Get the service manager.
public getServiceManager ( ) : PPI\Framework\ServiceManager\ServiceManager
return PPI\Framework\ServiceManager\ServiceManager

getStartTime() public method

Gets the request start time (not available if debug is disabled).
public getStartTime ( ) : integer
return integer The request start timestamp

getVersion() public method

Gets the version of the application.
public getVersion ( ) : string
return string The application version

handleRouting() protected method

Otherwise exceptions get thrown.
protected handleRouting ( PPI\Framework\Http\Request $request ) : array
$request PPI\Framework\Http\Request
return array

isDebug() public method

Checks if debug mode is enabled.
public isDebug ( ) : boolean
return boolean true if debug mode is enabled, false otherwise

isEnvironment() public method

public isEnvironment ( $env ) : boolean
$env
return boolean

loadConfig() public method

Loads a configuration file or PHP array.
public loadConfig ( $resource, null $type = null ) : App
$resource
$type null
return App The current instance

locateResource() public method

See also: PPI\Framework\Module\ModuleManager::locateResource()
public locateResource ( string $name, string $dir = null, boolean $first = true ) : string | array
$name string A resource name to locate
$dir string A directory where to look for the resource first
$first boolean Whether to return the first path or paths for all matching bundles
return string | array The absolute path of the resource or an array if $first is false

log() protected method

Logs with an arbitrary level.
protected log ( mixed $level, string $message, array $context = [] )
$level mixed
$message string
$context array

run() public method

Run the application and send the response.
public run ( PPI\Framework\Http\Request $request = null, PPI\Framework\Http\Response $response = null ) : PPI\Framework\Http\Response
$request PPI\Framework\Http\Request
$response PPI\Framework\Http\Response
return PPI\Framework\Http\Response

serialize() public method

public serialize ( ) : string
return string

setSymfonyKernel() public method

public setSymfonyKernel ( Symfony\Component\HttpKernel\KernelInterface $kernel )
$kernel Symfony\Component\HttpKernel\KernelInterface

unserialize() public method

public unserialize ( $data )

Property Details

$booted protected_oe property

protected bool $booted
return boolean

$configManager protected_oe property

Configuration loader.
protected ConfigManager,PPI\Framework\Config $configManager
return PPI\Framework\Config\ConfigManager

$debug protected_oe property

protected bool $debug
return boolean

$environment protected_oe property

Application environment: "dev|development" vs "prod|production".
protected string $environment
return string

$errorReportingLevel protected_oe property

protected $errorReportingLevel

$logger protected_oe property

protected LoggerInterface,Psr\Log $logger
return Psr\Log\LoggerInterface

$matchedRoute protected_oe property

protected null|array $matchedRoute
return null | array

$moduleManager protected_oe property

The Module Manager.
protected ModuleManager,Zend\ModuleManager $moduleManager
return Zend\ModuleManager\ModuleManager

$name protected_oe property

protected string $name
return string

$resolver protected_oe property

protected ControllerResolver,PPI\Framework\Module\Controller $resolver
return PPI\Framework\Module\Controller\ControllerResolver

$rootDir protected_oe property

Path to the application root dir aka the "app" directory.
protected null|string $rootDir
return null | string

$serviceManager protected_oe property

Service Manager.
protected ServiceManager,PPI\Framework\ServiceManager $serviceManager
return PPI\Framework\ServiceManager\ServiceManager

$startTime protected_oe property

Unix timestamp with microseconds.
protected float $startTime
return float