Guest User

Untitled

a guest
Jun 18th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. <?php
  2. hc_core_ClassLoader::load('halo_AbstractUrlHandlerMapping');
  3. class halo_SimpleUrlHandlerMapping extends halo_AbstractUrlHandlerMapping {
  4. protected $mappings;
  5. protected $useDefault;
  6. private $pathMatcher;
  7.  
  8. public function __construct(array $mappings, $default = null) {
  9. $this->mappings = $mappings;
  10. $this->default = $default;
  11. if ( $default !== null ) {
  12. $this->useDefault = true;
  13. } else {
  14. $this->useDefault = false;
  15. }
  16. }
  17. protected function getHandlerInternal(halo_HttpRequest $httpRequest) {
  18. $url = $httpRequest->getRequestedUrl();
  19.  
  20. if ( $this->useDefault and ( $url === null or $url === '/' ) and $this->default !== null ) {
  21. return $this->context->get($this->default);
  22. }
  23. if ( isset($this->registeredHandlers[$url]) ) {
  24. return $this->context->get($this->registeredHandlers[$url]);
  25. } else {
  26. foreach ($this->registeredHandlers as $key => $value) {
  27. if ($this->pathMatcher->match($key, $url)) {
  28. return $this->context->get($value);
  29. }
  30. }
  31. }
  32.  
  33. return null;
  34. }
  35.  
  36. protected function registerHandlers() {
  37. foreach ( $this->mappings as $url => $objectName ) {
  38. $this->registerHandler($url, $objectName);
  39. }
  40. }
  41.  
  42. public function setPathMatcher(halo_IPathMatcher $pathMatcher) {
  43. $this->pathMatcher = $pathMatcher;
  44. }
  45. }
  46. ?>
Add Comment
Please, Sign In to add comment