diff --git a/lib/Mage/Autoload/Simple.php b/lib/Mage/Autoload/Simple.php deleted file mode 100644 index 64599153a4c..00000000000 --- a/lib/Mage/Autoload/Simple.php +++ /dev/null @@ -1,50 +0,0 @@ -<?php -/** - * OpenMage - * - * NOTICE OF LICENSE - * - * This source file is subject to the Open Software License (OSL 3.0) - * that is bundled with this package in the file LICENSE.txt. - * It is also available through the world-wide-web at this URL: - * https://opensource.org/licenses/osl-3.0.php - * If you did not receive a copy of the license and are unable to - * obtain it through the world-wide-web, please send an email - * to license@magento.com so we can send you a copy immediately. - * - * @category Mage - * @package Mage_Autoload - * @copyright Copyright (c) 2006-2020 Magento, Inc. (https://www.magento.com) - * @copyright Copyright (c) 2022 The OpenMage Contributors (https://www.openmage.org) - * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) - */ - -class Mage_Autoload_Simple -{ - private static $_instance; - - public static function instance() - { - if (!self::$_instance) { - $class = __CLASS__; - self::$_instance = new $class(); - } - return self::$_instance; - } - - public static function register() - { - spl_autoload_register([self::instance(), 'autoload']); - } - - public function autoload($class) - { - $classFile = str_replace(' ', DIRECTORY_SEPARATOR, ucwords(str_replace('_', ' ', $class))); - $classFile .= '.php'; - /** @see https://stackoverflow.com/a/5504486/716029 */ - $found = stream_resolve_include_path($classFile); - if ($found !== false) { - include $found; - } - } -} diff --git a/lib/Magento/Autoload/ClassMap.php b/lib/Magento/Autoload/ClassMap.php deleted file mode 100644 index bc2b5c28d52..00000000000 --- a/lib/Magento/Autoload/ClassMap.php +++ /dev/null @@ -1,96 +0,0 @@ -<?php -/** - * OpenMage - * - * NOTICE OF LICENSE - * - * This source file is subject to the Open Software License (OSL 3.0) - * that is bundled with this package in the file LICENSE.txt. - * It is also available through the world-wide-web at this URL: - * https://opensource.org/licenses/osl-3.0.php - * If you did not receive a copy of the license and are unable to - * obtain it through the world-wide-web, please send an email - * to license@magento.com so we can send you a copy immediately. - * - * @category Magento - * @package Magento_Autoload - * @copyright Copyright (c) 2006-2020 Magento, Inc. (https://www.magento.com) - * @copyright Copyright (c) 2022 The OpenMage Contributors (https://www.openmage.org) - * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) - */ - -namespace Magento\Autoload; - -class ClassMap -{ - /** - * Absolute path to base directory that will be prepended as prefix to the included files - * - * @var string - */ - protected $_baseDir; - - /** - * Map of class name to file (relative to the base directory) - * - * array( - * 'Class_Name' => 'relative/path/to/Class/Name.php', - * ) - * - * @var array - */ - protected $_map = []; - - /** - * Set base directory absolute path - * - * @param string $baseDir - * @throws \InvalidArgumentException - */ - public function __construct($baseDir) - { - $this->_baseDir = realpath($baseDir); - if (!$this->_baseDir || !is_dir($this->_baseDir)) { - throw new \InvalidArgumentException("Specified path is not a valid directory: '{$baseDir}'"); - } - } - - /** - * Find an absolute path to a file to be included - * - * @param string $class - * @return string|bool - */ - public function getFile($class) - { - if (isset($this->_map[$class])) { - return $this->_baseDir . DIRECTORY_SEPARATOR . $this->_map[$class]; - } - return false; - } - - /** - * Add classes files declaration to the map. New map will override existing values if such was defined before. - * - * @param array $map - * @return \Magento\Autoload\ClassMap - */ - public function addMap(array $map) - { - $this->_map = array_merge($this->_map, $map); - return $this; - } - - /** - * Resolve a class file and include it - * - * @param string $class - */ - public function load($class) - { - $file = $this->getFile($class); - if (file_exists($file)) { - include $file; - } - } -} diff --git a/lib/Magento/Autoload/IncludePath.php b/lib/Magento/Autoload/IncludePath.php deleted file mode 100644 index 5e95cd06ca6..00000000000 --- a/lib/Magento/Autoload/IncludePath.php +++ /dev/null @@ -1,89 +0,0 @@ -<?php -/** - * OpenMage - * - * NOTICE OF LICENSE - * - * This source file is subject to the Open Software License (OSL 3.0) - * that is bundled with this package in the file LICENSE.txt. - * It is also available through the world-wide-web at this URL: - * https://opensource.org/licenses/osl-3.0.php - * If you did not receive a copy of the license and are unable to - * obtain it through the world-wide-web, please send an email - * to license@magento.com so we can send you a copy immediately. - * - * @category Magento - * @package Magento_Autoload - * @copyright Copyright (c) 2006-2020 Magento, Inc. (https://www.magento.com) - * @copyright Copyright (c) 2022 The OpenMage Contributors (https://www.openmage.org) - * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) - */ - -namespace Magento\Autoload; - -class IncludePath -{ - /** - * Namespaces separator - */ - public const NS_SEPARATOR = '\\'; - - /** - * Find a file in include path - * - * @param string $class - * @return string|bool - */ - public static function getFile($class) - { - $relativePath = self::getFilePath($class); - return stream_resolve_include_path($relativePath); - } - - /** - * Get relative file path for specified class - * - * @static - * @param string $class - * @return string - */ - public static function getFilePath($class) - { - if (strpos($class, self::NS_SEPARATOR) !== false) { - $class = ltrim(str_replace(self::NS_SEPARATOR, '_', $class), '_'); - } - return str_replace('_', DIRECTORY_SEPARATOR, $class) . '.php'; - } - - /** - * Add specified path(s) to the current include_path - * - * @param string|array $path - * @param bool $prepend Whether to prepend paths or to append them - */ - public static function addIncludePath($path, $prepend = true) - { - $includePathExtra = implode(PATH_SEPARATOR, (array)$path); - $includePath = get_include_path(); - $pathSeparator = $includePath && $includePathExtra ? PATH_SEPARATOR : ''; - if ($prepend) { - $includePath = $includePathExtra . $pathSeparator . $includePath; - } else { - $includePath = $includePath . $pathSeparator . $includePathExtra; - } - set_include_path($includePath); - } - - /** - * Resolve a class file and include it - * - * @param $class - */ - public static function load($class) - { - $file = self::getFile($class); - if ($file) { - include $file; - } - } -} diff --git a/lib/Magento/Autoload/Simple.php b/lib/Magento/Autoload/Simple.php deleted file mode 100644 index 634593e8c3f..00000000000 --- a/lib/Magento/Autoload/Simple.php +++ /dev/null @@ -1,52 +0,0 @@ -<?php -/** - * OpenMage - * - * NOTICE OF LICENSE - * - * This source file is subject to the Open Software License (OSL 3.0) - * that is bundled with this package in the file LICENSE.txt. - * It is also available through the world-wide-web at this URL: - * https://opensource.org/licenses/osl-3.0.php - * If you did not receive a copy of the license and are unable to - * obtain it through the world-wide-web, please send an email - * to license@magento.com so we can send you a copy immediately. - * - * @category Magento - * @package Magento_Autoload - * @copyright Copyright (c) 2006-2020 Magento, Inc. (https://www.magento.com) - * @copyright Copyright (c) 2022 The OpenMage Contributors (https://www.openmage.org) - * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) - */ - -namespace Magento\Autoload; - -class Simple -{ - private static $_instance; - - public static function instance() - { - if (!self::$_instance) { - $class = __CLASS__; - self::$_instance = new $class(); - } - return self::$_instance; - } - - public static function register() - { - spl_autoload_register([self::instance(), 'autoload']); - } - - public function autoload($class) - { - $classFile = str_replace(' ', DIRECTORY_SEPARATOR, ucwords(str_replace('_', ' ', $class))); - $classFile .= '.php'; - /** @see https://stackoverflow.com/a/5504486/716029 */ - $found = stream_resolve_include_path($classFile); - if ($found !== false) { - include $found; - } - } -}