Applications often have different runtime environments where they are running. For instance, there may be the production environment, and this may be different from the environment the application runs in while it is developed. stubbles/ioc supports different runtime environments.
In your applications you should typehint against stubbles\Environment
and not
refer to any of the concrete environment instances. This will ensure that you
refer to the mode selected by your application. To provide the runtime
environment via injection you may want to use the stubbles\Runtime
. You
can give it the requested runtime environment as constructor argument - if it is
not supplied the binding module will fall back to
stubbles\environments\Production
.
By implementing the stubbles\Environment
interface you can create your own
runtime environement implementation.
Every environment instance offers the following methods:
name()
returns the name of the mode (PROD, TEST, STAGE or DEV)registerExceptionHandler($projectPath)
registerErrorHandler($projectPath)
isCacheEnabled()
returnstrue
if the cache is enabled for this mode andfalse
if not.
stubbles/ioc offers two different exception handlers:
stubbles\environments\exceptionhandler\ProdModeExceptionHandler
will issue a HTTP 500 response with the contents of the file path/to/project/docroot/500.html (if the file is not present it will use a default error message).stubbles\environments\exceptionhandler\DisplayExceptionHandler
displays the exception message and the stack trace of the exception.
Both handlers have logging enabled by default. To switch off logging use
$exceptionHandler->disableLogging()
. Logged exceptions can be found at
path/to/project/log/errors/YYYY/MM/exceptions-YYYY-MM-DD.log.
See PHP manual on exception handlers for more information.
You can create your own exception handler by implementing the
stubbles\environments\exceptionhandler\ExceptionHandler
interface.
For production the stubbles\environments\errorhandler\LogErrorHandler
is
used. It will log any PHP errors to path/to/project/log/errors/YYYY/MM/php-error-YYYY-MM-DD.log.
See PHP manual on exception handlers for more information.
You can create your own error handler by implementing the
stubbles\environments\errorhandler\ErrorHandler
interface.