Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?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;
- }
- }
- ?>
Add Comment
Please, Sign In to add comment