From 232fde0a73055697fe09d0b8eea7b0239b53aaed Mon Sep 17 00:00:00 2001 From: Dmitriy Simushev Date: Fri, 4 Jul 2014 13:49:16 +0000 Subject: [PATCH] Decouple CookieFactory from AuthenticationManager --- src/mibew/libs/classes/Mibew/Application.php | 10 +++-- .../Authentication/AuthenticationManager.php | 11 ++---- .../Http/CookieFactoryAwareInterface.php | 38 +++++++++++++++++++ 3 files changed, 49 insertions(+), 10 deletions(-) create mode 100644 src/mibew/libs/classes/Mibew/Http/CookieFactoryAwareInterface.php diff --git a/src/mibew/libs/classes/Mibew/Application.php b/src/mibew/libs/classes/Mibew/Application.php index ec7f091e..f8b206a7 100644 --- a/src/mibew/libs/classes/Mibew/Application.php +++ b/src/mibew/libs/classes/Mibew/Application.php @@ -23,6 +23,7 @@ use Mibew\Authentication\AuthenticationManagerAwareInterface; use Mibew\Controller\ControllerResolver; use Mibew\EventDispatcher; use Mibew\Http\CookieFactory; +use Mibew\Http\CookieFactoryAwareInterface; use Mibew\Http\Exception\AccessDeniedException as AccessDeniedHttpException; use Mibew\Http\Exception\HttpException; use Mibew\Http\Exception\MethodNotAllowedException as MethodNotAllowedHttpException; @@ -93,10 +94,13 @@ class Application implements RouterAwareInterface, AuthenticationManagerAwareInt $context->fromRequest($request); $this->getRouter()->setContext($context); - // Actualize cookie factory in the authentication manager. $authentication_manager = $this->getAuthenticationManager(); - $cookie_factory = CookieFactory::fromRequest($request); - $authentication_manager->setCookieFactory($cookie_factory); + // Actualize cookie factory in the authentication manager if it is + // needed. + if ($authentication_manager instanceof CookieFactoryAwareInterface) { + $cookie_factory = CookieFactory::fromRequest($request); + $authentication_manager->setCookieFactory($cookie_factory); + } $authentication_manager->setOperatorFromRequest($request); try { diff --git a/src/mibew/libs/classes/Mibew/Authentication/AuthenticationManager.php b/src/mibew/libs/classes/Mibew/Authentication/AuthenticationManager.php index 1a631f38..89e9c68b 100644 --- a/src/mibew/libs/classes/Mibew/Authentication/AuthenticationManager.php +++ b/src/mibew/libs/classes/Mibew/Authentication/AuthenticationManager.php @@ -19,13 +19,14 @@ namespace Mibew\Authentication; use Mibew\EventDispatcher; use Mibew\Http\CookieFactory; +use Mibew\Http\CookieFactoryAwareInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; /** * Controls operator's authentication. */ -class AuthenticationManager implements AuthenticationManagerInterface +class AuthenticationManager implements AuthenticationManagerInterface, CookieFactoryAwareInterface { /** * Indicates if the operator is logged in. @@ -57,9 +58,7 @@ class AuthenticationManager implements AuthenticationManagerInterface protected $cookieFactory = null; /** - * Updates instance of cookie factory related with the manager. - * - * @param CookieFactory $factory An instance of CookieFactory. + * {@inheritdoc} */ public function setCookieFactory(CookieFactory $factory) { @@ -67,9 +66,7 @@ class AuthenticationManager implements AuthenticationManagerInterface } /** - * Returns an instance of cookie factory related with the manager. - * - * @return CookieFactory + * {@inheritdoc} */ public function getCookieFactory() { diff --git a/src/mibew/libs/classes/Mibew/Http/CookieFactoryAwareInterface.php b/src/mibew/libs/classes/Mibew/Http/CookieFactoryAwareInterface.php new file mode 100644 index 00000000..f62cdcfb --- /dev/null +++ b/src/mibew/libs/classes/Mibew/Http/CookieFactoryAwareInterface.php @@ -0,0 +1,38 @@ +