mirror of
https://github.com/Mibew/mibew.git
synced 2025-03-03 18:38:31 +03:00
Decouple CookieFactory from AuthenticationManager
This commit is contained in:
parent
93eeeafd3c
commit
232fde0a73
@ -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();
|
||||
// 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 {
|
||||
|
@ -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()
|
||||
{
|
||||
|
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright 2005-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace Mibew\Http;
|
||||
|
||||
/**
|
||||
* Interface for all classes that knows about cookie factory.
|
||||
*/
|
||||
interface CookieFactoryAwareInterface
|
||||
{
|
||||
/**
|
||||
* Sets internal instance of cookie factory.
|
||||
*
|
||||
* @param CookieFactory $factory A cookie factory instance.
|
||||
*/
|
||||
public function setCookieFactory(CookieFactory $factory);
|
||||
|
||||
/**
|
||||
* Gets cookie factory instance.
|
||||
*
|
||||
* @returns CookieFactory
|
||||
*/
|
||||
public function getCookieFactory();
|
||||
}
|
Loading…
Reference in New Issue
Block a user