An updated theme (based on Atticus Finch) for ClassicPress
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.3 KiB

3 years ago
  1. <?php
  2. if ( !class_exists('Puc_v4p1_Autoloader', false) ):
  3. class Puc_v4p1_Autoloader {
  4. private $prefix = '';
  5. private $rootDir = '';
  6. private $libraryDir = '';
  7. private $staticMap;
  8. public function __construct() {
  9. $this->rootDir = dirname(__FILE__) . '/';
  10. $nameParts = explode('_', __CLASS__, 3);
  11. $this->prefix = $nameParts[0] . '_' . $nameParts[1] . '_';
  12. $this->libraryDir = realpath($this->rootDir . '../..') . '/';
  13. $this->staticMap = array(
  14. 'PucReadmeParser' => 'vendor/readme-parser.php',
  15. 'Parsedown' => 'vendor/ParsedownLegacy.php',
  16. );
  17. if ( version_compare(PHP_VERSION, '5.3.0', '>=') ) {
  18. $this->staticMap['Parsedown'] = 'vendor/Parsedown.php';
  19. }
  20. spl_autoload_register(array($this, 'autoload'));
  21. }
  22. public function autoload($className) {
  23. if ( isset($this->staticMap[$className]) && file_exists($this->libraryDir . $this->staticMap[$className]) ) {
  24. /** @noinspection PhpIncludeInspection */
  25. include ($this->libraryDir . $this->staticMap[$className]);
  26. return;
  27. }
  28. if (strpos($className, $this->prefix) === 0) {
  29. $path = substr($className, strlen($this->prefix));
  30. $path = str_replace('_', '/', $path);
  31. $path = $this->rootDir . $path . '.php';
  32. if (file_exists($path)) {
  33. /** @noinspection PhpIncludeInspection */
  34. include $path;
  35. }
  36. }
  37. }
  38. }
  39. endif;