/
halo_handler_SimpleUriHandlerMapping.php
73 lines (62 loc) · 1.88 KB
/
halo_handler_SimpleUriHandlerMapping.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
require_once('halo_AbstractUriHandlerMapping.php');
require_once('halo_HttpRequest.php');
require_once('dd_logging_LogFactory.php');
require_once('dd_logging_ILogger.php');
class halo_SimpleUriHandlerMapping extends halo_AbstractUriHandlerMapping {
/**
* Logger
* @var dd_logging_ILogger
*/
public static $LOGGER;
/**
* URI to handler mappings
* @var Array
*/
protected $mappings;
/**
* Should we use a default handler?
* @var Bool
*/
protected $useDefault;
/**
* Constructor
* @param $mappings
* @param $default
*/
public function __construct(array $mappings, $default = null) {
$this->mappings = $mappings;
$this->default = $default;
if ( $default !== null ) {
$this->useDefault = true;
} else {
$this->useDefault = false;
}
}
/**
* Get the actual handler
* @param $httpRequest
*/
protected function getHandlerInternal(halo_HttpRequest $httpRequest) {
$uri = $httpRequest->requestedUri();
if ( $this->useDefault and ( $uri === null or $uri === '' ) and $this->default !== null ) {
return $this->context->get($this->default);
}
if ( isset($this->registeredHandlers[$uri]) ) {
return $this->context->get($this->registeredHandlers[$uri]);
}
if ( self::$LOGGER->isInfoEnabled() ) {
self::$LOGGER->info('Unable to handle request for URI: [' . $uri . ']');
}
return null;
}
/**
* Register the handlers
*/
protected function registerHandlers() {
foreach ( $this->mappings as $uri => $objectName ) {
$this->registerHandler($uri, $objectName);
}
}
}
halo_SimpleUriHandlerMapping::$LOGGER = dd_logging_LogFactory::get('halo_SimpleUriHandlerMapping');