Permalink
Browse files

Refactors code for clarity, updates doc block.

  • Loading branch information...
1 parent e0e0edf commit fb711771ed9b7a8b1c745685a9b1534bee55dafe @jeremykendall committed May 15, 2013
Showing with 12 additions and 14 deletions.
  1. +11 −13 library/Fa/Middleware/Authentication.php
  2. +1 −1 library/Fa/Middleware/Navigation.php
@@ -54,25 +54,23 @@ public function __construct(AuthenticationService $auth, array $config)
public function call()
{
$app = $this->app;
- $auth = $this->auth;
$req = $app->request();
+ $auth = $this->auth;
$config = $this->config;
- $this->app->hook('slim.before.router', function () use ($app, $auth, $req, $config) {
- $securedUrls = isset($config['security.urls']) ? $config['security.urls'] : array();
- foreach ($securedUrls as $surl) {
- $patternAsRegex = $surl['path'];
- $patternAsRegex = '@^' . $patternAsRegex . '$@';
- if (preg_match($patternAsRegex, $req->getPathInfo())) {
- if (!$auth->hasIdentity()) {
- if ($req->getPath() !== $config['login.url']) {
- $app->redirect($config['login.url']);
- }
- }
+ $checkAuth = function () use ($app, $auth, $req, $config) {
+ $securedUrls = isset($config['security.urls']) ? $config['security.urls'] : array();
+ foreach ($securedUrls as $url) {
+ $urlPattern = '@^' . $url['path'] . '$@';
+ if (preg_match($urlPattern, $req->getPathInfo()) && !$auth->hasIdentity()) {
+ if ($req->getPath() !== $config['login.url']) {
+ $app->redirect($config['login.url']);
}
}
}
- );
+ };
+
+ $this->app->hook('slim.before.router', $checkAuth);
$this->next->call();
}
@@ -40,7 +40,7 @@ public function __construct(AuthenticationService $auth)
/**
* Constructs array of navigation items and appends them to the view. Navigation
- * items differ if user is authenticated or not. Uses 'slim.before.router'.
+ * items differ if user is authenticated or not.
*/
public function call()
{

0 comments on commit fb71177

Please sign in to comment.