Prefix.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. /**
  3. * Load classes from a specific path matching a specific prefix.
  4. *
  5. * @author Chuck Hagenbuch <chuck@horde.org>
  6. * @category Horde
  7. * @package Autoloader
  8. */
  9. class Horde_Autoloader_ClassPathMapper_Prefix implements Horde_Autoloader_ClassPathMapper
  10. {
  11. private $_pattern;
  12. private $_includePath;
  13. public function __construct($pattern, $includePath)
  14. {
  15. $this->_pattern = $pattern;
  16. $this->_includePath = $includePath;
  17. }
  18. public function mapToPath($className)
  19. {
  20. if (preg_match($this->_pattern, $className, $matches, PREG_OFFSET_CAPTURE)) {
  21. if (strcasecmp($matches[0][0], $className) === 0) {
  22. return "$this->_includePath/$className.php";
  23. } else {
  24. return str_replace(['\\', '_'], '/', substr($className, 0, $matches[0][1])) .
  25. $this->_includePath . '/' .
  26. str_replace(['\\', '_'], '/', substr($className, $matches[0][1] + strlen($matches[0][0]))) .
  27. '.php';
  28. }
  29. }
  30. return false;
  31. }
  32. }