Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * dsDynamicCredentialsFilter
- *
- * This filter is created to add some credentials to user dynamically.
- *
- * It does following things:
- *
- * 1. retrieves current route,
- * 2. checks whether it is sfObjectRoute
- * 3. retrieves an object inside of that sfObjectRoute
- * 4. calls $object->getAddedCredentialsNames($user) where $user is instance of myUser
- * 5. adds credentials returned by #4 to $user
- *
- * @author Andrei Dziahel <develop7@develop7.info>
- */
- class dsDynamicCredentialsFilter extends sfFilter
- {
- public function execute($filterChain)
- {
- if ($this->isFirstCall())
- {
- $context = $this->getContext();
- /* @var $user sfGuardSecurityUser */
- $user = $context->getUser(); //TODO: fix hardcoded user instance
- $routename = $context->getRouting()->getCurrentRouteName();
- $routes = $context->getRouting()->getRoutes();
- /* @var $route sfObjectRoute */
- $route = $routes[$routename];
- if ($route instanceof sfObjectRoute && $route->isBound())
- {
- $object = false;
- try
- {
- $object = $route->getObject();
- }
- catch (LogicException $e)
- {
- $object = false;
- }
- if (false !== $object && method_exists($object, 'getAddedCredentialsNames'))
- {
- $names = call_user_func(array($object, 'getAddedCredentialsNames'), $user); //TODO: fix hardcoded method name
- $user->addCredentials($names);
- }
- else
- {
- if (sfConfig::get('sf_logging_enabled'))
- {
- $context->getEventDispatcher()->notify(new sfEvent($this,
- 'application.log',
- array('Can\'t retrieve object for route "'.$routename.'", skipping')));
- }
- }
- }
- }
- $filterChain->execute();
- }
- }
Add Comment
Please, Sign In to add comment