update v1.0.7.9 R.C.
This is a Release Candidate. We are still testing.
This commit is contained in:
229
vendor/zendframework/zend-loader/CONTRIBUTING.md
vendored
Normal file
229
vendor/zendframework/zend-loader/CONTRIBUTING.md
vendored
Normal file
@@ -0,0 +1,229 @@
|
||||
# CONTRIBUTING
|
||||
|
||||
## RESOURCES
|
||||
|
||||
If you wish to contribute to Zend Framework, please be sure to
|
||||
read/subscribe to the following resources:
|
||||
|
||||
- [Coding Standards](https://github.com/zendframework/zf2/wiki/Coding-Standards)
|
||||
- [Contributor's Guide](http://framework.zend.com/participate/contributor-guide)
|
||||
- ZF Contributor's mailing list:
|
||||
Archives: http://zend-framework-community.634137.n4.nabble.com/ZF-Contributor-f680267.html
|
||||
Subscribe: zf-contributors-subscribe@lists.zend.com
|
||||
- ZF Contributor's IRC channel:
|
||||
#zftalk.dev on Freenode.net
|
||||
|
||||
If you are working on new features or refactoring [create a proposal](https://github.com/zendframework/zend-loader/issues/new).
|
||||
|
||||
## Reporting Potential Security Issues
|
||||
|
||||
If you have encountered a potential security vulnerability, please **DO NOT** report it on the public
|
||||
issue tracker: send it to us at [zf-security@zend.com](mailto:zf-security@zend.com) instead.
|
||||
We will work with you to verify the vulnerability and patch it as soon as possible.
|
||||
|
||||
When reporting issues, please provide the following information:
|
||||
|
||||
- Component(s) affected
|
||||
- A description indicating how to reproduce the issue
|
||||
- A summary of the security vulnerability and impact
|
||||
|
||||
We request that you contact us via the email address above and give the project
|
||||
contributors a chance to resolve the vulnerability and issue a new release prior
|
||||
to any public exposure; this helps protect users and provides them with a chance
|
||||
to upgrade and/or update in order to protect their applications.
|
||||
|
||||
For sensitive email communications, please use [our PGP key](http://framework.zend.com/zf-security-pgp-key.asc).
|
||||
|
||||
## RUNNING TESTS
|
||||
|
||||
> ### Note: testing versions prior to 2.4
|
||||
>
|
||||
> This component originates with Zend Framework 2. During the lifetime of ZF2,
|
||||
> testing infrastructure migrated from PHPUnit 3 to PHPUnit 4. In most cases, no
|
||||
> changes were necessary. However, due to the migration, tests may not run on
|
||||
> versions < 2.4. As such, you may need to change the PHPUnit dependency if
|
||||
> attempting a fix on such a version.
|
||||
|
||||
To run tests:
|
||||
|
||||
- Clone the repository:
|
||||
|
||||
```console
|
||||
$ git clone git@github.com:zendframework/zend-loader.git
|
||||
$ cd
|
||||
```
|
||||
|
||||
- Install dependencies via composer:
|
||||
|
||||
```console
|
||||
$ curl -sS https://getcomposer.org/installer | php --
|
||||
$ ./composer.phar install
|
||||
```
|
||||
|
||||
If you don't have `curl` installed, you can also download `composer.phar` from https://getcomposer.org/
|
||||
|
||||
- Run the tests via `phpunit` and the provided PHPUnit config, like in this example:
|
||||
|
||||
```console
|
||||
$ ./vendor/bin/phpunit
|
||||
```
|
||||
|
||||
You can turn on conditional tests with the phpunit.xml file.
|
||||
To do so:
|
||||
|
||||
- Copy `phpunit.xml.dist` file to `phpunit.xml`
|
||||
- Edit `phpunit.xml` to enable any specific functionality you
|
||||
want to test, as well as to provide test values to utilize.
|
||||
|
||||
## Running Coding Standards Checks
|
||||
|
||||
This component uses [php-cs-fixer](http://cs.sensiolabs.org/) for coding
|
||||
standards checks, and provides configuration for our selected checks.
|
||||
`php-cs-fixer` is installed by default via Composer.
|
||||
|
||||
To run checks only:
|
||||
|
||||
```console
|
||||
$ ./vendor/bin/php-cs-fixer fix . -v --diff --dry-run --config-file=.php_cs
|
||||
```
|
||||
|
||||
To have `php-cs-fixer` attempt to fix problems for you, omit the `--dry-run`
|
||||
flag:
|
||||
|
||||
```console
|
||||
$ ./vendor/bin/php-cs-fixer fix . -v --diff --config-file=.php_cs
|
||||
```
|
||||
|
||||
If you allow php-cs-fixer to fix CS issues, please re-run the tests to ensure
|
||||
they pass, and make sure you add and commit the changes after verification.
|
||||
|
||||
## Recommended Workflow for Contributions
|
||||
|
||||
Your first step is to establish a public repository from which we can
|
||||
pull your work into the master repository. We recommend using
|
||||
[GitHub](https://github.com), as that is where the component is already hosted.
|
||||
|
||||
1. Setup a [GitHub account](http://github.com/), if you haven't yet
|
||||
2. Fork the repository (http://github.com/zendframework/zend-loader)
|
||||
3. Clone the canonical repository locally and enter it.
|
||||
|
||||
```console
|
||||
$ git clone git://github.com:zendframework/zend-loader.git
|
||||
$ cd zend-loader
|
||||
```
|
||||
|
||||
4. Add a remote to your fork; substitute your GitHub username in the command
|
||||
below.
|
||||
|
||||
```console
|
||||
$ git remote add {username} git@github.com:{username}/zend-loader.git
|
||||
$ git fetch {username}
|
||||
```
|
||||
|
||||
### Keeping Up-to-Date
|
||||
|
||||
Periodically, you should update your fork or personal repository to
|
||||
match the canonical ZF repository. Assuming you have setup your local repository
|
||||
per the instructions above, you can do the following:
|
||||
|
||||
|
||||
```console
|
||||
$ git checkout master
|
||||
$ git fetch origin
|
||||
$ git rebase origin/master
|
||||
# OPTIONALLY, to keep your remote up-to-date -
|
||||
$ git push {username} master:master
|
||||
```
|
||||
|
||||
If you're tracking other branches -- for example, the "develop" branch, where
|
||||
new feature development occurs -- you'll want to do the same operations for that
|
||||
branch; simply substitute "develop" for "master".
|
||||
|
||||
### Working on a patch
|
||||
|
||||
We recommend you do each new feature or bugfix in a new branch. This simplifies
|
||||
the task of code review as well as the task of merging your changes into the
|
||||
canonical repository.
|
||||
|
||||
A typical workflow will then consist of the following:
|
||||
|
||||
1. Create a new local branch based off either your master or develop branch.
|
||||
2. Switch to your new local branch. (This step can be combined with the
|
||||
previous step with the use of `git checkout -b`.)
|
||||
3. Do some work, commit, repeat as necessary.
|
||||
4. Push the local branch to your remote repository.
|
||||
5. Send a pull request.
|
||||
|
||||
The mechanics of this process are actually quite trivial. Below, we will
|
||||
create a branch for fixing an issue in the tracker.
|
||||
|
||||
```console
|
||||
$ git checkout -b hotfix/9295
|
||||
Switched to a new branch 'hotfix/9295'
|
||||
```
|
||||
|
||||
... do some work ...
|
||||
|
||||
|
||||
```console
|
||||
$ git commit
|
||||
```
|
||||
|
||||
... write your log message ...
|
||||
|
||||
|
||||
```console
|
||||
$ git push {username} hotfix/9295:hotfix/9295
|
||||
Counting objects: 38, done.
|
||||
Delta compression using up to 2 threads.
|
||||
Compression objects: 100% (18/18), done.
|
||||
Writing objects: 100% (20/20), 8.19KiB, done.
|
||||
Total 20 (delta 12), reused 0 (delta 0)
|
||||
To ssh://git@github.com/{username}/zend-loader.git
|
||||
b5583aa..4f51698 HEAD -> master
|
||||
```
|
||||
|
||||
To send a pull request, you have two options.
|
||||
|
||||
If using GitHub, you can do the pull request from there. Navigate to
|
||||
your repository, select the branch you just created, and then select the
|
||||
"Pull Request" button in the upper right. Select the user/organization
|
||||
"zendframework" as the recipient.
|
||||
|
||||
If using your own repository - or even if using GitHub - you can use `git
|
||||
format-patch` to create a patchset for us to apply; in fact, this is
|
||||
**recommended** for security-related patches. If you use `format-patch`, please
|
||||
send the patches as attachments to:
|
||||
|
||||
- zf-devteam@zend.com for patches without security implications
|
||||
- zf-security@zend.com for security patches
|
||||
|
||||
#### What branch to issue the pull request against?
|
||||
|
||||
Which branch should you issue a pull request against?
|
||||
|
||||
- For fixes against the stable release, issue the pull request against the
|
||||
"master" branch.
|
||||
- For new features, or fixes that introduce new elements to the public API (such
|
||||
as new public methods or properties), issue the pull request against the
|
||||
"develop" branch.
|
||||
|
||||
### Branch Cleanup
|
||||
|
||||
As you might imagine, if you are a frequent contributor, you'll start to
|
||||
get a ton of branches both locally and on your remote.
|
||||
|
||||
Once you know that your changes have been accepted to the master
|
||||
repository, we suggest doing some cleanup of these branches.
|
||||
|
||||
- Local branch cleanup
|
||||
|
||||
```console
|
||||
$ git branch -d <branchname>
|
||||
```
|
||||
|
||||
- Remote branch removal
|
||||
|
||||
```console
|
||||
$ git push {username} :<branchname>
|
||||
```
|
28
vendor/zendframework/zend-loader/LICENSE.md
vendored
Normal file
28
vendor/zendframework/zend-loader/LICENSE.md
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
Copyright (c) 2005-2015, Zend Technologies USA, Inc.
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
- Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
|
||||
- Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
- Neither the name of Zend Technologies USA, Inc. nor the names of its
|
||||
contributors may be used to endorse or promote products derived from this
|
||||
software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
10
vendor/zendframework/zend-loader/README.md
vendored
Normal file
10
vendor/zendframework/zend-loader/README.md
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
# zend-loader
|
||||
|
||||
[](https://secure.travis-ci.org/zendframework/zend-loader)
|
||||
[](https://coveralls.io/r/zendframework/zend-loader?branch=master)
|
||||
|
||||
`Zend\Loader` provides different strategies for autoloading PHP classes.
|
||||
|
||||
|
||||
- File issues at https://github.com/zendframework/zend-loader/issues
|
||||
- Documentation is at http://framework.zend.com/manual/current/en/index.html#zend-loader
|
35
vendor/zendframework/zend-loader/composer.json
vendored
Normal file
35
vendor/zendframework/zend-loader/composer.json
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"name": "zendframework/zend-loader",
|
||||
"description": " ",
|
||||
"license": "BSD-3-Clause",
|
||||
"keywords": [
|
||||
"zf2",
|
||||
"loader"
|
||||
],
|
||||
"homepage": "https://github.com/zendframework/zend-loader",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Zend\\Loader\\": "src/"
|
||||
}
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3.23"
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"prefer-stable": true,
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.5-dev",
|
||||
"dev-develop": "2.6-dev"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"ZendTest\\Loader\\": "test/"
|
||||
}
|
||||
},
|
||||
"require-dev": {
|
||||
"fabpot/php-cs-fixer": "1.7.*",
|
||||
"phpunit/PHPUnit": "~4.0"
|
||||
}
|
||||
}
|
211
vendor/zendframework/zend-loader/src/AutoloaderFactory.php
vendored
Normal file
211
vendor/zendframework/zend-loader/src/AutoloaderFactory.php
vendored
Normal file
@@ -0,0 +1,211 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Loader;
|
||||
|
||||
use Traversable;
|
||||
|
||||
if (class_exists('Zend\Loader\AutoloaderFactory')) {
|
||||
return;
|
||||
}
|
||||
|
||||
abstract class AutoloaderFactory
|
||||
{
|
||||
const STANDARD_AUTOLOADER = 'Zend\Loader\StandardAutoloader';
|
||||
|
||||
/**
|
||||
* @var array All autoloaders registered using the factory
|
||||
*/
|
||||
protected static $loaders = array();
|
||||
|
||||
/**
|
||||
* @var StandardAutoloader StandardAutoloader instance for resolving
|
||||
* autoloader classes via the include_path
|
||||
*/
|
||||
protected static $standardAutoloader;
|
||||
|
||||
/**
|
||||
* Factory for autoloaders
|
||||
*
|
||||
* Options should be an array or Traversable object of the following structure:
|
||||
* <code>
|
||||
* array(
|
||||
* '<autoloader class name>' => $autoloaderOptions,
|
||||
* )
|
||||
* </code>
|
||||
*
|
||||
* The factory will then loop through and instantiate each autoloader with
|
||||
* the specified options, and register each with the spl_autoloader.
|
||||
*
|
||||
* You may retrieve the concrete autoloader instances later using
|
||||
* {@link getRegisteredAutoloaders()}.
|
||||
*
|
||||
* Note that the class names must be resolvable on the include_path or via
|
||||
* the Zend library, using PSR-0 rules (unless the class has already been
|
||||
* loaded).
|
||||
*
|
||||
* @param array|Traversable $options (optional) options to use. Defaults to Zend\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
|
||||
*/
|
||||
public static function factory($options = null)
|
||||
{
|
||||
if (null === $options) {
|
||||
if (!isset(static::$loaders[static::STANDARD_AUTOLOADER])) {
|
||||
$autoloader = static::getStandardAutoloader();
|
||||
$autoloader->register();
|
||||
static::$loaders[static::STANDARD_AUTOLOADER] = $autoloader;
|
||||
}
|
||||
|
||||
// Return so we don't hit the next check's exception (we're done here anyway)
|
||||
return;
|
||||
}
|
||||
|
||||
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'
|
||||
);
|
||||
}
|
||||
|
||||
foreach ($options as $class => $autoloaderOptions) {
|
||||
if (!isset(static::$loaders[$class])) {
|
||||
$autoloader = static::getStandardAutoloader();
|
||||
if (!class_exists($class) && !$autoloader->autoload($class)) {
|
||||
require_once 'Exception/InvalidArgumentException.php';
|
||||
throw new Exception\InvalidArgumentException(
|
||||
sprintf('Autoloader class "%s" not loaded', $class)
|
||||
);
|
||||
}
|
||||
|
||||
if (!is_subclass_of($class, 'Zend\Loader\SplAutoloader')) {
|
||||
require_once 'Exception/InvalidArgumentException.php';
|
||||
throw new Exception\InvalidArgumentException(
|
||||
sprintf('Autoloader class %s must implement Zend\\Loader\\SplAutoloader', $class)
|
||||
);
|
||||
}
|
||||
|
||||
if ($class === static::STANDARD_AUTOLOADER) {
|
||||
$autoloader->setOptions($autoloaderOptions);
|
||||
} else {
|
||||
$autoloader = new $class($autoloaderOptions);
|
||||
}
|
||||
$autoloader->register();
|
||||
static::$loaders[$class] = $autoloader;
|
||||
} else {
|
||||
static::$loaders[$class]->setOptions($autoloaderOptions);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all autoloaders registered with the factory
|
||||
*
|
||||
* Returns an array of autoloader instances.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getRegisteredAutoloaders()
|
||||
{
|
||||
return static::$loaders;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves an autoloader by class name
|
||||
*
|
||||
* @param string $class
|
||||
* @return SplAutoloader
|
||||
* @throws Exception\InvalidArgumentException for non-registered class
|
||||
*/
|
||||
public static function getRegisteredAutoloader($class)
|
||||
{
|
||||
if (!isset(static::$loaders[$class])) {
|
||||
require_once 'Exception/InvalidArgumentException.php';
|
||||
throw new Exception\InvalidArgumentException(sprintf('Autoloader class "%s" not loaded', $class));
|
||||
}
|
||||
return static::$loaders[$class];
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters all autoloaders that have been registered via the factory.
|
||||
* This will NOT unregister autoloaders registered outside of the fctory.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function unregisterAutoloaders()
|
||||
{
|
||||
foreach (static::getRegisteredAutoloaders() as $class => $autoloader) {
|
||||
spl_autoload_unregister(array($autoloader, 'autoload'));
|
||||
unset(static::$loaders[$class]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister a single autoloader by class name
|
||||
*
|
||||
* @param string $autoloaderClass
|
||||
* @return bool
|
||||
*/
|
||||
public static function unregisterAutoloader($autoloaderClass)
|
||||
{
|
||||
if (!isset(static::$loaders[$autoloaderClass])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$autoloader = static::$loaders[$autoloaderClass];
|
||||
spl_autoload_unregister(array($autoloader, 'autoload'));
|
||||
unset(static::$loaders[$autoloaderClass]);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an instance of the standard autoloader
|
||||
*
|
||||
* Used to attempt to resolve autoloader classes, using the
|
||||
* StandardAutoloader. The instance is marked as a fallback autoloader, to
|
||||
* allow resolving autoloaders not under the "Zend" namespace.
|
||||
*
|
||||
* @return SplAutoloader
|
||||
*/
|
||||
protected static function getStandardAutoloader()
|
||||
{
|
||||
if (null !== static::$standardAutoloader) {
|
||||
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();
|
||||
static::$standardAutoloader = $loader;
|
||||
return static::$standardAutoloader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the object has this class as one of its parents
|
||||
*
|
||||
* @see https://bugs.php.net/bug.php?id=53727
|
||||
* @see https://github.com/zendframework/zf2/pull/1807
|
||||
*
|
||||
* @deprecated since zf 2.3 requires PHP >= 5.3.23
|
||||
*
|
||||
* @param string $className
|
||||
* @param string $type
|
||||
* @return bool
|
||||
*/
|
||||
protected static function isSubclassOf($className, $type)
|
||||
{
|
||||
return is_subclass_of($className, $type);
|
||||
}
|
||||
}
|
221
vendor/zendframework/zend-loader/src/ClassMapAutoloader.php
vendored
Normal file
221
vendor/zendframework/zend-loader/src/ClassMapAutoloader.php
vendored
Normal file
@@ -0,0 +1,221 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Loader;
|
||||
|
||||
use Traversable;
|
||||
|
||||
// Grab SplAutoloader interface
|
||||
require_once __DIR__ . '/SplAutoloader.php';
|
||||
|
||||
/**
|
||||
* Class-map autoloader
|
||||
*
|
||||
* Utilizes class-map files to lookup classfile locations.
|
||||
*/
|
||||
class ClassMapAutoloader implements SplAutoloader
|
||||
{
|
||||
/**
|
||||
* Registry of map files that have already been loaded
|
||||
* @var array
|
||||
*/
|
||||
protected $mapsLoaded = array();
|
||||
|
||||
/**
|
||||
* Class name/filename map
|
||||
* @var array
|
||||
*/
|
||||
protected $map = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Create a new instance, and optionally configure the autoloader.
|
||||
*
|
||||
* @param null|array|Traversable $options
|
||||
*/
|
||||
public function __construct($options = null)
|
||||
{
|
||||
if (null !== $options) {
|
||||
$this->setOptions($options);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the autoloader
|
||||
*
|
||||
* Proxies to {@link registerAutoloadMaps()}.
|
||||
*
|
||||
* @param array|Traversable $options
|
||||
* @return ClassMapAutoloader
|
||||
*/
|
||||
public function setOptions($options)
|
||||
{
|
||||
$this->registerAutoloadMaps($options);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an autoload map
|
||||
*
|
||||
* An autoload map may be either an associative array, or a file returning
|
||||
* an associative array.
|
||||
*
|
||||
* An autoload map should be an associative array containing
|
||||
* classname/file pairs.
|
||||
*
|
||||
* @param string|array $map
|
||||
* @throws Exception\InvalidArgumentException
|
||||
* @return ClassMapAutoloader
|
||||
*/
|
||||
public function registerAutoloadMap($map)
|
||||
{
|
||||
if (is_string($map)) {
|
||||
$location = $map;
|
||||
if ($this === ($map = $this->loadMapFromFile($location))) {
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_array($map)) {
|
||||
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))
|
||||
));
|
||||
}
|
||||
|
||||
$this->map = $map + $this->map;
|
||||
|
||||
if (isset($location)) {
|
||||
$this->mapsLoaded[] = $location;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register many autoload maps at once
|
||||
*
|
||||
* @param array $locations
|
||||
* @throws Exception\InvalidArgumentException
|
||||
* @return ClassMapAutoloader
|
||||
*/
|
||||
public function registerAutoloadMaps($locations)
|
||||
{
|
||||
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');
|
||||
}
|
||||
foreach ($locations as $location) {
|
||||
$this->registerAutoloadMap($location);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve current autoload map
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAutoloadMap()
|
||||
{
|
||||
return $this->map;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function autoload($class)
|
||||
{
|
||||
if (isset($this->map[$class])) {
|
||||
require_once $this->map[$class];
|
||||
|
||||
return $class;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the autoloader with spl_autoload registry
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
spl_autoload_register(array($this, 'autoload'), true, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a map from a file
|
||||
*
|
||||
* If the map has been previously loaded, returns the current instance;
|
||||
* otherwise, returns whatever was returned by calling include() on the
|
||||
* location.
|
||||
*
|
||||
* @param string $location
|
||||
* @return ClassMapAutoloader|mixed
|
||||
* @throws Exception\InvalidArgumentException for nonexistent locations
|
||||
*/
|
||||
protected function loadMapFromFile($location)
|
||||
{
|
||||
if (!file_exists($location)) {
|
||||
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))
|
||||
));
|
||||
}
|
||||
|
||||
if (!$path = static::realPharPath($location)) {
|
||||
$path = realpath($location);
|
||||
}
|
||||
|
||||
if (in_array($path, $this->mapsLoaded)) {
|
||||
// Already loaded this map
|
||||
return $this;
|
||||
}
|
||||
|
||||
$map = include $path;
|
||||
|
||||
return $map;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the real_path() to a file within a phar.
|
||||
*
|
||||
* @see https://bugs.php.net/bug.php?id=52769
|
||||
* @param string $path
|
||||
* @return string
|
||||
*/
|
||||
public static function realPharPath($path)
|
||||
{
|
||||
if (!preg_match('|^phar:(/{2,3})|', $path, $match)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$prefixLength = 5 + strlen($match[1]);
|
||||
$parts = explode('/', str_replace(array('/', '\\'), '/', substr($path, $prefixLength)));
|
||||
$parts = array_values(array_filter($parts, function ($p) {
|
||||
return ($p !== '' && $p !== '.');
|
||||
}));
|
||||
|
||||
array_walk($parts, function ($value, $key) use (&$parts) {
|
||||
if ($value === '..') {
|
||||
unset($parts[$key], $parts[$key-1]);
|
||||
$parts = array_values($parts);
|
||||
}
|
||||
});
|
||||
|
||||
if (file_exists($realPath = str_pad('phar:', $prefixLength, '/') . implode('/', $parts))) {
|
||||
return $realPath;
|
||||
}
|
||||
}
|
||||
}
|
17
vendor/zendframework/zend-loader/src/Exception/BadMethodCallException.php
vendored
Normal file
17
vendor/zendframework/zend-loader/src/Exception/BadMethodCallException.php
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Loader\Exception;
|
||||
|
||||
require_once __DIR__ . '/ExceptionInterface.php';
|
||||
|
||||
class BadMethodCallException extends \BadMethodCallException implements
|
||||
ExceptionInterface
|
||||
{
|
||||
}
|
16
vendor/zendframework/zend-loader/src/Exception/DomainException.php
vendored
Normal file
16
vendor/zendframework/zend-loader/src/Exception/DomainException.php
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Loader\Exception;
|
||||
|
||||
require_once __DIR__ . '/ExceptionInterface.php';
|
||||
|
||||
class DomainException extends \DomainException implements ExceptionInterface
|
||||
{
|
||||
}
|
14
vendor/zendframework/zend-loader/src/Exception/ExceptionInterface.php
vendored
Normal file
14
vendor/zendframework/zend-loader/src/Exception/ExceptionInterface.php
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Loader\Exception;
|
||||
|
||||
interface ExceptionInterface
|
||||
{
|
||||
}
|
16
vendor/zendframework/zend-loader/src/Exception/InvalidArgumentException.php
vendored
Normal file
16
vendor/zendframework/zend-loader/src/Exception/InvalidArgumentException.php
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Loader\Exception;
|
||||
|
||||
require_once __DIR__ . '/ExceptionInterface.php';
|
||||
|
||||
class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface
|
||||
{
|
||||
}
|
16
vendor/zendframework/zend-loader/src/Exception/InvalidPathException.php
vendored
Normal file
16
vendor/zendframework/zend-loader/src/Exception/InvalidPathException.php
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Loader\Exception;
|
||||
|
||||
require_once __DIR__ . '/ExceptionInterface.php';
|
||||
|
||||
class InvalidPathException extends \Exception implements ExceptionInterface
|
||||
{
|
||||
}
|
16
vendor/zendframework/zend-loader/src/Exception/MissingResourceNamespaceException.php
vendored
Normal file
16
vendor/zendframework/zend-loader/src/Exception/MissingResourceNamespaceException.php
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Loader\Exception;
|
||||
|
||||
require_once __DIR__ . '/ExceptionInterface.php';
|
||||
|
||||
class MissingResourceNamespaceException extends \Exception implements ExceptionInterface
|
||||
{
|
||||
}
|
19
vendor/zendframework/zend-loader/src/Exception/PluginLoaderException.php
vendored
Normal file
19
vendor/zendframework/zend-loader/src/Exception/PluginLoaderException.php
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Loader\Exception;
|
||||
|
||||
require_once __DIR__ . '/DomainException.php';
|
||||
|
||||
/**
|
||||
* Plugin class loader exceptions
|
||||
*/
|
||||
class PluginLoaderException extends DomainException
|
||||
{
|
||||
}
|
16
vendor/zendframework/zend-loader/src/Exception/RuntimeException.php
vendored
Normal file
16
vendor/zendframework/zend-loader/src/Exception/RuntimeException.php
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Loader\Exception;
|
||||
|
||||
require_once __DIR__ . '/ExceptionInterface.php';
|
||||
|
||||
class RuntimeException extends \RuntimeException implements ExceptionInterface
|
||||
{
|
||||
}
|
16
vendor/zendframework/zend-loader/src/Exception/SecurityException.php
vendored
Normal file
16
vendor/zendframework/zend-loader/src/Exception/SecurityException.php
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Loader\Exception;
|
||||
|
||||
require_once __DIR__ . '/DomainException.php';
|
||||
|
||||
class SecurityException extends DomainException
|
||||
{
|
||||
}
|
442
vendor/zendframework/zend-loader/src/ModuleAutoloader.php
vendored
Normal file
442
vendor/zendframework/zend-loader/src/ModuleAutoloader.php
vendored
Normal file
@@ -0,0 +1,442 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Loader;
|
||||
|
||||
// Grab SplAutoloader interface
|
||||
require_once __DIR__ . '/SplAutoloader.php';
|
||||
|
||||
use GlobIterator;
|
||||
use Phar;
|
||||
use PharFileInfo;
|
||||
use SplFileInfo;
|
||||
use Traversable;
|
||||
|
||||
class ModuleAutoloader implements SplAutoloader
|
||||
{
|
||||
/**
|
||||
* @var array An array of module paths to scan
|
||||
*/
|
||||
protected $paths = array();
|
||||
|
||||
/**
|
||||
* @var array An array of modulename => path
|
||||
*/
|
||||
protected $explicitPaths = array();
|
||||
|
||||
/**
|
||||
* @var array An array of namespaceName => namespacePath
|
||||
*/
|
||||
protected $namespacedPaths = array();
|
||||
|
||||
/**
|
||||
* @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)
|
||||
*/
|
||||
protected $pharExtensions = array();
|
||||
|
||||
/**
|
||||
* @var array An array of module classes to their containing files
|
||||
*/
|
||||
protected $moduleClassMap = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Allow configuration of the autoloader via the constructor.
|
||||
*
|
||||
* @param null|array|Traversable $options
|
||||
*/
|
||||
public function __construct($options = null)
|
||||
{
|
||||
if (extension_loaded('phar')) {
|
||||
$this->pharBasePath = Phar::running(true);
|
||||
$this->pharExtensions = array(
|
||||
'phar',
|
||||
'phar.tar',
|
||||
'tar',
|
||||
);
|
||||
|
||||
// ext/zlib enabled -> phar can read gzip & zip compressed files
|
||||
if (extension_loaded('zlib')) {
|
||||
$this->pharExtensions[] = 'phar.gz';
|
||||
$this->pharExtensions[] = 'phar.tar.gz';
|
||||
$this->pharExtensions[] = 'tar.gz';
|
||||
|
||||
$this->pharExtensions[] = 'phar.zip';
|
||||
$this->pharExtensions[] = 'zip';
|
||||
}
|
||||
|
||||
// ext/bzip2 enabled -> phar can read bz2 compressed files
|
||||
if (extension_loaded('bzip2')) {
|
||||
$this->pharExtensions[] = 'phar.bz2';
|
||||
$this->pharExtensions[] = 'phar.tar.bz2';
|
||||
$this->pharExtensions[] = 'tar.bz2';
|
||||
}
|
||||
}
|
||||
|
||||
if (null !== $options) {
|
||||
$this->setOptions($options);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the autoloader
|
||||
*
|
||||
* In most cases, $options should be either an associative array or
|
||||
* Traversable object.
|
||||
*
|
||||
* @param array|Traversable $options
|
||||
* @return ModuleAutoloader
|
||||
*/
|
||||
public function setOptions($options)
|
||||
{
|
||||
$this->registerPaths($options);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the class map for all loaded modules.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getModuleClassMap()
|
||||
{
|
||||
return $this->moduleClassMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the class map used to speed up the module autoloading.
|
||||
*
|
||||
* @param array $classmap
|
||||
* @return ModuleAutoloader
|
||||
*/
|
||||
public function setModuleClassMap(array $classmap)
|
||||
{
|
||||
$this->moduleClassMap = $classmap;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Autoload a class
|
||||
*
|
||||
* @param $class
|
||||
* @return mixed
|
||||
* False [if unable to load $class]
|
||||
* get_class($class) [if $class is successfully loaded]
|
||||
*/
|
||||
public function autoload($class)
|
||||
{
|
||||
// Limit scope of this autoloader
|
||||
if (substr($class, -7) !== '\Module') {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isset($this->moduleClassMap[$class])) {
|
||||
require_once $this->moduleClassMap[$class];
|
||||
return $class;
|
||||
}
|
||||
|
||||
$moduleName = substr($class, 0, -7);
|
||||
if (isset($this->explicitPaths[$moduleName])) {
|
||||
$classLoaded = $this->loadModuleFromDir($this->explicitPaths[$moduleName], $class);
|
||||
if ($classLoaded) {
|
||||
return $classLoaded;
|
||||
}
|
||||
|
||||
$classLoaded = $this->loadModuleFromPhar($this->explicitPaths[$moduleName], $class);
|
||||
if ($classLoaded) {
|
||||
return $classLoaded;
|
||||
}
|
||||
}
|
||||
|
||||
if (count($this->namespacedPaths) >= 1) {
|
||||
foreach ($this->namespacedPaths as $namespace => $path) {
|
||||
if (false === strpos($moduleName, $namespace)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$moduleNameBuffer = str_replace($namespace . "\\", "", $moduleName);
|
||||
$path .= DIRECTORY_SEPARATOR . $moduleNameBuffer . DIRECTORY_SEPARATOR;
|
||||
|
||||
$classLoaded = $this->loadModuleFromDir($path, $class);
|
||||
if ($classLoaded) {
|
||||
return $classLoaded;
|
||||
}
|
||||
|
||||
$classLoaded = $this->loadModuleFromPhar($path, $class);
|
||||
if ($classLoaded) {
|
||||
return $classLoaded;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$moduleClassPath = str_replace('\\', DIRECTORY_SEPARATOR, $moduleName);
|
||||
|
||||
$pharSuffixPattern = null;
|
||||
if ($this->pharExtensions) {
|
||||
$pharSuffixPattern = '(' . implode('|', array_map('preg_quote', $this->pharExtensions)) . ')';
|
||||
}
|
||||
|
||||
foreach ($this->paths as $path) {
|
||||
$path = $path . $moduleClassPath;
|
||||
|
||||
if ($path == '.' || substr($path, 0, 2) == './' || substr($path, 0, 2) == '.\\') {
|
||||
if (!$basePath = $this->pharBasePath) {
|
||||
$basePath = realpath('.');
|
||||
}
|
||||
|
||||
if (false === $basePath) {
|
||||
$basePath = getcwd();
|
||||
}
|
||||
|
||||
$path = rtrim($basePath, '\/\\') . substr($path, 1);
|
||||
}
|
||||
|
||||
$classLoaded = $this->loadModuleFromDir($path, $class);
|
||||
if ($classLoaded) {
|
||||
return $classLoaded;
|
||||
}
|
||||
|
||||
// No directory with Module.php, searching for phars
|
||||
if ($pharSuffixPattern) {
|
||||
foreach (new GlobIterator($path . '.*') as $entry) {
|
||||
if ($entry->isDir()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!preg_match('#.+\.' . $pharSuffixPattern . '$#', $entry->getPathname())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$classLoaded = $this->loadModuleFromPhar($entry->getPathname(), $class);
|
||||
if ($classLoaded) {
|
||||
return $classLoaded;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* loadModuleFromDir
|
||||
*
|
||||
* @param string $dirPath
|
||||
* @param string $class
|
||||
* @return mixed
|
||||
* False [if unable to load $class]
|
||||
* get_class($class) [if $class is successfully loaded]
|
||||
*/
|
||||
protected function loadModuleFromDir($dirPath, $class)
|
||||
{
|
||||
$modulePath = $dirPath . '/Module.php';
|
||||
if (substr($modulePath, 0, 7) === 'phar://') {
|
||||
$file = new PharFileInfo($modulePath);
|
||||
} else {
|
||||
$file = new SplFileInfo($modulePath);
|
||||
}
|
||||
|
||||
if (($file->isReadable() && $file->isFile())) {
|
||||
// Found directory with Module.php in it
|
||||
$absModulePath = $this->pharBasePath ? (string) $file : $file->getRealPath();
|
||||
require_once $absModulePath;
|
||||
if (class_exists($class)) {
|
||||
$this->moduleClassMap[$class] = $absModulePath;
|
||||
return $class;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* loadModuleFromPhar
|
||||
*
|
||||
* @param string $pharPath
|
||||
* @param string $class
|
||||
* @return mixed
|
||||
* False [if unable to load $class]
|
||||
* get_class($class) [if $class is successfully loaded]
|
||||
*/
|
||||
protected function loadModuleFromPhar($pharPath, $class)
|
||||
{
|
||||
$pharPath = static::normalizePath($pharPath, false);
|
||||
$file = new SplFileInfo($pharPath);
|
||||
if (!$file->isReadable() || !$file->isFile()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$fileRealPath = $file->getRealPath();
|
||||
|
||||
// Phase 0: Check for executable phar with Module class in stub
|
||||
if (strpos($fileRealPath, '.phar') !== false) {
|
||||
// First see if the stub makes the Module class available
|
||||
require_once $fileRealPath;
|
||||
if (class_exists($class)) {
|
||||
$this->moduleClassMap[$class] = $fileRealPath;
|
||||
return $class;
|
||||
}
|
||||
}
|
||||
|
||||
// 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);
|
||||
if ($moduleFile->isReadable() && $moduleFile->isFile()) {
|
||||
require_once $moduleClassFile;
|
||||
if (class_exists($class)) {
|
||||
$this->moduleClassMap[$class] = $moduleClassFile;
|
||||
return $class;
|
||||
}
|
||||
}
|
||||
|
||||
// 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);
|
||||
if ($moduleFile->isReadable() && $moduleFile->isFile()) {
|
||||
require_once $moduleClassFile;
|
||||
if (class_exists($class)) {
|
||||
$this->moduleClassMap[$class] = $moduleClassFile;
|
||||
return $class;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the autoloader with spl_autoload registry
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
spl_autoload_register(array($this, 'autoload'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister the autoloader with spl_autoload registry
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unregister()
|
||||
{
|
||||
spl_autoload_unregister(array($this, 'autoload'));
|
||||
}
|
||||
|
||||
/**
|
||||
* registerPaths
|
||||
*
|
||||
* @param array|Traversable $paths
|
||||
* @throws \InvalidArgumentException
|
||||
* @return ModuleAutoloader
|
||||
*/
|
||||
public function registerPaths($paths)
|
||||
{
|
||||
if (!is_array($paths) && !$paths instanceof Traversable) {
|
||||
require_once __DIR__ . '/Exception/InvalidArgumentException.php';
|
||||
throw new Exception\InvalidArgumentException(
|
||||
'Parameter to \\Zend\\Loader\\ModuleAutoloader\'s '
|
||||
. 'registerPaths method must be an array or '
|
||||
. 'implement the Traversable interface'
|
||||
);
|
||||
}
|
||||
|
||||
foreach ($paths as $module => $path) {
|
||||
if (is_string($module)) {
|
||||
$this->registerPath($path, $module);
|
||||
} else {
|
||||
$this->registerPath($path);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* registerPath
|
||||
*
|
||||
* @param string $path
|
||||
* @param bool|string $moduleName
|
||||
* @throws \InvalidArgumentException
|
||||
* @return ModuleAutoloader
|
||||
*/
|
||||
public function registerPath($path, $moduleName = false)
|
||||
{
|
||||
if (!is_string($path)) {
|
||||
require_once __DIR__ . '/Exception/InvalidArgumentException.php';
|
||||
throw new Exception\InvalidArgumentException(sprintf(
|
||||
'Invalid path provided; must be a string, received %s',
|
||||
gettype($path)
|
||||
));
|
||||
}
|
||||
if ($moduleName) {
|
||||
if (in_array(substr($moduleName, -2), array('\\*', '\\%'))) {
|
||||
$this->namespacedPaths[substr($moduleName, 0, -2)] = static::normalizePath($path);
|
||||
} else {
|
||||
$this->explicitPaths[$moduleName] = static::normalizePath($path);
|
||||
}
|
||||
} else {
|
||||
$this->paths[] = static::normalizePath($path);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* getPaths
|
||||
*
|
||||
* This is primarily for unit testing, but could have other uses.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPaths()
|
||||
{
|
||||
return $this->paths;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the base module name from the path to a phar
|
||||
*
|
||||
* @param string $pharPath
|
||||
* @return string
|
||||
*/
|
||||
protected function pharFileToModuleName($pharPath)
|
||||
{
|
||||
do {
|
||||
$pathinfo = pathinfo($pharPath);
|
||||
$pharPath = $pathinfo['filename'];
|
||||
} while (isset($pathinfo['extension']));
|
||||
return $pathinfo['filename'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize a path for insertion in the stack
|
||||
*
|
||||
* @param string $path
|
||||
* @param bool $trailingSlash Whether trailing slash should be included
|
||||
* @return string
|
||||
*/
|
||||
public static function normalizePath($path, $trailingSlash = true)
|
||||
{
|
||||
$path = rtrim($path, '/');
|
||||
$path = rtrim($path, '\\');
|
||||
if ($trailingSlash) {
|
||||
$path .= DIRECTORY_SEPARATOR;
|
||||
}
|
||||
return $path;
|
||||
}
|
||||
}
|
217
vendor/zendframework/zend-loader/src/PluginClassLoader.php
vendored
Normal file
217
vendor/zendframework/zend-loader/src/PluginClassLoader.php
vendored
Normal file
@@ -0,0 +1,217 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Loader;
|
||||
|
||||
use ArrayIterator;
|
||||
use IteratorAggregate;
|
||||
use Traversable;
|
||||
|
||||
/**
|
||||
* Plugin class locator interface
|
||||
*/
|
||||
class PluginClassLoader implements PluginClassLocator
|
||||
{
|
||||
/**
|
||||
* List of plugin name => class name pairs
|
||||
* @var array
|
||||
*/
|
||||
protected $plugins = array();
|
||||
|
||||
/**
|
||||
* Static map allow global seeding of plugin loader
|
||||
* @var array
|
||||
*/
|
||||
protected static $staticMap = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param null|array|Traversable $map If provided, seeds the loader with a map
|
||||
*/
|
||||
public function __construct($map = null)
|
||||
{
|
||||
// Merge in static overrides
|
||||
if (!empty(static::$staticMap)) {
|
||||
$this->registerPlugins(static::$staticMap);
|
||||
}
|
||||
|
||||
// Merge in constructor arguments
|
||||
if ($map !== null) {
|
||||
$this->registerPlugins($map);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a static map of plugins
|
||||
*
|
||||
* A null value will clear the static map.
|
||||
*
|
||||
* @param null|array|Traversable $map
|
||||
* @throws Exception\InvalidArgumentException
|
||||
* @return void
|
||||
*/
|
||||
public static function addStaticMap($map)
|
||||
{
|
||||
if (null === $map) {
|
||||
static::$staticMap = array();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!is_array($map) && !$map instanceof Traversable) {
|
||||
throw new Exception\InvalidArgumentException('Expects an array or Traversable object');
|
||||
}
|
||||
foreach ($map as $key => $value) {
|
||||
static::$staticMap[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a class to a given short name
|
||||
*
|
||||
* @param string $shortName
|
||||
* @param string $className
|
||||
* @return PluginClassLoader
|
||||
*/
|
||||
public function registerPlugin($shortName, $className)
|
||||
{
|
||||
$this->plugins[strtolower($shortName)] = $className;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register many plugins at once
|
||||
*
|
||||
* If $map is a string, assumes that the map is the class name of a
|
||||
* Traversable object (likely a ShortNameLocator); it will then instantiate
|
||||
* this class and use it to register plugins.
|
||||
*
|
||||
* If $map is an array or Traversable object, it will iterate it to
|
||||
* register plugin names/classes.
|
||||
*
|
||||
* For all other arguments, or if the string $map is not a class or not a
|
||||
* Traversable class, an exception will be raised.
|
||||
*
|
||||
* @param string|array|Traversable $map
|
||||
* @return PluginClassLoader
|
||||
* @throws Exception\InvalidArgumentException
|
||||
*/
|
||||
public function registerPlugins($map)
|
||||
{
|
||||
if (is_string($map)) {
|
||||
if (!class_exists($map)) {
|
||||
throw new Exception\InvalidArgumentException('Map class provided is invalid');
|
||||
}
|
||||
$map = new $map;
|
||||
}
|
||||
if (is_array($map)) {
|
||||
$map = new ArrayIterator($map);
|
||||
}
|
||||
if (!$map instanceof Traversable) {
|
||||
throw new Exception\InvalidArgumentException('Map provided is invalid; must be traversable');
|
||||
}
|
||||
|
||||
// iterator_apply doesn't work as expected with IteratorAggregate
|
||||
if ($map instanceof IteratorAggregate) {
|
||||
$map = $map->getIterator();
|
||||
}
|
||||
|
||||
foreach ($map as $name => $class) {
|
||||
if (is_int($name) || is_numeric($name)) {
|
||||
if (!is_object($class) && class_exists($class)) {
|
||||
$class = new $class();
|
||||
}
|
||||
|
||||
if ($class instanceof Traversable) {
|
||||
$this->registerPlugins($class);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$this->registerPlugin($name, $class);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister a short name lookup
|
||||
*
|
||||
* @param mixed $shortName
|
||||
* @return PluginClassLoader
|
||||
*/
|
||||
public function unregisterPlugin($shortName)
|
||||
{
|
||||
$lookup = strtolower($shortName);
|
||||
if (array_key_exists($lookup, $this->plugins)) {
|
||||
unset($this->plugins[$lookup]);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all registered plugins
|
||||
*
|
||||
* @return array|Traversable
|
||||
*/
|
||||
public function getRegisteredPlugins()
|
||||
{
|
||||
return $this->plugins;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not a plugin by a specific name has been registered
|
||||
*
|
||||
* @param string $name
|
||||
* @return bool
|
||||
*/
|
||||
public function isLoaded($name)
|
||||
{
|
||||
$lookup = strtolower($name);
|
||||
return isset($this->plugins[$lookup]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return full class name for a named helper
|
||||
*
|
||||
* @param string $name
|
||||
* @return string|false
|
||||
*/
|
||||
public function getClassName($name)
|
||||
{
|
||||
return $this->load($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a helper via the name provided
|
||||
*
|
||||
* @param string $name
|
||||
* @return string|false
|
||||
*/
|
||||
public function load($name)
|
||||
{
|
||||
if (!$this->isLoaded($name)) {
|
||||
return false;
|
||||
}
|
||||
return $this->plugins[strtolower($name)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Defined by IteratorAggregate
|
||||
*
|
||||
* Returns an instance of ArrayIterator, containing a map of
|
||||
* all plugins
|
||||
*
|
||||
* @return ArrayIterator
|
||||
*/
|
||||
public function getIterator()
|
||||
{
|
||||
return new ArrayIterator($this->plugins);
|
||||
}
|
||||
}
|
43
vendor/zendframework/zend-loader/src/PluginClassLocator.php
vendored
Normal file
43
vendor/zendframework/zend-loader/src/PluginClassLocator.php
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Loader;
|
||||
|
||||
use IteratorAggregate;
|
||||
use Traversable;
|
||||
|
||||
/**
|
||||
* Plugin class locator interface
|
||||
*/
|
||||
interface PluginClassLocator extends ShortNameLocator, IteratorAggregate
|
||||
{
|
||||
/**
|
||||
* Register a class to a given short name
|
||||
*
|
||||
* @param string $shortName
|
||||
* @param string $className
|
||||
* @return PluginClassLocator
|
||||
*/
|
||||
public function registerPlugin($shortName, $className);
|
||||
|
||||
/**
|
||||
* Unregister a short name lookup
|
||||
*
|
||||
* @param mixed $shortName
|
||||
* @return void
|
||||
*/
|
||||
public function unregisterPlugin($shortName);
|
||||
|
||||
/**
|
||||
* Get a list of all registered plugins
|
||||
*
|
||||
* @return array|Traversable
|
||||
*/
|
||||
public function getRegisteredPlugins();
|
||||
}
|
40
vendor/zendframework/zend-loader/src/ShortNameLocator.php
vendored
Normal file
40
vendor/zendframework/zend-loader/src/ShortNameLocator.php
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Loader;
|
||||
|
||||
/**
|
||||
* Short name locator interface
|
||||
*/
|
||||
interface ShortNameLocator
|
||||
{
|
||||
/**
|
||||
* Whether or not a Helper by a specific name
|
||||
*
|
||||
* @param string $name
|
||||
* @return bool
|
||||
*/
|
||||
public function isLoaded($name);
|
||||
|
||||
/**
|
||||
* Return full class name for a named helper
|
||||
*
|
||||
* @param string $name
|
||||
* @return string
|
||||
*/
|
||||
public function getClassName($name);
|
||||
|
||||
/**
|
||||
* Load a helper via the name provided
|
||||
*
|
||||
* @param string $name
|
||||
* @return string
|
||||
*/
|
||||
public function load($name);
|
||||
}
|
65
vendor/zendframework/zend-loader/src/SplAutoloader.php
vendored
Normal file
65
vendor/zendframework/zend-loader/src/SplAutoloader.php
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Loader;
|
||||
|
||||
use Traversable;
|
||||
|
||||
if (interface_exists('Zend\Loader\SplAutoloader')) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines an interface for classes that may register with the spl_autoload
|
||||
* registry
|
||||
*/
|
||||
interface SplAutoloader
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Allow configuration of the autoloader via the constructor.
|
||||
*
|
||||
* @param null|array|Traversable $options
|
||||
*/
|
||||
public function __construct($options = null);
|
||||
|
||||
/**
|
||||
* Configure the autoloader
|
||||
*
|
||||
* In most cases, $options should be either an associative array or
|
||||
* Traversable object.
|
||||
*
|
||||
* @param array|Traversable $options
|
||||
* @return SplAutoloader
|
||||
*/
|
||||
public function setOptions($options);
|
||||
|
||||
/**
|
||||
* Autoload a class
|
||||
*
|
||||
* @param $class
|
||||
* @return mixed
|
||||
* False [if unable to load $class]
|
||||
* get_class($class) [if $class is successfully loaded]
|
||||
*/
|
||||
public function autoload($class);
|
||||
|
||||
/**
|
||||
* Register the autoloader with spl_autoload registry
|
||||
*
|
||||
* Typically, the body of this will simply be:
|
||||
* <code>
|
||||
* spl_autoload_register(array($this, 'autoload'));
|
||||
* </code>
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register();
|
||||
}
|
327
vendor/zendframework/zend-loader/src/StandardAutoloader.php
vendored
Normal file
327
vendor/zendframework/zend-loader/src/StandardAutoloader.php
vendored
Normal file
@@ -0,0 +1,327 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Loader;
|
||||
|
||||
// Grab SplAutoloader interface
|
||||
require_once __DIR__ . '/SplAutoloader.php';
|
||||
|
||||
/**
|
||||
* PSR-0 compliant autoloader
|
||||
*
|
||||
* Allows autoloading both namespaced and vendor-prefixed classes. Class
|
||||
* lookups are performed on the filesystem. If a class file for the referenced
|
||||
* class is not found, a PHP warning will be raised by include().
|
||||
*/
|
||||
class StandardAutoloader implements SplAutoloader
|
||||
{
|
||||
const NS_SEPARATOR = '\\';
|
||||
const PREFIX_SEPARATOR = '_';
|
||||
const LOAD_NS = 'namespaces';
|
||||
const LOAD_PREFIX = 'prefixes';
|
||||
const ACT_AS_FALLBACK = 'fallback_autoloader';
|
||||
const AUTOREGISTER_ZF = 'autoregister_zf';
|
||||
|
||||
/**
|
||||
* @var array Namespace/directory pairs to search; ZF library added by default
|
||||
*/
|
||||
protected $namespaces = array();
|
||||
|
||||
/**
|
||||
* @var array Prefix/directory pairs to search
|
||||
*/
|
||||
protected $prefixes = array();
|
||||
|
||||
/**
|
||||
* @var bool Whether or not the autoloader should also act as a fallback autoloader
|
||||
*/
|
||||
protected $fallbackAutoloaderFlag = false;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param null|array|\Traversable $options
|
||||
*/
|
||||
public function __construct($options = null)
|
||||
{
|
||||
if (null !== $options) {
|
||||
$this->setOptions($options);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure autoloader
|
||||
*
|
||||
* Allows specifying both "namespace" and "prefix" pairs, using the
|
||||
* following structure:
|
||||
* <code>
|
||||
* array(
|
||||
* 'namespaces' => array(
|
||||
* 'Zend' => '/path/to/Zend/library',
|
||||
* 'Doctrine' => '/path/to/Doctrine/library',
|
||||
* ),
|
||||
* 'prefixes' => array(
|
||||
* 'Phly_' => '/path/to/Phly/library',
|
||||
* ),
|
||||
* 'fallback_autoloader' => true,
|
||||
* )
|
||||
* </code>
|
||||
*
|
||||
* @param array|\Traversable $options
|
||||
* @throws Exception\InvalidArgumentException
|
||||
* @return StandardAutoloader
|
||||
*/
|
||||
public function setOptions($options)
|
||||
{
|
||||
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');
|
||||
}
|
||||
|
||||
foreach ($options as $type => $pairs) {
|
||||
switch ($type) {
|
||||
case self::AUTOREGISTER_ZF:
|
||||
if ($pairs) {
|
||||
$this->registerNamespace('Zend', dirname(__DIR__));
|
||||
$this->registerNamespace('ZendXml', dirname(dirname((__DIR__))) . DIRECTORY_SEPARATOR . 'ZendXml');
|
||||
}
|
||||
break;
|
||||
case self::LOAD_NS:
|
||||
if (is_array($pairs) || $pairs instanceof \Traversable) {
|
||||
$this->registerNamespaces($pairs);
|
||||
}
|
||||
break;
|
||||
case self::LOAD_PREFIX:
|
||||
if (is_array($pairs) || $pairs instanceof \Traversable) {
|
||||
$this->registerPrefixes($pairs);
|
||||
}
|
||||
break;
|
||||
case self::ACT_AS_FALLBACK:
|
||||
$this->setFallbackAutoloader($pairs);
|
||||
break;
|
||||
default:
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set flag indicating fallback autoloader status
|
||||
*
|
||||
* @param bool $flag
|
||||
* @return StandardAutoloader
|
||||
*/
|
||||
public function setFallbackAutoloader($flag)
|
||||
{
|
||||
$this->fallbackAutoloaderFlag = (bool) $flag;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this autoloader acting as a fallback autoloader?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isFallbackAutoloader()
|
||||
{
|
||||
return $this->fallbackAutoloaderFlag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a namespace/directory pair
|
||||
*
|
||||
* @param string $namespace
|
||||
* @param string $directory
|
||||
* @return StandardAutoloader
|
||||
*/
|
||||
public function registerNamespace($namespace, $directory)
|
||||
{
|
||||
$namespace = rtrim($namespace, self::NS_SEPARATOR) . self::NS_SEPARATOR;
|
||||
$this->namespaces[$namespace] = $this->normalizeDirectory($directory);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register many namespace/directory pairs at once
|
||||
*
|
||||
* @param array $namespaces
|
||||
* @throws Exception\InvalidArgumentException
|
||||
* @return StandardAutoloader
|
||||
*/
|
||||
public function registerNamespaces($namespaces)
|
||||
{
|
||||
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');
|
||||
}
|
||||
|
||||
foreach ($namespaces as $namespace => $directory) {
|
||||
$this->registerNamespace($namespace, $directory);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a prefix/directory pair
|
||||
*
|
||||
* @param string $prefix
|
||||
* @param string $directory
|
||||
* @return StandardAutoloader
|
||||
*/
|
||||
public function registerPrefix($prefix, $directory)
|
||||
{
|
||||
$prefix = rtrim($prefix, self::PREFIX_SEPARATOR). self::PREFIX_SEPARATOR;
|
||||
$this->prefixes[$prefix] = $this->normalizeDirectory($directory);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register many namespace/directory pairs at once
|
||||
*
|
||||
* @param array $prefixes
|
||||
* @throws Exception\InvalidArgumentException
|
||||
* @return StandardAutoloader
|
||||
*/
|
||||
public function registerPrefixes($prefixes)
|
||||
{
|
||||
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');
|
||||
}
|
||||
|
||||
foreach ($prefixes as $prefix => $directory) {
|
||||
$this->registerPrefix($prefix, $directory);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defined by Autoloadable; autoload a class
|
||||
*
|
||||
* @param string $class
|
||||
* @return false|string
|
||||
*/
|
||||
public function autoload($class)
|
||||
{
|
||||
$isFallback = $this->isFallbackAutoloader();
|
||||
if (false !== strpos($class, self::NS_SEPARATOR)) {
|
||||
if ($this->loadClass($class, self::LOAD_NS)) {
|
||||
return $class;
|
||||
} elseif ($isFallback) {
|
||||
return $this->loadClass($class, self::ACT_AS_FALLBACK);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (false !== strpos($class, self::PREFIX_SEPARATOR)) {
|
||||
if ($this->loadClass($class, self::LOAD_PREFIX)) {
|
||||
return $class;
|
||||
} elseif ($isFallback) {
|
||||
return $this->loadClass($class, self::ACT_AS_FALLBACK);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if ($isFallback) {
|
||||
return $this->loadClass($class, self::ACT_AS_FALLBACK);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the autoloader with spl_autoload
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
spl_autoload_register(array($this, 'autoload'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform the class name to a filename
|
||||
*
|
||||
* @param string $class
|
||||
* @param string $directory
|
||||
* @return string
|
||||
*/
|
||||
protected function transformClassNameToFilename($class, $directory)
|
||||
{
|
||||
// $class may contain a namespace portion, in which case we need
|
||||
// to preserve any underscores in that portion.
|
||||
$matches = array();
|
||||
preg_match('/(?P<namespace>.+\\\)?(?P<class>[^\\\]+$)/', $class, $matches);
|
||||
|
||||
$class = (isset($matches['class'])) ? $matches['class'] : '';
|
||||
$namespace = (isset($matches['namespace'])) ? $matches['namespace'] : '';
|
||||
|
||||
return $directory
|
||||
. str_replace(self::NS_SEPARATOR, '/', $namespace)
|
||||
. str_replace(self::PREFIX_SEPARATOR, '/', $class)
|
||||
. '.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a class, based on its type (namespaced or prefixed)
|
||||
*
|
||||
* @param string $class
|
||||
* @param string $type
|
||||
* @return bool|string
|
||||
* @throws Exception\InvalidArgumentException
|
||||
*/
|
||||
protected function loadClass($class, $type)
|
||||
{
|
||||
if (!in_array($type, array(self::LOAD_NS, self::LOAD_PREFIX, self::ACT_AS_FALLBACK))) {
|
||||
require_once __DIR__ . '/Exception/InvalidArgumentException.php';
|
||||
throw new Exception\InvalidArgumentException();
|
||||
}
|
||||
|
||||
// Fallback autoloading
|
||||
if ($type === self::ACT_AS_FALLBACK) {
|
||||
// create filename
|
||||
$filename = $this->transformClassNameToFilename($class, '');
|
||||
$resolvedName = stream_resolve_include_path($filename);
|
||||
if ($resolvedName !== false) {
|
||||
return include $resolvedName;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Namespace and/or prefix autoloading
|
||||
foreach ($this->$type as $leader => $path) {
|
||||
if (0 === strpos($class, $leader)) {
|
||||
// Trim off leader (namespace or prefix)
|
||||
$trimmedClass = substr($class, strlen($leader));
|
||||
|
||||
// create filename
|
||||
$filename = $this->transformClassNameToFilename($trimmedClass, $path);
|
||||
if (file_exists($filename)) {
|
||||
return include $filename;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize the directory to include a trailing directory separator
|
||||
*
|
||||
* @param string $directory
|
||||
* @return string
|
||||
*/
|
||||
protected function normalizeDirectory($directory)
|
||||
{
|
||||
$last = $directory[strlen($directory) - 1];
|
||||
if (in_array($last, array('/', '\\'))) {
|
||||
$directory[strlen($directory) - 1] = DIRECTORY_SEPARATOR;
|
||||
return $directory;
|
||||
}
|
||||
$directory .= DIRECTORY_SEPARATOR;
|
||||
return $directory;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user