Created
February 15, 2012 22:27
-
-
Save kriswallsmith/1839490 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?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); | |
} | |
} |
This file contains hidden or 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
<?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