Created
October 18, 2010 17:43
-
-
Save aek/632647 to your computer and use it in GitHub Desktop.
tweeks for halo
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 | |
hc_core_ClassLoader::load('halo_AbstractUrlHandlerMapping'); | |
class halo_SimpleUrlHandlerMapping extends halo_AbstractUrlHandlerMapping { | |
protected $mappings; | |
protected $useDefault; | |
private $pathMatcher; | |
public function __construct(array $mappings, $default = null) { | |
$this->mappings = $mappings; | |
$this->default = $default; | |
if ( $default !== null ) { | |
$this->useDefault = true; | |
} else { | |
$this->useDefault = false; | |
} | |
} | |
protected function getHandlerInternal(halo_HttpRequest $httpRequest) { | |
$url = $httpRequest->getRequestedUrl(); | |
if ( $this->useDefault and ( $url === null or $url === '/' ) and $this->default !== null ) { | |
return $this->context->get($this->default); | |
} | |
if ( isset($this->registeredHandlers[$url]) ) { | |
return $this->context->get($this->registeredHandlers[$url]); | |
} else { | |
foreach ($this->registeredHandlers as $key => $value) { | |
if ($this->pathMatcher->match($key, $url)) { | |
return $this->context->get($value); | |
} | |
} | |
} | |
return null; | |
} | |
protected function registerHandlers() { | |
foreach ( $this->mappings as $url => $objectName ) { | |
$this->registerHandler($url, $objectName); | |
} | |
} | |
public function setPathMatcher(halo_IPathMatcher $pathMatcher) { | |
$this->pathMatcher = $pathMatcher; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment