Skip to content

Instantly share code, notes, and snippets.

@kriswallsmith
Created February 15, 2012 22:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kriswallsmith/1839490 to your computer and use it in GitHub Desktop.
Save kriswallsmith/1839490 to your computer and use it in GitHub Desktop.
<?php
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Http\AccessMapInterface;
class DelegatingAccessMap implements AccessMapInterface
{
/**
* @var array A map of path prefix to delegate map
*/
private $map = array();
/**
* @var AccessMap The default access map
*/
private $defaultMap;
public function addMap($prefix, AccessMapInterface $map)
{
if (empty($prefix)) {
throw new \InvalidArgumentException('Prefix cannot be empty');
}
$this->map[$prefix] = $map;
}
public function setDefaultMap(AccessMapInterface $map)
{
$this->defaultMap = $map;
}
public function getPatterns(Request $request)
{
foreach ($this->map as $prefix => $map) {
if (0 === strpos($request->getPathInfo(), $prefix)) {
return $map->getPatterns($request);
}
}
if (null !== $this->defaultMap) {
return $this->defaultMap->getPatterns($request);
}
return array(null, null);
}
}
<?php
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Http\AccessMap;
class DelegatingAccessMap extends AccessMap
{
/**
* @var array A map of path prefix to delegate map
*/
private $map = array();
/**
* @var AccessMap The default access map
*/
private $defaultMap;
public function addMap($prefix, AccessMap $map)
{
if (empty($prefix)) {
throw new \InvalidArgumentException('Prefix cannot be empty');
}
$this->map[$prefix] = $map;
}
public function setDefaultMap(AccessMap $map)
{
$this->defaultMap = $map;
}
public function getPatterns(Request $request)
{
foreach ($this->map as $prefix => $map) {
if (0 === strpos($request->getPathInfo(), $prefix)) {
return $map->getPatterns($request);
}
}
if (null !== $this->defaultMap) {
return $this->defaultMap->getPatterns($request);
}
return array(null, null);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment