fuegas / boilerplate-slim
Boilerplate for Slim applications
Requires
- php: >5.5.0
- monolog/monolog: 1.15.*
- phpmailer/phpmailer: 5.2.*
- slim/slim: 2.6.*
Requires (Dev)
- fuegas/vanilla-psr: 1.*
- phpunit/phpunit: 4.7.*
This package is not auto-updated.
Last update: 2025-01-08 12:56:20 UTC
README
Environment
You can get the environment the application is running in using the Environment
class. The default environment variable that is requested is SLIM_ENV. If you want
to use a different variable you can specify it when requesting the environment
value:
Environment::env() // Returns SLIM_ENV value or default (null)
Environment::env('MY_ENV') // Returns MY_ENV value or default (null)
Environment::env('MY_ENV', 'production') // Returns MY_ENV value or default ('production')
Logger
The boilerplate has Monolog as a dependency. It can be injected into Slim during instantiation.
By default the logger will be injected with the following values:
array(
'name' => 'SlimMonoLogger',
'handlers' => array(
new \Monolog\Handler\StreamHandler('./logs/'.date('y-m-d').'.log'),
),
'processors' => array(),
)
If you want to use stdout
as logger, use the following instance call:
Log::getInstance([
'name' => 'YourLogger',
'handlers' => [ new \Monolog\Handler\StreamHandler('php://stdout') ]
]);
For other logging capabilities, please take a look at: https://github.com/Seldaek/monolog
If you want to inject the logger into Slim yourself see the following example:
$app = new \Slim\Slim(array(
'log.writer' => new Ssllii\Helpers\Log(array(
'name' => 'SlimMonoLogger',
'handlers' => array(
new \Monolog\Handler\StreamHandler('./logs/'.date('Y-m-d').'.log'),
),
'processors' => array(
function ($record) {
$record['extra']['dummy'] = 'Hello world!';
return $record;
},
),
))
));