Skip to content

Instantly share code, notes, and snippets.

@aek
Created October 18, 2010 17:43
Show Gist options
  • Save aek/632647 to your computer and use it in GitHub Desktop.
Save aek/632647 to your computer and use it in GitHub Desktop.
tweeks for halo
<?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