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 = [] | |
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.
\Psr\Log\LoggerInterface | $logger | Logger instance |
\SlaxWeb\Router\Response | $response | Response object |
array | $settings | Output manager settings array |
array | $errorTpl | Error templates for error output, default [] |
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.
string | $name | Name of the method to call |
array | $args | Arguments for the method call |
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.
int | $code | Error code |
string | $error | Error message |
string | $file | File in which the error occured |
int | $line | Line at which the error occured |
array | $context | Error context pointing to the active symbol table |
|
protected |
Get handler
Tries to obtain an Output Handler, either directly from the '$handler' property, or through the getter.
|
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.
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.
bool | $enabled | Enabled flag, default bool(true) |
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.
\SlaxWeb\Output\AbstractHandler | $handler | Handler instance |
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.
callable | $getter | Handler getter callable |
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.
|
protected |
SlaxWeb\Output\Manager::E_WARNING |