Overview

Packages

  • Autoloader

Classes

  • Horde_Autoloader
  • Horde_Autoloader_ClassPathMapper_Application
  • Horde_Autoloader_ClassPathMapper_Default
  • Horde_Autoloader_ClassPathMapper_Prefix
  • Horde_Autoloader_Default

Interfaces

  • Horde_Autoloader_ClassPathMapper
  • Overview
  • Package
  • Class
  • Tree
 1: <?php
 2: /**
 3:  * Provides a generic pattern for different mapping types within the application
 4:  * directory.
 5:  *
 6:  * @author   Bob Mckee <bmckee@bywires.com>
 7:  * @author   Chuck Hagenbuch <chuck@horde.org>
 8:  * @category Horde
 9:  * @package  Autoloader
10:  */
11: class Horde_Autoloader_ClassPathMapper_Application implements Horde_Autoloader_ClassPathMapper
12: {
13:     protected $_appDir;
14:     protected $_mappings = array();
15: 
16:     /**
17:      * The following constants are for naming the positions in the regex for
18:      * easy readability later.
19:      */
20:     const APPLICATION_POS = 1;
21:     const ACTION_POS = 2;
22:     const SUFFIX_POS = 3;
23: 
24:     const NAME_SEGMENT = '([0-9A-Z][0-9A-Za-z]+)+';
25: 
26:     public function __construct($appDir)
27:     {
28:         $this->_appDir = rtrim($appDir, '/') . '/';
29:     }
30: 
31:     public function addMapping($classSuffix, $subDir)
32:     {
33:         $this->_mappings[$classSuffix] = $subDir;
34:         $this->_classMatchRegex = '/^' . self::NAME_SEGMENT . '_' . self::NAME_SEGMENT . '_' .
35:             '(' . implode('|', array_keys($this->_mappings)) . ')$/';
36:     }
37: 
38:     public function mapToPath($className)
39:     {
40:         if (preg_match($this->_classMatchRegex, $className, $matches)) {
41:             return $this->_appDir . $this->_mappings[$matches[self::SUFFIX_POS]] . '/' . $matches[self::ACTION_POS] . '.php';
42:         }
43:     }
44: 
45:     public function __toString()
46:     {
47:         return get_class($this) . ' ' . $this->_classMatchRegex . ' [' . $this->_appDir . ']';
48:     }
49: }
50: 
API documentation generated by ApiGen