Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds lazy loading for firewall configurations. This is useful when you have multiple firewalls, only the firewalls which are actually needed to process the Request are initialized. So, your event dispatcher is not as costly to initialize anymore. It also implements re-using of RequestMatchers if all matching rules are the same, and exposes the remaining rules which are already implemented by the request matcher (host, ip, methods) in the access-control section
- Loading branch information
1 parent
82d29d2
commit 507da2a
Showing
11 changed files
with
196 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/Symfony/Bundle/FrameworkBundle/Security/FirewallContext.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace Symfony\Bundle\FrameworkBundle\Security; | ||
|
||
use Symfony\Component\HttpKernel\Security\Firewall\ExceptionListener; | ||
|
||
/** | ||
* This is a wrapper around the actual firewall configuration which allows us | ||
* to lazy load the context for one specific firewall only when we need it. | ||
* | ||
* @author Johannes M. Schmitt <schmittjoh@gmail.com> | ||
*/ | ||
class FirewallContext | ||
{ | ||
protected $listeners; | ||
protected $exceptionListener; | ||
|
||
public function __construct(array $listeners, ExceptionListener $exceptionListener) | ||
{ | ||
$this->listeners = $listeners; | ||
$this->exceptionListener = $exceptionListener; | ||
} | ||
|
||
public function getContext() | ||
{ | ||
return array($this->listeners, $this->exceptionListener); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/Symfony/Bundle/FrameworkBundle/Security/FirewallMap.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace Symfony\Bundle\FrameworkBundle\Security; | ||
|
||
use Symfony\Component\HttpKernel\Security\FirewallMapInterface; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
|
||
/** | ||
* This is a lazy-loading firewall map implementation | ||
* | ||
* Listeners will only be initialized if we really need them. | ||
* | ||
* @author Johannes M. Schmitt <schmittjoh@gmail.com> | ||
*/ | ||
class FirewallMap implements FirewallMapInterface | ||
{ | ||
protected $container; | ||
protected $map; | ||
|
||
public function __construct(ContainerInterface $container, array $map) | ||
{ | ||
$this->container = $container; | ||
$this->map = $map; | ||
} | ||
|
||
public function getListeners(Request $request) | ||
{ | ||
foreach ($this->map as $contextId => $requestMatcher) { | ||
if (null === $requestMatcher || $requestMatcher->matches($request)) { | ||
return $this->container->get($contextId)->getContext(); | ||
} | ||
} | ||
|
||
return array(array(), null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/Symfony/Component/HttpKernel/Security/FirewallMapInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace Symfony\Component\HttpKernel\Security; | ||
|
||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
/** | ||
* This interface must be implemented by firewall maps. | ||
* | ||
* @author Johannes M. Schmitt <schmittjoh@gmail.com> | ||
*/ | ||
interface FirewallMapInterface | ||
{ | ||
/** | ||
* Returns the authentication listeners, and the exception listener to use | ||
* for the given request. | ||
* | ||
* If there are no authentication listeners, the first inner are must be | ||
* empty. | ||
* | ||
* If there is no exception listener, the second element of the outer array | ||
* must be null. | ||
* | ||
* @param Request $request | ||
* @return array of the format array(array(AuthenticationListener), ExceptionListener) | ||
*/ | ||
function getListeners(Request $request); | ||
} |