Overview

Packages

  • Horde
    • Routes
  • Routes

Classes

  • Horde_Routes_Matcher
  • Overview
  • Package
  • Class
  • Tree
 1: <?php
 2: /**
 3:  * Helper class to generate the match dictionary for the incoming request.
 4:  *
 5:  * PHP version 5
 6:  *
 7:  * @category Horde
 8:  * @package  Horde_Routes
 9:  * @author   Gunnar Wrobel <wrobel@pardus.de>
10:  * @license  http://www.horde.org/licenses/lgpl21 LGPL 2.1
11:  * @link     http://pear.horde.org/index.php?package=Horde_Routes
12:  * @since    1.1.0
13:  */
14: 
15: /**
16:  * Generates the match dictionary for the incoming request.
17:  *
18:  * Copyright 2011-2012 Horde LLC (http://www.horde.org/)
19:  *
20:  * See the enclosed file COPYING for license information (LGPL). If you did not
21:  * receive this file, see
22:  * http://www.horde.org/licenses/lgpl21.
23:  *
24:  * @category Horde
25:  * @package  Horde_Routes
26:  * @author   Gunnar Wrobel <wrobel@pardus.de>
27:  * @license  http://www.horde.org/licenses/lgpl21 LGPL 2.1
28:  * @link     http://pear.horde.org/index.php?package=Horde_Routes
29:  * @since    1.1.0
30:  */
31: class Horde_Routes_Matcher
32: {
33:     /**
34:      * The routes mapper.
35:      *
36:      * @var Horde_Routes_Mapper
37:      */
38:     protected $_mapper;
39: 
40:     /**
41:      * The incoming request.
42:      *
43:      * @var Horde_Controller_Request
44:      */
45:     protected $_request;
46: 
47:     /**
48:      * The match dictionary.
49:      *
50:      * @var array
51:      */
52:     protected $_match_dict;
53: 
54:     /**
55:      * Constructor
56:      *
57:      * @param Horde_Routes_Mapper $mapper        The mapper
58:      * @param Object $request  A request object that implements a ::getPath()
59:      *                         method similar to Horde_Controller_Request::
60:      */
61:     public function __construct(
62:         Horde_Routes_Mapper $mapper,
63:         $request)
64:     {
65:         $this->_mapper = $mapper;
66:         $this->_request = $request;
67:     }
68: 
69:     /**
70:      * Return the match dictionary for the incoming request.
71:      *
72:      * @return array The match dictionary.
73:      */
74:     public function getMatchDict()
75:     {
76:         if ($this->_match_dict === null) {
77:             $path = $this->_request->getPath();
78:             if (($pos = strpos($path, '?')) !== false) {
79:                 $path = substr($path, 0, $pos);
80:             }
81:             if (!$path) {
82:                 $path = '/';
83:             }
84:             $this->_match_dict = new Horde_Support_Array($this->_mapper->match($path));
85:         }
86:         return $this->_match_dict;
87:     }
88: 
89: }
API documentation generated by ApiGen