mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-19 15:22:17 +02:00
N°5122 - Update libs to new PHP requirements
This commit is contained in:
@@ -1,26 +1,29 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @see https://github.com/laminas/laminas-loader for the canonical source repository
|
||||
* @copyright https://github.com/laminas/laminas-loader/blob/master/COPYRIGHT.md
|
||||
* @license https://github.com/laminas/laminas-loader/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Laminas\Loader;
|
||||
|
||||
use Laminas\Loader\SplAutoloader;
|
||||
use Laminas\Loader\StandardAutoloader;
|
||||
use Traversable;
|
||||
|
||||
if (class_exists('Laminas\Loader\AutoloaderFactory')) {
|
||||
use function class_exists;
|
||||
use function is_array;
|
||||
use function is_subclass_of;
|
||||
use function spl_autoload_unregister;
|
||||
use function sprintf;
|
||||
use function strrchr;
|
||||
use function substr;
|
||||
|
||||
if (class_exists(AutoloaderFactory::class)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// phpcs:ignore WebimpressCodingStandard.NamingConventions.AbstractClass.Prefix
|
||||
abstract class AutoloaderFactory
|
||||
{
|
||||
const STANDARD_AUTOLOADER = 'Laminas\Loader\StandardAutoloader';
|
||||
public const STANDARD_AUTOLOADER = StandardAutoloader::class;
|
||||
|
||||
/**
|
||||
* @var array All autoloaders registered using the factory
|
||||
*/
|
||||
/** @var array All autoloaders registered using the factory */
|
||||
protected static $loaders = [];
|
||||
|
||||
/**
|
||||
@@ -51,9 +54,9 @@ abstract class AutoloaderFactory
|
||||
*
|
||||
* @param array|Traversable $options (optional) options to use. Defaults to Laminas\Loader\StandardAutoloader
|
||||
* @return void
|
||||
* @throws Exception\InvalidArgumentException for invalid options
|
||||
* @throws Exception\InvalidArgumentException for unloadable autoloader classes
|
||||
* @throws Exception\DomainException for autoloader classes not implementing SplAutoloader
|
||||
* @throws Exception\InvalidArgumentException For invalid options.
|
||||
* @throws Exception\InvalidArgumentException For unloadable autoloader classes.
|
||||
* @throws Exception\DomainException For autoloader classes not implementing SplAutoloader.
|
||||
*/
|
||||
public static function factory($options = null)
|
||||
{
|
||||
@@ -68,7 +71,7 @@ abstract class AutoloaderFactory
|
||||
return;
|
||||
}
|
||||
|
||||
if (! is_array($options) && ! ($options instanceof Traversable)) {
|
||||
if (! is_array($options) && ! $options instanceof Traversable) {
|
||||
require_once __DIR__ . '/Exception/InvalidArgumentException.php';
|
||||
throw new Exception\InvalidArgumentException(
|
||||
'Options provided must be an array or Traversable'
|
||||
@@ -85,7 +88,7 @@ abstract class AutoloaderFactory
|
||||
);
|
||||
}
|
||||
|
||||
if (! is_subclass_of($class, 'Laminas\Loader\SplAutoloader')) {
|
||||
if (! is_subclass_of($class, SplAutoloader::class)) {
|
||||
require_once 'Exception/InvalidArgumentException.php';
|
||||
throw new Exception\InvalidArgumentException(
|
||||
sprintf('Autoloader class %s must implement Laminas\\Loader\\SplAutoloader', $class)
|
||||
@@ -122,7 +125,7 @@ abstract class AutoloaderFactory
|
||||
*
|
||||
* @param string $class
|
||||
* @return SplAutoloader
|
||||
* @throws Exception\InvalidArgumentException for non-registered class
|
||||
* @throws Exception\InvalidArgumentException For non-registered class.
|
||||
*/
|
||||
public static function getRegisteredAutoloader($class)
|
||||
{
|
||||
@@ -180,13 +183,12 @@ abstract class AutoloaderFactory
|
||||
return static::$standardAutoloader;
|
||||
}
|
||||
|
||||
|
||||
if (! class_exists(static::STANDARD_AUTOLOADER)) {
|
||||
// Extract the filename from the classname
|
||||
$stdAutoloader = substr(strrchr(static::STANDARD_AUTOLOADER, '\\'), 1);
|
||||
require_once __DIR__ . "/$stdAutoloader.php";
|
||||
}
|
||||
$loader = new StandardAutoloader();
|
||||
$loader = new StandardAutoloader();
|
||||
static::$standardAutoloader = $loader;
|
||||
return static::$standardAutoloader;
|
||||
}
|
||||
@@ -194,11 +196,11 @@ abstract class AutoloaderFactory
|
||||
/**
|
||||
* Checks if the object has this class as one of its parents
|
||||
*
|
||||
* @deprecated since laminas 2.3 requires PHP >= 5.3.23
|
||||
*
|
||||
* @see https://bugs.php.net/bug.php?id=53727
|
||||
* @see https://github.com/zendframework/zf2/pull/1807
|
||||
*
|
||||
* @deprecated since laminas 2.3 requires PHP >= 5.3.23
|
||||
*
|
||||
* @param string $className
|
||||
* @param string $type
|
||||
* @return bool
|
||||
|
||||
@@ -1,15 +1,28 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @see https://github.com/laminas/laminas-loader for the canonical source repository
|
||||
* @copyright https://github.com/laminas/laminas-loader/blob/master/COPYRIGHT.md
|
||||
* @license https://github.com/laminas/laminas-loader/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Laminas\Loader;
|
||||
|
||||
use Traversable;
|
||||
|
||||
use function array_filter;
|
||||
use function array_values;
|
||||
use function array_walk;
|
||||
use function explode;
|
||||
use function file_exists;
|
||||
use function gettype;
|
||||
use function implode;
|
||||
use function in_array;
|
||||
use function is_array;
|
||||
use function is_string;
|
||||
use function preg_match;
|
||||
use function realpath;
|
||||
use function spl_autoload_register;
|
||||
use function sprintf;
|
||||
use function str_pad;
|
||||
use function str_replace;
|
||||
use function strlen;
|
||||
use function substr;
|
||||
|
||||
// Grab SplAutoloader interface
|
||||
require_once __DIR__ . '/SplAutoloader.php';
|
||||
|
||||
@@ -22,12 +35,14 @@ class ClassMapAutoloader implements SplAutoloader
|
||||
{
|
||||
/**
|
||||
* Registry of map files that have already been loaded
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $mapsLoaded = [];
|
||||
|
||||
/**
|
||||
* Class name/filename map
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $map = [];
|
||||
@@ -86,7 +101,7 @@ class ClassMapAutoloader implements SplAutoloader
|
||||
require_once __DIR__ . '/Exception/InvalidArgumentException.php';
|
||||
throw new Exception\InvalidArgumentException(sprintf(
|
||||
'Map file provided does not return a map. Map file: "%s"',
|
||||
(isset($location) && is_string($location) ? $location : 'unexpected type: ' . gettype($map))
|
||||
isset($location) && is_string($location) ? $location : 'unexpected type: ' . gettype($map)
|
||||
));
|
||||
}
|
||||
|
||||
@@ -108,7 +123,7 @@ class ClassMapAutoloader implements SplAutoloader
|
||||
*/
|
||||
public function registerAutoloadMaps($locations)
|
||||
{
|
||||
if (! is_array($locations) && ! ($locations instanceof Traversable)) {
|
||||
if (! is_array($locations) && ! $locations instanceof Traversable) {
|
||||
require_once __DIR__ . '/Exception/InvalidArgumentException.php';
|
||||
throw new Exception\InvalidArgumentException('Map list must be an array or implement Traversable');
|
||||
}
|
||||
@@ -161,7 +176,7 @@ class ClassMapAutoloader implements SplAutoloader
|
||||
*
|
||||
* @param string $location
|
||||
* @return ClassMapAutoloader|mixed
|
||||
* @throws Exception\InvalidArgumentException for nonexistent locations
|
||||
* @throws Exception\InvalidArgumentException For nonexistent locations.
|
||||
*/
|
||||
protected function loadMapFromFile($location)
|
||||
{
|
||||
@@ -169,7 +184,7 @@ class ClassMapAutoloader implements SplAutoloader
|
||||
require_once __DIR__ . '/Exception/InvalidArgumentException.php';
|
||||
throw new Exception\InvalidArgumentException(sprintf(
|
||||
'Map file provided does not exist. Map file: "%s"',
|
||||
(is_string($location) ? $location : 'unexpected type: ' . gettype($location))
|
||||
is_string($location) ? $location : 'unexpected type: ' . gettype($location)
|
||||
));
|
||||
}
|
||||
|
||||
@@ -182,15 +197,14 @@ class ClassMapAutoloader implements SplAutoloader
|
||||
return $this;
|
||||
}
|
||||
|
||||
$map = include $path;
|
||||
|
||||
return $map;
|
||||
return include $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the real_path() to a file within a phar.
|
||||
*
|
||||
* @see https://bugs.php.net/bug.php?id=52769
|
||||
*
|
||||
* @param string $path
|
||||
* @return string
|
||||
*/
|
||||
@@ -200,10 +214,10 @@ class ClassMapAutoloader implements SplAutoloader
|
||||
return;
|
||||
}
|
||||
|
||||
$prefixLength = 5 + strlen($match[1]);
|
||||
$parts = explode('/', str_replace(['/', '\\'], '/', substr($path, $prefixLength)));
|
||||
$parts = array_values(array_filter($parts, function ($p) {
|
||||
return ($p !== '' && $p !== '.');
|
||||
$prefixLength = 5 + strlen($match[1]);
|
||||
$parts = explode('/', str_replace(['/', '\\'], '/', substr($path, $prefixLength)));
|
||||
$parts = array_values(array_filter($parts, function ($p) {
|
||||
return $p !== '' && $p !== '.';
|
||||
}));
|
||||
|
||||
array_walk($parts, function ($value, $key) use (&$parts) {
|
||||
|
||||
@@ -1,11 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @see https://github.com/laminas/laminas-loader for the canonical source repository
|
||||
* @copyright https://github.com/laminas/laminas-loader/blob/master/COPYRIGHT.md
|
||||
* @license https://github.com/laminas/laminas-loader/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Laminas\Loader\Exception;
|
||||
|
||||
require_once __DIR__ . '/ExceptionInterface.php';
|
||||
|
||||
@@ -1,11 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @see https://github.com/laminas/laminas-loader for the canonical source repository
|
||||
* @copyright https://github.com/laminas/laminas-loader/blob/master/COPYRIGHT.md
|
||||
* @license https://github.com/laminas/laminas-loader/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Laminas\Loader\Exception;
|
||||
|
||||
require_once __DIR__ . '/ExceptionInterface.php';
|
||||
|
||||
@@ -1,11 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @see https://github.com/laminas/laminas-loader for the canonical source repository
|
||||
* @copyright https://github.com/laminas/laminas-loader/blob/master/COPYRIGHT.md
|
||||
* @license https://github.com/laminas/laminas-loader/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Laminas\Loader\Exception;
|
||||
|
||||
interface ExceptionInterface
|
||||
|
||||
@@ -1,11 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @see https://github.com/laminas/laminas-loader for the canonical source repository
|
||||
* @copyright https://github.com/laminas/laminas-loader/blob/master/COPYRIGHT.md
|
||||
* @license https://github.com/laminas/laminas-loader/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Laminas\Loader\Exception;
|
||||
|
||||
require_once __DIR__ . '/ExceptionInterface.php';
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @see https://github.com/laminas/laminas-loader for the canonical source repository
|
||||
* @copyright https://github.com/laminas/laminas-loader/blob/master/COPYRIGHT.md
|
||||
* @license https://github.com/laminas/laminas-loader/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Laminas\Loader\Exception;
|
||||
|
||||
use Exception;
|
||||
|
||||
require_once __DIR__ . '/ExceptionInterface.php';
|
||||
|
||||
class InvalidPathException extends \Exception implements ExceptionInterface
|
||||
class InvalidPathException extends Exception implements ExceptionInterface
|
||||
{
|
||||
}
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @see https://github.com/laminas/laminas-loader for the canonical source repository
|
||||
* @copyright https://github.com/laminas/laminas-loader/blob/master/COPYRIGHT.md
|
||||
* @license https://github.com/laminas/laminas-loader/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Laminas\Loader\Exception;
|
||||
|
||||
use Exception;
|
||||
|
||||
require_once __DIR__ . '/ExceptionInterface.php';
|
||||
|
||||
class MissingResourceNamespaceException extends \Exception implements ExceptionInterface
|
||||
class MissingResourceNamespaceException extends Exception implements ExceptionInterface
|
||||
{
|
||||
}
|
||||
|
||||
@@ -1,11 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @see https://github.com/laminas/laminas-loader for the canonical source repository
|
||||
* @copyright https://github.com/laminas/laminas-loader/blob/master/COPYRIGHT.md
|
||||
* @license https://github.com/laminas/laminas-loader/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Laminas\Loader\Exception;
|
||||
|
||||
require_once __DIR__ . '/DomainException.php';
|
||||
|
||||
@@ -1,11 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @see https://github.com/laminas/laminas-loader for the canonical source repository
|
||||
* @copyright https://github.com/laminas/laminas-loader/blob/master/COPYRIGHT.md
|
||||
* @license https://github.com/laminas/laminas-loader/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Laminas\Loader\Exception;
|
||||
|
||||
require_once __DIR__ . '/ExceptionInterface.php';
|
||||
|
||||
@@ -1,11 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @see https://github.com/laminas/laminas-loader for the canonical source repository
|
||||
* @copyright https://github.com/laminas/laminas-loader/blob/master/COPYRIGHT.md
|
||||
* @license https://github.com/laminas/laminas-loader/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Laminas\Loader\Exception;
|
||||
|
||||
require_once __DIR__ . '/DomainException.php';
|
||||
|
||||
@@ -1,52 +1,56 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @see https://github.com/laminas/laminas-loader for the canonical source repository
|
||||
* @copyright https://github.com/laminas/laminas-loader/blob/master/COPYRIGHT.md
|
||||
* @license https://github.com/laminas/laminas-loader/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Laminas\Loader;
|
||||
|
||||
// Grab SplAutoloader interface
|
||||
require_once __DIR__ . '/SplAutoloader.php';
|
||||
|
||||
use GlobIterator;
|
||||
use InvalidArgumentException;
|
||||
use Phar;
|
||||
use PharFileInfo;
|
||||
use SplFileInfo;
|
||||
use Traversable;
|
||||
use function array_map;
|
||||
use function class_exists;
|
||||
use function count;
|
||||
use function extension_loaded;
|
||||
use function getcwd;
|
||||
use function gettype;
|
||||
use function implode;
|
||||
use function in_array;
|
||||
use function is_array;
|
||||
use function is_string;
|
||||
use function pathinfo;
|
||||
use function preg_match;
|
||||
use function realpath;
|
||||
use function rtrim;
|
||||
use function spl_autoload_register;
|
||||
use function spl_autoload_unregister;
|
||||
use function sprintf;
|
||||
use function str_replace;
|
||||
use function strpos;
|
||||
use function substr;
|
||||
use const DIRECTORY_SEPARATOR;
|
||||
|
||||
class ModuleAutoloader implements SplAutoloader
|
||||
{
|
||||
/**
|
||||
* @var array An array of module paths to scan
|
||||
*/
|
||||
/** @var array An array of module paths to scan */
|
||||
protected $paths = [];
|
||||
|
||||
/**
|
||||
* @var array An array of modulename => path
|
||||
*/
|
||||
/** @var array An array of modulename => path */
|
||||
protected $explicitPaths = [];
|
||||
|
||||
/**
|
||||
* @var array An array of namespaceName => namespacePath
|
||||
*/
|
||||
/** @var array An array of namespaceName => namespacePath */
|
||||
protected $namespacedPaths = [];
|
||||
|
||||
/**
|
||||
* @var string Will contain the absolute phar:// path to the executable when packaged as phar file
|
||||
*/
|
||||
/** @var string Will contain the absolute phar:// path to the executable when packaged as phar file */
|
||||
protected $pharBasePath = "";
|
||||
|
||||
/**
|
||||
* @var array An array of supported phar extensions (filled on constructor)
|
||||
*/
|
||||
/** @var array An array of supported phar extensions (filled on constructor) */
|
||||
protected $pharExtensions = [];
|
||||
|
||||
/**
|
||||
* @var array An array of module classes to their containing files
|
||||
*/
|
||||
/** @var array An array of module classes to their containing files */
|
||||
protected $moduleClassMap = [];
|
||||
|
||||
/**
|
||||
@@ -59,7 +63,7 @@ class ModuleAutoloader implements SplAutoloader
|
||||
public function __construct($options = null)
|
||||
{
|
||||
if (extension_loaded('phar')) {
|
||||
$this->pharBasePath = Phar::running(true);
|
||||
$this->pharBasePath = Phar::running(true);
|
||||
$this->pharExtensions = [
|
||||
'phar',
|
||||
'phar.tar',
|
||||
@@ -130,7 +134,7 @@ class ModuleAutoloader implements SplAutoloader
|
||||
/**
|
||||
* Autoload a class
|
||||
*
|
||||
* @param $class
|
||||
* @param string $class
|
||||
* @return mixed
|
||||
* False [if unable to load $class]
|
||||
* get_class($class) [if $class is successfully loaded]
|
||||
@@ -167,7 +171,7 @@ class ModuleAutoloader implements SplAutoloader
|
||||
}
|
||||
|
||||
$moduleNameBuffer = str_replace($namespace . "\\", "", $moduleName);
|
||||
$path .= DIRECTORY_SEPARATOR . $moduleNameBuffer . DIRECTORY_SEPARATOR;
|
||||
$path .= DIRECTORY_SEPARATOR . $moduleNameBuffer . DIRECTORY_SEPARATOR;
|
||||
|
||||
$classLoaded = $this->loadModuleFromDir($path, $class);
|
||||
if ($classLoaded) {
|
||||
@@ -181,7 +185,7 @@ class ModuleAutoloader implements SplAutoloader
|
||||
}
|
||||
}
|
||||
|
||||
$moduleClassPath = str_replace('\\', DIRECTORY_SEPARATOR, $moduleName);
|
||||
$moduleClassPath = str_replace('\\', DIRECTORY_SEPARATOR, $moduleName);
|
||||
|
||||
$pharSuffixPattern = null;
|
||||
if ($this->pharExtensions) {
|
||||
@@ -189,9 +193,9 @@ class ModuleAutoloader implements SplAutoloader
|
||||
}
|
||||
|
||||
foreach ($this->paths as $path) {
|
||||
$path = $path . $moduleClassPath;
|
||||
$path .= $moduleClassPath;
|
||||
|
||||
if ($path == '.' || substr($path, 0, 2) == './' || substr($path, 0, 2) == '.\\') {
|
||||
if ($path === '.' || substr($path, 0, 2) === './' || substr($path, 0, 2) === '.\\') {
|
||||
if (! $basePath = $this->pharBasePath) {
|
||||
$basePath = realpath('.');
|
||||
}
|
||||
@@ -248,7 +252,7 @@ class ModuleAutoloader implements SplAutoloader
|
||||
$file = new SplFileInfo($modulePath);
|
||||
}
|
||||
|
||||
if (($file->isReadable() && $file->isFile())) {
|
||||
if ($file->isReadable() && $file->isFile()) {
|
||||
// Found directory with Module.php in it
|
||||
$absModulePath = $this->pharBasePath ? (string) $file : $file->getRealPath();
|
||||
require_once $absModulePath;
|
||||
@@ -272,7 +276,7 @@ class ModuleAutoloader implements SplAutoloader
|
||||
protected function loadModuleFromPhar($pharPath, $class)
|
||||
{
|
||||
$pharPath = static::normalizePath($pharPath, false);
|
||||
$file = new SplFileInfo($pharPath);
|
||||
$file = new SplFileInfo($pharPath);
|
||||
if (! $file->isReadable() || ! $file->isFile()) {
|
||||
return false;
|
||||
}
|
||||
@@ -291,7 +295,7 @@ class ModuleAutoloader implements SplAutoloader
|
||||
|
||||
// Phase 1: Not executable phar, no stub, or stub did not provide Module class; try Module.php directly
|
||||
$moduleClassFile = 'phar://' . $fileRealPath . '/Module.php';
|
||||
$moduleFile = new SplFileInfo($moduleClassFile);
|
||||
$moduleFile = new SplFileInfo($moduleClassFile);
|
||||
if ($moduleFile->isReadable() && $moduleFile->isFile()) {
|
||||
require_once $moduleClassFile;
|
||||
if (class_exists($class)) {
|
||||
@@ -303,9 +307,9 @@ class ModuleAutoloader implements SplAutoloader
|
||||
// Phase 2: Check for nested module directory within archive
|
||||
// Checks for /path/to/MyModule.tar/MyModule/Module.php
|
||||
// (shell-integrated zip/tar utilities wrap directories like this)
|
||||
$pharBaseName = $this->pharFileToModuleName($fileRealPath);
|
||||
$moduleClassFile = 'phar://' . $fileRealPath . '/' . $pharBaseName . '/Module.php';
|
||||
$moduleFile = new SplFileInfo($moduleClassFile);
|
||||
$pharBaseName = $this->pharFileToModuleName($fileRealPath);
|
||||
$moduleClassFile = 'phar://' . $fileRealPath . '/' . $pharBaseName . '/Module.php';
|
||||
$moduleFile = new SplFileInfo($moduleClassFile);
|
||||
if ($moduleFile->isReadable() && $moduleFile->isFile()) {
|
||||
require_once $moduleClassFile;
|
||||
if (class_exists($class)) {
|
||||
@@ -341,7 +345,7 @@ class ModuleAutoloader implements SplAutoloader
|
||||
* registerPaths
|
||||
*
|
||||
* @param array|Traversable $paths
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws InvalidArgumentException
|
||||
* @return ModuleAutoloader
|
||||
*/
|
||||
public function registerPaths($paths)
|
||||
@@ -371,7 +375,7 @@ class ModuleAutoloader implements SplAutoloader
|
||||
*
|
||||
* @param string $path
|
||||
* @param bool|string $moduleName
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws InvalidArgumentException
|
||||
* @return ModuleAutoloader
|
||||
*/
|
||||
public function registerPath($path, $moduleName = false)
|
||||
|
||||
@@ -1,17 +1,21 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @see https://github.com/laminas/laminas-loader for the canonical source repository
|
||||
* @copyright https://github.com/laminas/laminas-loader/blob/master/COPYRIGHT.md
|
||||
* @license https://github.com/laminas/laminas-loader/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
<?php // phpcs:disable SlevomatCodingStandard.Namespaces.UnusedUses.UnusedUse
|
||||
|
||||
namespace Laminas\Loader;
|
||||
|
||||
use ArrayIterator;
|
||||
use IteratorAggregate;
|
||||
use ReturnTypeWillChange;
|
||||
use Traversable;
|
||||
|
||||
use function array_key_exists;
|
||||
use function class_exists;
|
||||
use function is_array;
|
||||
use function is_int;
|
||||
use function is_numeric;
|
||||
use function is_object;
|
||||
use function is_string;
|
||||
use function strtolower;
|
||||
|
||||
/**
|
||||
* Plugin class locator interface
|
||||
*/
|
||||
@@ -19,12 +23,14 @@ class PluginClassLoader implements PluginClassLocator
|
||||
{
|
||||
/**
|
||||
* List of plugin name => class name pairs
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $plugins = [];
|
||||
|
||||
/**
|
||||
* Static map allow global seeding of plugin loader
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $staticMap = [];
|
||||
@@ -107,7 +113,7 @@ class PluginClassLoader implements PluginClassLocator
|
||||
if (! class_exists($map)) {
|
||||
throw new Exception\InvalidArgumentException('Map class provided is invalid');
|
||||
}
|
||||
$map = new $map;
|
||||
$map = new $map();
|
||||
}
|
||||
if (is_array($map)) {
|
||||
$map = new ArrayIterator($map);
|
||||
@@ -209,6 +215,7 @@ class PluginClassLoader implements PluginClassLocator
|
||||
*
|
||||
* @return ArrayIterator
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function getIterator()
|
||||
{
|
||||
return new ArrayIterator($this->plugins);
|
||||
|
||||
@@ -1,10 +1,4 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @see https://github.com/laminas/laminas-loader for the canonical source repository
|
||||
* @copyright https://github.com/laminas/laminas-loader/blob/master/COPYRIGHT.md
|
||||
* @license https://github.com/laminas/laminas-loader/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
<?php // phpcs:disable WebimpressCodingStandard.NamingConventions.Interface.Suffix
|
||||
|
||||
namespace Laminas\Loader;
|
||||
|
||||
|
||||
@@ -1,10 +1,4 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @see https://github.com/laminas/laminas-loader for the canonical source repository
|
||||
* @copyright https://github.com/laminas/laminas-loader/blob/master/COPYRIGHT.md
|
||||
* @license https://github.com/laminas/laminas-loader/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
<?php // phpcs:disable WebimpressCodingStandard.NamingConventions.Interface.Suffix
|
||||
|
||||
namespace Laminas\Loader;
|
||||
|
||||
|
||||
@@ -1,16 +1,12 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @see https://github.com/laminas/laminas-loader for the canonical source repository
|
||||
* @copyright https://github.com/laminas/laminas-loader/blob/master/COPYRIGHT.md
|
||||
* @license https://github.com/laminas/laminas-loader/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
<?php // phpcs:disable WebimpressCodingStandard.NamingConventions.Interface.Suffix
|
||||
|
||||
namespace Laminas\Loader;
|
||||
|
||||
use Traversable;
|
||||
|
||||
if (interface_exists('Laminas\Loader\SplAutoloader')) {
|
||||
use function interface_exists;
|
||||
|
||||
if (interface_exists(SplAutoloader::class)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -43,7 +39,7 @@ interface SplAutoloader
|
||||
/**
|
||||
* Autoload a class
|
||||
*
|
||||
* @param $class
|
||||
* @param string $class
|
||||
* @return mixed
|
||||
* False [if unable to load $class]
|
||||
* get_class($class) [if $class is successfully loaded]
|
||||
|
||||
@@ -1,13 +1,24 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @see https://github.com/laminas/laminas-loader for the canonical source repository
|
||||
* @copyright https://github.com/laminas/laminas-loader/blob/master/COPYRIGHT.md
|
||||
* @license https://github.com/laminas/laminas-loader/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Laminas\Loader;
|
||||
|
||||
use Traversable;
|
||||
|
||||
use function dirname;
|
||||
use function file_exists;
|
||||
use function in_array;
|
||||
use function is_array;
|
||||
use function preg_match;
|
||||
use function rtrim;
|
||||
use function spl_autoload_register;
|
||||
use function str_replace;
|
||||
use function stream_resolve_include_path;
|
||||
use function strlen;
|
||||
use function strpos;
|
||||
use function substr;
|
||||
|
||||
use const DIRECTORY_SEPARATOR;
|
||||
|
||||
// Grab SplAutoloader interface
|
||||
require_once __DIR__ . '/SplAutoloader.php';
|
||||
|
||||
@@ -20,34 +31,28 @@ require_once __DIR__ . '/SplAutoloader.php';
|
||||
*/
|
||||
class StandardAutoloader implements SplAutoloader
|
||||
{
|
||||
const NS_SEPARATOR = '\\';
|
||||
const PREFIX_SEPARATOR = '_';
|
||||
const LOAD_NS = 'namespaces';
|
||||
const LOAD_PREFIX = 'prefixes';
|
||||
const ACT_AS_FALLBACK = 'fallback_autoloader';
|
||||
public const NS_SEPARATOR = '\\';
|
||||
public const PREFIX_SEPARATOR = '_';
|
||||
public const LOAD_NS = 'namespaces';
|
||||
public const LOAD_PREFIX = 'prefixes';
|
||||
public const ACT_AS_FALLBACK = 'fallback_autoloader';
|
||||
/** @deprecated Use AUTOREGISTER_LAMINAS instead */
|
||||
const AUTOREGISTER_ZF = 'autoregister_laminas';
|
||||
const AUTOREGISTER_LAMINAS = 'autoregister_laminas';
|
||||
public const AUTOREGISTER_ZF = 'autoregister_laminas';
|
||||
public const AUTOREGISTER_LAMINAS = 'autoregister_laminas';
|
||||
|
||||
/**
|
||||
* @var array Namespace/directory pairs to search; Laminas library added by default
|
||||
*/
|
||||
/** @var array Namespace/directory pairs to search; Laminas library added by default */
|
||||
protected $namespaces = [];
|
||||
|
||||
/**
|
||||
* @var array Prefix/directory pairs to search
|
||||
*/
|
||||
/** @var array Prefix/directory pairs to search */
|
||||
protected $prefixes = [];
|
||||
|
||||
/**
|
||||
* @var bool Whether or not the autoloader should also act as a fallback autoloader
|
||||
*/
|
||||
/** @var bool Whether or not the autoloader should also act as a fallback autoloader */
|
||||
protected $fallbackAutoloaderFlag = false;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param null|array|\Traversable $options
|
||||
* @param null|array|Traversable $options
|
||||
*/
|
||||
public function __construct($options = null)
|
||||
{
|
||||
@@ -74,13 +79,13 @@ class StandardAutoloader implements SplAutoloader
|
||||
* )
|
||||
* </code>
|
||||
*
|
||||
* @param array|\Traversable $options
|
||||
* @param array|Traversable $options
|
||||
* @throws Exception\InvalidArgumentException
|
||||
* @return StandardAutoloader
|
||||
*/
|
||||
public function setOptions($options)
|
||||
{
|
||||
if (! is_array($options) && ! ($options instanceof \Traversable)) {
|
||||
if (! is_array($options) && ! $options instanceof Traversable) {
|
||||
require_once __DIR__ . '/Exception/InvalidArgumentException.php';
|
||||
throw new Exception\InvalidArgumentException('Options must be either an array or Traversable');
|
||||
}
|
||||
@@ -93,12 +98,12 @@ class StandardAutoloader implements SplAutoloader
|
||||
}
|
||||
break;
|
||||
case self::LOAD_NS:
|
||||
if (is_array($pairs) || $pairs instanceof \Traversable) {
|
||||
if (is_array($pairs) || $pairs instanceof Traversable) {
|
||||
$this->registerNamespaces($pairs);
|
||||
}
|
||||
break;
|
||||
case self::LOAD_PREFIX:
|
||||
if (is_array($pairs) || $pairs instanceof \Traversable) {
|
||||
if (is_array($pairs) || $pairs instanceof Traversable) {
|
||||
$this->registerPrefixes($pairs);
|
||||
}
|
||||
break;
|
||||
@@ -143,7 +148,7 @@ class StandardAutoloader implements SplAutoloader
|
||||
*/
|
||||
public function registerNamespace($namespace, $directory)
|
||||
{
|
||||
$namespace = rtrim($namespace, self::NS_SEPARATOR) . self::NS_SEPARATOR;
|
||||
$namespace = rtrim($namespace, self::NS_SEPARATOR) . self::NS_SEPARATOR;
|
||||
$this->namespaces[$namespace] = $this->normalizeDirectory($directory);
|
||||
return $this;
|
||||
}
|
||||
@@ -157,7 +162,7 @@ class StandardAutoloader implements SplAutoloader
|
||||
*/
|
||||
public function registerNamespaces($namespaces)
|
||||
{
|
||||
if (! is_array($namespaces) && ! $namespaces instanceof \Traversable) {
|
||||
if (! is_array($namespaces) && ! $namespaces instanceof Traversable) {
|
||||
require_once __DIR__ . '/Exception/InvalidArgumentException.php';
|
||||
throw new Exception\InvalidArgumentException('Namespace pairs must be either an array or Traversable');
|
||||
}
|
||||
@@ -177,7 +182,7 @@ class StandardAutoloader implements SplAutoloader
|
||||
*/
|
||||
public function registerPrefix($prefix, $directory)
|
||||
{
|
||||
$prefix = rtrim($prefix, self::PREFIX_SEPARATOR). self::PREFIX_SEPARATOR;
|
||||
$prefix = rtrim($prefix, self::PREFIX_SEPARATOR) . self::PREFIX_SEPARATOR;
|
||||
$this->prefixes[$prefix] = $this->normalizeDirectory($directory);
|
||||
return $this;
|
||||
}
|
||||
@@ -191,7 +196,7 @@ class StandardAutoloader implements SplAutoloader
|
||||
*/
|
||||
public function registerPrefixes($prefixes)
|
||||
{
|
||||
if (! is_array($prefixes) && ! $prefixes instanceof \Traversable) {
|
||||
if (! is_array($prefixes) && ! $prefixes instanceof Traversable) {
|
||||
require_once __DIR__ . '/Exception/InvalidArgumentException.php';
|
||||
throw new Exception\InvalidArgumentException('Prefix pairs must be either an array or Traversable');
|
||||
}
|
||||
@@ -257,8 +262,8 @@ class StandardAutoloader implements SplAutoloader
|
||||
$matches = [];
|
||||
preg_match('/(?P<namespace>.+\\\)?(?P<class>[^\\\]+$)/', $class, $matches);
|
||||
|
||||
$class = (isset($matches['class'])) ? $matches['class'] : '';
|
||||
$namespace = (isset($matches['namespace'])) ? $matches['namespace'] : '';
|
||||
$class = $matches['class'] ?? '';
|
||||
$namespace = $matches['namespace'] ?? '';
|
||||
|
||||
return $directory
|
||||
. str_replace(self::NS_SEPARATOR, '/', $namespace)
|
||||
|
||||
Reference in New Issue
Block a user