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