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\Controller\ControllerResolver;
|
||||||
use Mibew\EventDispatcher;
|
use Mibew\EventDispatcher;
|
||||||
use Mibew\Http\CookieFactory;
|
use Mibew\Http\CookieFactory;
|
||||||
|
use Mibew\Http\CookieFactoryAwareInterface;
|
||||||
use Mibew\Http\Exception\AccessDeniedException as AccessDeniedHttpException;
|
use Mibew\Http\Exception\AccessDeniedException as AccessDeniedHttpException;
|
||||||
use Mibew\Http\Exception\HttpException;
|
use Mibew\Http\Exception\HttpException;
|
||||||
use Mibew\Http\Exception\MethodNotAllowedException as MethodNotAllowedHttpException;
|
use Mibew\Http\Exception\MethodNotAllowedException as MethodNotAllowedHttpException;
|
||||||
@ -93,10 +94,13 @@ class Application implements RouterAwareInterface, AuthenticationManagerAwareInt
|
|||||||
$context->fromRequest($request);
|
$context->fromRequest($request);
|
||||||
$this->getRouter()->setContext($context);
|
$this->getRouter()->setContext($context);
|
||||||
|
|
||||||
// Actualize cookie factory in the authentication manager.
|
|
||||||
$authentication_manager = $this->getAuthenticationManager();
|
$authentication_manager = $this->getAuthenticationManager();
|
||||||
$cookie_factory = CookieFactory::fromRequest($request);
|
// Actualize cookie factory in the authentication manager if it is
|
||||||
$authentication_manager->setCookieFactory($cookie_factory);
|
// needed.
|
||||||
|
if ($authentication_manager instanceof CookieFactoryAwareInterface) {
|
||||||
|
$cookie_factory = CookieFactory::fromRequest($request);
|
||||||
|
$authentication_manager->setCookieFactory($cookie_factory);
|
||||||
|
}
|
||||||
$authentication_manager->setOperatorFromRequest($request);
|
$authentication_manager->setOperatorFromRequest($request);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -19,13 +19,14 @@ namespace Mibew\Authentication;
|
|||||||
|
|
||||||
use Mibew\EventDispatcher;
|
use Mibew\EventDispatcher;
|
||||||
use Mibew\Http\CookieFactory;
|
use Mibew\Http\CookieFactory;
|
||||||
|
use Mibew\Http\CookieFactoryAwareInterface;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controls operator's authentication.
|
* Controls operator's authentication.
|
||||||
*/
|
*/
|
||||||
class AuthenticationManager implements AuthenticationManagerInterface
|
class AuthenticationManager implements AuthenticationManagerInterface, CookieFactoryAwareInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Indicates if the operator is logged in.
|
* Indicates if the operator is logged in.
|
||||||
@ -57,9 +58,7 @@ class AuthenticationManager implements AuthenticationManagerInterface
|
|||||||
protected $cookieFactory = null;
|
protected $cookieFactory = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates instance of cookie factory related with the manager.
|
* {@inheritdoc}
|
||||||
*
|
|
||||||
* @param CookieFactory $factory An instance of CookieFactory.
|
|
||||||
*/
|
*/
|
||||||
public function setCookieFactory(CookieFactory $factory)
|
public function setCookieFactory(CookieFactory $factory)
|
||||||
{
|
{
|
||||||
@ -67,9 +66,7 @@ class AuthenticationManager implements AuthenticationManagerInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an instance of cookie factory related with the manager.
|
* {@inheritdoc}
|
||||||
*
|
|
||||||
* @return CookieFactory
|
|
||||||
*/
|
*/
|
||||||
public function getCookieFactory()
|
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