public function register(Container $app) { $app['logger'] = function () use($app) { return $app['monolog']; }; if ($bridge = class_exists('Symfony\\Bridge\\Monolog\\Logger')) { $app['monolog.handler.debug'] = function () use($app) { $level = MonologServiceProvider::translateLevel($app['monolog.level']); return new DebugHandler($level); }; if (isset($app['request_stack'])) { $app['monolog.not_found_activation_strategy'] = function () use($app) { return new NotFoundActivationStrategy($app['request_stack'], array('^/'), $app['monolog.level']); }; } } $app['monolog.logger.class'] = $bridge ? 'Symfony\\Bridge\\Monolog\\Logger' : 'Monolog\\Logger'; $app['monolog'] = function ($app) { $log = new $app['monolog.logger.class']($app['monolog.name']); $handler = new Handler\GroupHandler($app['monolog.handlers']); if (isset($app['monolog.not_found_activation_strategy'])) { $handler = new Handler\FingersCrossedHandler($handler, $app['monolog.not_found_activation_strategy']); } $log->pushHandler($handler); if ($app['debug'] && isset($app['monolog.handler.debug'])) { $log->pushHandler($app['monolog.handler.debug']); } return $log; }; $app['monolog.formatter'] = function () { return new LineFormatter(); }; $app['monolog.handler'] = $defaultHandler = function () use($app) { $level = MonologServiceProvider::translateLevel($app['monolog.level']); $handler = new Handler\StreamHandler($app['monolog.logfile'], $level, $app['monolog.bubble'], $app['monolog.permission']); $handler->setFormatter($app['monolog.formatter']); return $handler; }; $app['monolog.handlers'] = function () use($app, $defaultHandler) { $handlers = array(); // enables the default handler if a logfile was set or the monolog.handler service was redefined if ($app['monolog.logfile'] || $defaultHandler !== $app->raw('monolog.handler')) { $handlers[] = $app['monolog.handler']; } return $handlers; }; $app['monolog.level'] = function () { return Logger::DEBUG; }; $app['monolog.listener'] = function () use($app) { return new LogListener($app['logger'], $app['monolog.exception.logger_filter']); }; $app['monolog.name'] = 'app'; $app['monolog.bubble'] = true; $app['monolog.permission'] = null; $app['monolog.exception.logger_filter'] = null; $app['monolog.logfile'] = null; $app['monolog.use_error_handler'] = !$app['debug']; }
/** * {@inheritDoc} */ public function register(Container $container) { $container['defaultErrorHandler'] = $container->raw('phpErrorHandler'); $container['errorHandler'] = function ($container) { return new ErrorHandler($container); }; $container['phpErrorHandler'] = function ($container) { return new ErrorHandler($container); }; }
/** * {@inheritDoc} */ public function register(Container $container) { // Save default handler under new name $container['defaultNotAllowedHandler'] = $container->raw('notAllowedHandler'); /** * Add dependency (DI). * * @param Container $c * * @return NotAllowedHandler */ $container['notAllowedHandler'] = function ($c) { return new NotAllowedHandler($c); }; }
/** * Test __construct(). */ public function testConstructor() { $app = new Application(['foo' => 'bar']); $this->assertInstanceOf(Config::class, $app['config']); $providers = $app->getProviders(); foreach ($providers as $provider) { $container = new Container(); $container->register(new $provider()); $container['config'] = $app->raw('config'); $container['access_token'] = $app->raw('access_token'); $container['request'] = $app->raw('request'); $container['cache'] = $app->raw('cache'); foreach ($container->keys() as $providerName) { $this->assertEquals($container->raw($providerName), $app->raw($providerName)); } unset($container); } }
public function raw($id) { return $this->pimpleContainer->raw($this->ensureNamespacesLoaded($id)); }
/** * @expectedException \InvalidArgumentException * @expectedExceptionMessage Identifier "foo" is not defined. */ public function testRawValidatesKeyIsPresent() { $pimple = new Container(); $pimple->raw('foo'); }
/** * {@inheritDoc} */ public function register(PimpleContainer $slimContainer) { foreach ($this->pimpleContainer->keys() as $key) { $slimContainer[$key] = $this->pimpleContainer->raw($key); } }