SlaxWeb Framework
 All Classes Namespaces Functions Variables Pages
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
SlaxWeb\Output\Manager Class Reference

Public Member Functions

 __construct (Logger $logger, Response $response, array $settings, array $errorTpl=[])
 
 __call (string $name, array $args)
 
 setEnabled (bool $enabled=true)
 
 setHandler (AbstractHandler $handler)
 
 setHandlerGetter (callable $getter)
 
 shutdownHandler ()
 
 errorHandler (int $code, string $error, string $file, int $line, array $context=[])
 

Public Attributes

 E_WARNING
 

Protected Member Functions

 init ()
 
 getHandler ()
 

Protected Attributes

 $logger = null
 
 $response = null
 
 $enabled = false
 
 $allowOutput = true
 
 $env = ""
 
 $handler = null
 
 $handlerGetter = null
 
 $statusCode = 0
 
 $levels
 
 $errorTpl = []
 

Constructor & Destructor Documentation

SlaxWeb\Output\Manager::__construct ( Logger  $logger,
Response  $response,
array  $settings,
array  $errorTpl = [] 
)

Class constructor

Copy dependencies to protected class properties, and parse the configuration array.

Parameters
\Psr\Log\LoggerInterface$loggerLogger instance
\SlaxWeb\Router\Response$responseResponse object
array$settingsOutput manager settings array
array$errorTplError templates for error output, default []

Member Function Documentation

SlaxWeb\Output\Manager::__call ( string  $name,
array  $args 
)

Magic call

Forward all calls to the Output Handler. Once this call has been made the handler is set to the Manager and can no longer be changed.

Parameters
string$nameName of the method to call
array$argsArguments for the method call
Returns
mixed
SlaxWeb\Output\Manager::errorHandler ( int  $code,
string  $error,
string  $file,
int  $line,
array  $context = [] 
)

Error handler

The classic PHP error handler. It will load the "style" template set in the "errorTpl" protected property only once on the first run, to ensure any styling template is output only once. If the "template" item is not found in the "errorTpl" protected property array, then the method will return bool(false) and regular PHP error handling will proceed. If the environment is not set to "development", method will return bool(true), halting any error output. When set to "development", and the "template" item being set, the template will be loaded with the error parameters.

Parameters
int$codeError code
string$errorError message
string$fileFile in which the error occured
int$lineLine at which the error occured
array$contextError context pointing to the active symbol table
Returns
bool
Todo:
log the error in appropriate level
SlaxWeb\Output\Manager::getHandler ( )
protected

Get handler

Tries to obtain an Output Handler, either directly from the '$handler' property, or through the getter.

Returns
SlaxWeb\Output\Manager::init ( )
protected

Initialise manager

Registers a shutdown handler function, and a error handler function for handling execution termination, and allows for the desired output. After the handlers are registered, output buffering is started.

Returns
void
SlaxWeb\Output\Manager::setEnabled ( bool  $enabled = true)

Set enabled

Sets the enabled flag to on or off, depending on the input parameter. When set to true, the output manager will be enabled.

Parameters
bool$enabledEnabled flag, default bool(true)
Returns
self
SlaxWeb\Output\Manager::setHandler ( AbstractHandler  $handler)

Set Handler

Sets the output handler instance to the Manager. The handler must implement the to be accepted by the method. Returns an instance of itself.

Parameters
\SlaxWeb\Output\AbstractHandler$handlerHandler instance
Returns
self
SlaxWeb\Output\Manager::setHandlerGetter ( callable  $getter)

Set Handler Getter

Sets a callable as the handler getter. The callable will be called the first time when the handler is required. This can happen when an access to the handler through magic '__call' method is made, or when the execution is shutting down and the shutdown handler will try and render the handlers contents, if enabled. Returns an instance of itself.

Parameters
callable$getterHandler getter callable
Returns
self
SlaxWeb\Output\Manager::shutdownHandler ( )

Shutdown handler

Shutdown handler handles output for a specified mode in the Output Manager. This method is called by PHP automatically at end of execution, and should never be called directly. If the Output component is not enabled, it will not attempt to generate output for the set mode.

The method also catches fatal errors and forwards them to the error handler method.

Returns
void

Member Data Documentation

SlaxWeb\Output\Manager::$levels
protected
Initial value:
= [
E_ERROR => "Error"
SlaxWeb\Output\Manager::E_WARNING
Initial value:
=> "Warning",
E_PARSE => "Parsing Error",
E_NOTICE => "Notice",
E_CORE_ERROR => "Core Error",
E_CORE_WARNING => "Core Warning",
E_COMPILE_ERROR => "Compile Error",
E_COMPILE_WARNING => "Compile Warning",
E_USER_ERROR => "User Error",
E_USER_WARNING => "User Warning",
E_USER_NOTICE => "User Notice",
E_STRICT => "Runtime Notice"
]

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