Skip to content
This repository has been archived by the owner on Jul 4, 2018. It is now read-only.

Commit

Permalink
feature #894 Replaceable event listener callable (dazz)
Browse files Browse the repository at this point in the history
This PR was merged into the 1.2.x-dev branch.

Discussion
----------

Replaceable event listener callable

Made event callables injectable with pimple. refs #870

Commits
-------

6690ff5 Made event callables injectable with pimple. refs #870
  • Loading branch information
fabpot committed Jan 21, 2014
2 parents df1d9e7 + 6690ff5 commit 2798eb1
Showing 1 changed file with 30 additions and 18 deletions.
48 changes: 30 additions & 18 deletions src/Silex/Provider/MonologServiceProvider.php
Expand Up @@ -66,35 +66,47 @@ public function register(Application $app)
return Logger::DEBUG;
};

$app['monolog.boot.before'] = $app->protect(
function (Request $request) use ($app) {
$app['monolog']->addInfo('> '.$request->getMethod().' '.$request->getRequestUri());
}
);

$app['monolog.boot.error'] = $app->protect(
function (\Exception $e) use ($app) {
$message = sprintf('%s: %s (uncaught exception) at %s line %s', get_class($e), $e->getMessage(), $e->getFile(), $e->getLine());
if ($e instanceof HttpExceptionInterface && $e->getStatusCode() < 500) {
$app['monolog']->addError($message, array('exception' => $e));
} else {
$app['monolog']->addCritical($message, array('exception' => $e));
}
}
);

$app['monolog.boot.after'] = $app->protect(
function (Request $request, Response $response) use ($app) {
if ($response instanceof RedirectResponse) {
$app['monolog']->addInfo('< '.$response->getStatusCode().' '.$response->getTargetUrl());
} else {
$app['monolog']->addInfo('< '.$response->getStatusCode());
}
}
);

$app['monolog.name'] = 'myapp';
}

public function boot(Application $app)
{
$app->before(function (Request $request) use ($app) {
$app['monolog']->addInfo('> '.$request->getMethod().' '.$request->getRequestUri());
});
$app->before($app['monolog.boot.before']);

/*
* Priority -4 is used to come after those from SecurityServiceProvider (0)
* but before the error handlers added with Silex\Application::error (defaults to -8)
*/
$app->error(function (\Exception $e) use ($app) {
$message = sprintf('%s: %s (uncaught exception) at %s line %s', get_class($e), $e->getMessage(), $e->getFile(), $e->getLine());
if ($e instanceof HttpExceptionInterface && $e->getStatusCode() < 500) {
$app['monolog']->addError($message, array('exception' => $e));
} else {
$app['monolog']->addCritical($message, array('exception' => $e));
}
}, -4);
$app->error($app['monolog.boot.error'], -4);

$app->after(function (Request $request, Response $response) use ($app) {
if ($response instanceof RedirectResponse) {
$app['monolog']->addInfo('< '.$response->getStatusCode().' '.$response->getTargetUrl());
} else {
$app['monolog']->addInfo('< '.$response->getStatusCode());
}
});
$app->after($app['monolog.boot.after']);
}

public static function translateLevel($name)
Expand Down

0 comments on commit 2798eb1

Please sign in to comment.