diff options
author | Bernhard Posselt <dev@bernhard-posselt.com> | 2015-01-27 09:17:15 +0100 |
---|---|---|
committer | Bernhard Posselt <dev@bernhard-posselt.com> | 2015-01-27 09:17:15 +0100 |
commit | fe3969f3759998d3f567a6769535640be69ea1e9 (patch) | |
tree | 774efc15376860697c0648e49bf8066317b0d118 /vendor | |
parent | 32ec52747b7f2e25df273471bc6be480aa2dcca9 (diff) |
remove xxe checks for loadHML since it is apparenly no possible to exploit it
Diffstat (limited to 'vendor')
-rw-r--r-- | vendor/ZendXml/.gitignore | 5 | ||||
-rw-r--r-- | vendor/ZendXml/.travis.yml | 29 | ||||
-rw-r--r-- | vendor/ZendXml/README.md | 50 | ||||
-rw-r--r-- | vendor/ZendXml/composer.json | 40 | ||||
-rw-r--r-- | vendor/ZendXml/library/ZendXml/Exception/ExceptionInterface.php | 14 | ||||
-rw-r--r-- | vendor/ZendXml/library/ZendXml/Exception/InvalidArgumentException.php | 17 | ||||
-rw-r--r-- | vendor/ZendXml/library/ZendXml/Exception/RuntimeException.php | 17 | ||||
-rw-r--r-- | vendor/ZendXml/library/ZendXml/Security.php | 168 | ||||
-rw-r--r-- | vendor/ZendXml/tests/Bootstrap.php | 92 | ||||
-rw-r--r-- | vendor/ZendXml/tests/ZendXmlTest/SecurityTest.php | 152 | ||||
-rwxr-xr-x | vendor/ZendXml/tests/phpunit.xml.dist | 27 | ||||
-rw-r--r-- | vendor/ZendXml/vendor/autoload.php | 7 | ||||
-rw-r--r-- | vendor/ZendXml/vendor/composer/ClassLoader.php | 383 | ||||
-rw-r--r-- | vendor/ZendXml/vendor/composer/autoload_classmap.php | 9 | ||||
-rw-r--r-- | vendor/ZendXml/vendor/composer/autoload_namespaces.php | 10 | ||||
-rw-r--r-- | vendor/ZendXml/vendor/composer/autoload_psr4.php | 10 | ||||
-rw-r--r-- | vendor/ZendXml/vendor/composer/autoload_real.php | 50 |
17 files changed, 0 insertions, 1080 deletions
diff --git a/vendor/ZendXml/.gitignore b/vendor/ZendXml/.gitignore deleted file mode 100644 index 0a4f6e27f..000000000 --- a/vendor/ZendXml/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -composer.lock -vendor -.buildpath -.project -.settings diff --git a/vendor/ZendXml/.travis.yml b/vendor/ZendXml/.travis.yml deleted file mode 100644 index ad8db966f..000000000 --- a/vendor/ZendXml/.travis.yml +++ /dev/null @@ -1,29 +0,0 @@ -language: php -php: - - 5.3 - - 5.4 - - 5.5 - - 5.6 - - hhvm - -matrix: - allow_failures: - - php: hhvm - -before_install: - # need to update libxml to 2.7.8 to be able to run tests using the - # LIBXML_HTML_NODEFDTD and LIBXML_HTML_NOIMPLIED libxml constant - - sudo apt-get update - - sudo apt-get -o DPkg::Options::="--force-confold" -y upgrade - -before_script: - - composer self-update - - composer install --dev - -script: - - ./vendor/bin/phpunit -c ./tests - - ./vendor/bin/phpcs --standard=PSR2 --ignore=tests/Bootstrap.php library tests - -notifications: - irc: "irc.freenode.org#zftalk.dev" - email: false diff --git a/vendor/ZendXml/README.md b/vendor/ZendXml/README.md deleted file mode 100644 index 2c67008da..000000000 --- a/vendor/ZendXml/README.md +++ /dev/null @@ -1,50 +0,0 @@ -ZendXml -======= - -An utility component for XML usage and best practices in PHP - -Installation ------------- - -You can install using: - -``` -curl -s https://getcomposer.org/installer | php -php composer.phar install -``` - -Notice that this library doesn't have any external dependencies, the usage of composer is for autoloading and standard purpose. - - -ZendXml\Security ----------------- - -This is a security component to prevent [XML eXternal Entity](https://www.owasp.org/index.php/XML_External_Entity_%28XXE%29_Processing) (XXE) and [XML Entity Expansion](http://projects.webappsec.org/w/page/13247002/XML%20Entity%20Expansion) (XEE) attacks on XML documents. - -The XXE attack is prevented disabling the load of external entities in the libxml library used by PHP, using the function [libxml_disable_entity_loader](http://www.php.net/manual/en/function.libxml-disable-entity-loader.php). - -The XEE attack is prevented looking inside the XML document for ENTITY usage. If the XML document uses ENTITY the library throw an Exception. - -We have two static methods to scan and load XML document from a string (scan) and from a file (scanFile). You can decide to get a SimpleXMLElement or DOMDocument as result, using the following use cases: - -```php -use ZendXml\Security as XmlSecurity; - -$xml = <<<XML -<?xml version="1.0"?> -<results> - <result>test</result> -</results> -XML; - -// SimpleXML use case -$simplexml = XmlSecurity::scan($xml); -printf ("SimpleXMLElement: %s\n", ($simplexml instanceof \SimpleXMLElement) ? 'yes' : 'no'); - -// DOMDocument use case -$dom = new \DOMDocument('1.0'); -$dom = XmlSecurity::scan($xml, $dom); -printf ("DOMDocument: %s\n", ($dom instanceof \DOMDocument) ? 'yes' : 'no'); -``` - - diff --git a/vendor/ZendXml/composer.json b/vendor/ZendXml/composer.json deleted file mode 100644 index 139f1e23b..000000000 --- a/vendor/ZendXml/composer.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "name": "zendframework/zendxml", - "description": "Utility library for XML usage, best practices, and security in PHP", - "type": "library", - "license": "BSD-3-Clause", - "keywords": [ - "zf2", - "xml", - "security" - ], - "homepage": "http://packages.zendframework.com/", - "autoload": { - "psr-0": { - "ZendXml\\": "library/" - } - }, - "autoload-dev": { - "psr-4": { - "ZendTest\\Xml\\": "tests/ZendXmlTest/" - } - }, - "repositories": [ - { - "type": "composer", - "url": "http://packages.zendframework.com/" - } - ], - "require": { - "php": ">=5.3.3" - }, - "extra": { - "branch-alias": { - "dev-master": "1.0-dev" - } - }, - "require-dev": { - "phpunit/phpunit": "~3.7", - "squizlabs/php_codesniffer": "~1.5" - } -} diff --git a/vendor/ZendXml/library/ZendXml/Exception/ExceptionInterface.php b/vendor/ZendXml/library/ZendXml/Exception/ExceptionInterface.php deleted file mode 100644 index c55eb9034..000000000 --- a/vendor/ZendXml/library/ZendXml/Exception/ExceptionInterface.php +++ /dev/null @@ -1,14 +0,0 @@ -<?php -/** - * Zend Framework (http://framework.zend.com/) - * - * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - */ - -namespace ZendXml\Exception; - -interface ExceptionInterface -{ -} diff --git a/vendor/ZendXml/library/ZendXml/Exception/InvalidArgumentException.php b/vendor/ZendXml/library/ZendXml/Exception/InvalidArgumentException.php deleted file mode 100644 index 0fef6b298..000000000 --- a/vendor/ZendXml/library/ZendXml/Exception/InvalidArgumentException.php +++ /dev/null @@ -1,17 +0,0 @@ -<?php -/** - * Zend Framework (http://framework.zend.com/) - * - * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - */ - -namespace ZendXml\Exception; - -/** - * Invalid argument exception - */ -class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface -{ -} diff --git a/vendor/ZendXml/library/ZendXml/Exception/RuntimeException.php b/vendor/ZendXml/library/ZendXml/Exception/RuntimeException.php deleted file mode 100644 index b730da4ff..000000000 --- a/vendor/ZendXml/library/ZendXml/Exception/RuntimeException.php +++ /dev/null @@ -1,17 +0,0 @@ -<?php -/** - * Zend Framework (http://framework.zend.com/) - * - * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - */ - -namespace ZendXml\Exception; - -/** - * Runtime exception - */ -class RuntimeException extends \RuntimeException implements ExceptionInterface -{ -} diff --git a/vendor/ZendXml/library/ZendXml/Security.php b/vendor/ZendXml/library/ZendXml/Security.php deleted file mode 100644 index e97a54d77..000000000 --- a/vendor/ZendXml/library/ZendXml/Security.php +++ /dev/null @@ -1,168 +0,0 @@ -<?php -/** - * Zend Framework (http://framework.zend.com/) - * - * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - */ -namespace ZendXml; - -use DOMDocument; -use SimpleXMLElement; - -class Security -{ - const ENTITY_DETECT = 'Detected use of ENTITY in XML, disabled to prevent XXE/XEE attacks'; - - /** - * Heuristic scan to detect entity in XML - * - * @param string $xml - * @throws Exception\RuntimeException - */ - protected static function heuristicScan($xml) - { - if (strpos($xml, '<!ENTITY') !== false) { - throw new Exception\RuntimeException(self::ENTITY_DETECT); - } - } - - /** - * Scan XML string for potential XXE and XEE attacks - * - * @param string $xml - * @param DomDocument $dom - * @param int $libXmlConstants additional libxml constants to pass in - * @param Callable $callback the callback to use to create the dom element - * @throws Exception\RuntimeException - * @return SimpleXMLElement|DomDocument|boolean - */ - private static function scanString($xml, $dom, $libXmlConstants, $callback) - { - // If running with PHP-FPM we perform an heuristic scan - // We cannot use libxml_disable_entity_loader because of this bug - // @see https://bugs.php.net/bug.php?id=64938 - if (self::isPhpFpm()) { - self::heuristicScan($xml); - } - - if (null === $dom) { - $simpleXml = true; - $dom = new DOMDocument(); - } - - if (!self::isPhpFpm()) { - $loadEntities = libxml_disable_entity_loader(true); - $useInternalXmlErrors = libxml_use_internal_errors(true); - } - - // Load XML with network access disabled (LIBXML_NONET) - // error disabled with @ for PHP-FPM scenario - set_error_handler(function ($errno, $errstr) { - if (substr_count($errstr, 'DOMDocument::loadXML()') > 0) { - return true; - } - return false; - }, E_WARNING); - - $result = $callback($xml, $dom, LIBXML_NONET | $libXmlConstants); - - restore_error_handler(); - - // Entity load to previous setting - if (!self::isPhpFpm()) { - libxml_disable_entity_loader($loadEntities); - libxml_use_internal_errors($useInternalXmlErrors); - } - - if (!$result) { - return false; - } - - // Scan for potential XEE attacks using ENTITY, if not PHP-FPM - if (!self::isPhpFpm()) { - foreach ($dom->childNodes as $child) { - if ($child->nodeType === XML_DOCUMENT_TYPE_NODE) { - if ($child->entities->length > 0) { - throw new Exception\RuntimeException(self::ENTITY_DETECT); - } - } - } - } - - if (isset($simpleXml)) { - $result = simplexml_import_dom($dom); - if (!$result instanceof SimpleXMLElement) { - return false; - } - return $result; - } - return $dom; - } - - /** - * Scan HTML string for potential XXE and XEE attacks - * - * @param string $xml - * @param DomDocument $dom - * @param int $libXmlConstants additional libxml constants to pass in - * @throws Exception\RuntimeException - * @return SimpleXMLElement|DomDocument|boolean - */ - public static function scanHtml($html, DOMDocument $dom = null, $libXmlConstants = 0) - { - $callback = function ($html, $dom, $constants) { - return $dom->loadHtml($html, $constants); - }; - return self::scanString($html, $dom, $libXmlConstants, $callback); - } - - /** - * Scan XML string for potential XXE and XEE attacks - * - * @param string $xml - * @param DomDocument $dom - * @param int $libXmlConstants additional libxml constants to pass in - * @throws Exception\RuntimeException - * @return SimpleXMLElement|DomDocument|boolean - */ - public static function scan($xml, DOMDocument $dom = null, $libXmlConstants = 0) - { - $callback = function ($xml, $dom, $constants) { - return $dom->loadXml($xml, $constants); - }; - return self::scanString($xml, $dom, $libXmlConstants, $callback); - } - - /** - * Scan XML file for potential XXE/XEE attacks - * - * @param string $file - * @param DOMDocument $dom - * @throws Exception\InvalidArgumentException - * @return SimpleXMLElement|DomDocument - */ - public static function scanFile($file, DOMDocument $dom = null) - { - if (!file_exists($file)) { - throw new Exception\InvalidArgumentException( - "The file $file specified doesn't exist" - ); - } - return self::scan(file_get_contents($file), $dom); - } - - /** - * Return true if PHP is running with PHP-FPM - * - * @return boolean - */ - public static function isPhpFpm() - { - if (substr(php_sapi_name(), 0, 3) === 'fpm') { - return true; - } - return false; - } -} diff --git a/vendor/ZendXml/tests/Bootstrap.php b/vendor/ZendXml/tests/Bootstrap.php deleted file mode 100644 index a9d0e6a55..000000000 --- a/vendor/ZendXml/tests/Bootstrap.php +++ /dev/null @@ -1,92 +0,0 @@ -<?php -/** - * Zend Framework (http://framework.zend.com/) - * - * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend - */ - -/** - * Set error reporting to the level to which Zend Framework code must comply. - */ -error_reporting( E_ALL | E_STRICT ); - -if (class_exists('PHPUnit_Runner_Version', true)) { - $phpUnitVersion = PHPUnit_Runner_Version::id(); - if ('@package_version@' !== $phpUnitVersion && version_compare($phpUnitVersion, '3.7.0', '<')) { - echo 'This version of PHPUnit (' . - PHPUnit_Runner_Version::id() . - ') is not supported for ZendXml unit tests - use v 3.7.0 or higher.' - . PHP_EOL - ; - exit(1); - } - unset($phpUnitVersion); -} - -/** - * Setup autoloading - */ -// Try to use Composer autoloader -if (file_exists(__DIR__ . '/../vendor/autoload.php')) { - include_once __DIR__ . '/../vendor/autoload.php'; -} -// ... or use a simple SPL autoloader -else{ - - // update include path - set_include_path(implode(PATH_SEPARATOR, array( - __DIR__.'/../src', - __DIR__, - get_include_path() - ))); - - /** - * @link https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md#example-implementation - */ - spl_autoload_register(function ($className) { - $className = ltrim($className, '\\'); - $fileName = ''; - $namespace = ''; - if ($lastNsPos = strrpos($className, '\\')) { - $namespace = substr($className, 0, $lastNsPos); - $className = substr($className, $lastNsPos + 1); - $fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR; - } - $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'; - require $fileName; - }); - -} - -/** - * Code coverage option - */ -if (defined('TESTS_GENERATE_REPORT') && TESTS_GENERATE_REPORT === true) { - $codeCoverageFilter = new PHP_CodeCoverage_Filter(); - - $lastArg = end($_SERVER['argv']); - if (is_dir($zfCoreTests . '/' . $lastArg)) { - $codeCoverageFilter->addDirectoryToWhitelist($zfCoreLibrary . '/' . $lastArg); - } elseif (is_file($zfCoreTests . '/' . $lastArg)) { - $codeCoverageFilter->addDirectoryToWhitelist(dirname($zfCoreLibrary . '/' . $lastArg)); - } else { - $codeCoverageFilter->addDirectoryToWhitelist($zfCoreLibrary); - } - - /* - * Omit from code coverage reports the contents of the tests directory - */ - $codeCoverageFilter->addDirectoryToBlacklist($zfCoreTests, ''); - $codeCoverageFilter->addDirectoryToBlacklist(PEAR_INSTALL_DIR, ''); - $codeCoverageFilter->addDirectoryToBlacklist(PHP_LIBDIR, ''); - - unset($codeCoverageFilter); -} - -/* - * Unset global variables that are no longer needed. - */ -unset($phpUnitVersion); diff --git a/vendor/ZendXml/tests/ZendXmlTest/SecurityTest.php b/vendor/ZendXml/tests/ZendXmlTest/SecurityTest.php deleted file mode 100644 index 0f0fbffba..000000000 --- a/vendor/ZendXml/tests/ZendXmlTest/SecurityTest.php +++ /dev/null @@ -1,152 +0,0 @@ -<?php -/** - * Zend Framework (http://framework.zend.com/) - * - * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - */ -namespace ZendTest\Xml; - -use ZendXml\Security as XmlSecurity; -use ZendXml\Exception; -use DOMDocument; -use SimpleXMLElement; - -class SecurityTest extends \PHPUnit_Framework_TestCase -{ - /** - * @expectedException ZendXml\Exception\RuntimeException - */ - public function testScanForXEE() - { - $xml = <<<XML -<?xml version="1.0"?> -<!DOCTYPE results [<!ENTITY harmless "completely harmless">]> -<results> - <result>This result is &harmless;</result> -</results> -XML; - - $this->setExpectedException('ZendXml\Exception\RuntimeException'); - $result = XmlSecurity::scan($xml); - } - - public function testScanForXXE() - { - $file = tempnam(sys_get_temp_dir(), 'ZendXml_Security'); - file_put_contents($file, 'This is a remote content!'); - $xml = <<<XML -<?xml version="1.0"?> -<!DOCTYPE root -[ -<!ENTITY foo SYSTEM "file://$file"> -]> -<results> - <result>&foo;</result> -</results> -XML; - - try { - $result = XmlSecurity::scan($xml); - } catch (Exception\RuntimeException $e) { - unlink($file); - return; - } - $this->fail('An expected exception has not been raised.'); - } - - public function testScanSimpleXmlResult() - { - $result = XmlSecurity::scan($this->getXml()); - $this->assertTrue($result instanceof SimpleXMLElement); - $this->assertEquals($result->result, 'test'); - } - - public function testScanDom() - { - $dom = new DOMDocument('1.0'); - $result = XmlSecurity::scan($this->getXml(), $dom); - $this->assertTrue($result instanceof DOMDocument); - $node = $result->getElementsByTagName('result')->item(0); - $this->assertEquals($node->nodeValue, 'test'); - } - - /** - * @requires PHP 5.4 - */ - public function testScanDomHTML() - { - // loadHtml accepts constants in php >= 5.4 - // http://php.net/manual/de/domdocument.loadhtml.php - $dom = new DOMDocument('1.0'); - $html = <<<HTML -<p>a simple test</p> -HTML; - $constants = LIBXML_HTML_NODEFDTD | LIBXML_HTML_NOIMPLIED; - $result = XmlSecurity::scanHtml($html, $dom, $constants); - $this->assertTrue($result instanceof DOMDocument); - $this->assertEquals($html, trim($result->saveHtml())); - } - - public function testScanInvalidXml() - { - $xml = <<<XML -<foo>test</bar> -XML; - - $result = XmlSecurity::scan($xml); - $this->assertFalse($result); - } - - public function testScanInvalidXmlDom() - { - $xml = <<<XML -<foo>test</bar> -XML; - - $dom = new DOMDocument('1.0'); - $result = XmlSecurity::scan($xml, $dom); - $this->assertFalse($result); - } - - public function testScanFile() - { - $file = tempnam(sys_get_temp_dir(), 'ZendXml_Security'); - file_put_contents($file, $this->getXml()); - - $result = XmlSecurity::scanFile($file); - $this->assertTrue($result instanceof SimpleXMLElement); - $this->assertEquals($result->result, 'test'); - unlink($file); - } - - public function testScanXmlWithDTD() - { - $xml = <<<XML -<?xml version="1.0"?> -<!DOCTYPE results [ -<!ELEMENT results (result+)> -<!ELEMENT result (#PCDATA)> -]> -<results> - <result>test</result> -</results> -XML; - - $dom = new DOMDocument('1.0'); - $result = XmlSecurity::scan($xml, $dom); - $this->assertTrue($result instanceof DOMDocument); - $this->assertTrue($result->validate()); - } - - protected function getXml() - { - return <<<XML -<?xml version="1.0"?> -<results> - <result>test</result> -</results> -XML; - } -} diff --git a/vendor/ZendXml/tests/phpunit.xml.dist b/vendor/ZendXml/tests/phpunit.xml.dist deleted file mode 100755 index 069784bd7..000000000 --- a/vendor/ZendXml/tests/phpunit.xml.dist +++ /dev/null @@ -1,27 +0,0 @@ -<phpunit bootstrap="./Bootstrap.php" colors="true"> - <testsuites> - <testsuite name="ZendXml Test Suite"> - <directory>./ZendXmlTest</directory> - <exclude>./ZendXmlTest/TestAsset</exclude> - </testsuite> - </testsuites> - - <groups> - <exclude> - </exclude> - </groups> - - <listeners> - </listeners> - - <filter> - <blacklist> - <directory suffix=".php">./ZendXmlTest</directory> - <directory>../vendor</directory> - </blacklist> - </filter> - - <php> - </php> - -</phpunit> diff --git a/vendor/ZendXml/vendor/autoload.php b/vendor/ZendXml/vendor/autoload.php deleted file mode 100644 index ec43ad18d..000000000 --- a/vendor/ZendXml/vendor/autoload.php +++ /dev/null @@ -1,7 +0,0 @@ -<?php - -// autoload.php @generated by Composer - -require_once __DIR__ . '/composer' . '/autoload_real.php'; - -return ComposerAutoloaderInitea88c51e6ab35b96029638db6e4797bb::getLoader(); diff --git a/vendor/ZendXml/vendor/composer/ClassLoader.php b/vendor/ZendXml/vendor/composer/ClassLoader.php deleted file mode 100644 index 443364959..000000000 --- a/vendor/ZendXml/vendor/composer/ClassLoader.php +++ /dev/null @@ -1,383 +0,0 @@ -<?php - -/* - * This file is part of Composer. - * - * (c) Nils Adermann <naderman@naderman.de> - * Jordi Boggiano <j.boggiano@seld.be> - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Composer\Autoload; - -/** - * ClassLoader implements a PSR-0 class loader - * - * See https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md - * - * $loader = new \Composer\Autoload\ClassLoader(); - * - * // register classes with namespaces - * $loader->add('Symfony\Component', __DIR__.'/component'); - * $loader->add('Symfony', __DIR__.'/framework'); - * - * // activate the autoloader - * $loader->register(); - * - * // to enable searching the include path (eg. for PEAR packages) - * $loader->setUseIncludePath(true); - * - * In this example, if you try to use a class in the Symfony\Component - * namespace or one of its children (Symfony\Component\Console for instance), - * the autoloader will first look for the class under the component/ - * directory, and it will then fallback to the framework/ directory if not - * found before giving up. - * - * This class is loosely based on the Symfony UniversalClassLoader. - * - * @author Fabien Potencier <fabien@symfony.com> - * @author Jordi Boggiano <j.boggiano@seld.be> - */ -class ClassLoader -{ - // PSR-4 - private $prefixLengthsPsr4 = array(); - private $prefixDirsPsr4 = array(); - private $fallbackDirsPsr4 = array(); - - // PSR-0 - private $prefixesPsr0 = array(); - private $fallbackDirsPsr0 = array(); - - private $useIncludePath = false; - private $classMap = array(); - - public function getPrefixes() - { - return call_user_func_array('array_merge', $this->prefixesPsr0); - } - - public function getPrefixesPsr4() - { - return $this->prefixDirsPsr4; - } - - public function getFallbackDirs() - { - return $this->fallbackDirsPsr0; - } - - public function getFallbackDirsPsr4() - { - return $this->fallbackDirsPsr4; - } - - public function getClassMap() - { - return $this->classMap; - } - - /** - * @param array $classMap Class to filename map - */ - public function addClassMap(array $classMap) - { - if ($this->classMap) { - $this->classMap = array_merge($this->classMap, $classMap); - } else { - $this->classMap = $classMap; - } - } - - /** - * Registers a set of PSR-0 directories for a given prefix, either - * appending or prepending to the ones previously set for this prefix. - * - * @param string $prefix The prefix - * @param array|string $paths The PSR-0 root directories - * @param bool $prepend Whether to prepend the directories - */ - public function add($prefix, $paths, $prepend = false) - { - if (!$prefix) { - if ($prepend) { - $this->fallbackDirsPsr0 = array_merge( - (array) $paths, - $this->fallbackDirsPsr0 - ); - } else { - $this->fallbackDirsPsr0 = array_merge( - $this->fallbackDirsPsr0, - (array) $paths - ); - } - - return; - } - - $first = $prefix[0]; - if (!isset($this->prefixesPsr0[$first][$prefix])) { - $this->prefixesPsr0[$first][$prefix] = (array) $paths; - - return; - } - if ($prepend) { - $this->prefixesPsr0[$first][$prefix] = array_merge( |