web/lib/Zend/Loader/ClassMapAutoloader.php
author Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
Fri, 01 Jan 2016 01:11:05 +0100
changeset 1308 ef42d4f12cfc
parent 1230 68c69c656a2c
permissions -rw-r--r--
add grammar version if on annotation + upgrade metadataplayer to take it into account

<?php
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Loader
 * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */

// Grab SplAutoloader interface
require_once dirname(__FILE__) . '/SplAutoloader.php';

/**
 * Class-map autoloader
 *
 * Utilizes class-map files to lookup classfile locations.
 * 
 * @package    Zend_Loader
 * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    New BSD {@link http://framework.zend.com/license/new-bsd}
 */
class Zend_Loader_ClassMapAutoloader implements Zend_Loader_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 
     * @return void
     */
    public function __construct($options = null)
    {
        if (null !== $options) {
            $this->setOptions($options);
        }
    }

    /**
     * Configure the autoloader
     *
     * Proxies to {@link registerAutoloadMaps()}.
     * 
     * @param  array|Traversable $options 
     * @return Zend_Loader_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 $location 
     * @return Zend_Loader_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 dirname(__FILE__) . '/Exception/InvalidArgumentException.php';
            throw new Zend_Loader_Exception_InvalidArgumentException('Map file provided does not return a map');
        }

        $this->map = array_merge($this->map, $map);

        if (isset($location)) {
            $this->mapsLoaded[] = $location;
        }

        return $this;
    }

    /**
     * Register many autoload maps at once
     * 
     * @param  array $locations 
     * @return Zend_Loader_ClassMapAutoloader
     */
    public function registerAutoloadMaps($locations)
    {
        if (!is_array($locations) && !($locations instanceof Traversable)) {
            require_once dirname(__FILE__) . '/Exception/InvalidArgumentException.php';
            throw new Zend_Loader_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;
    }

    /**
     * Defined by Autoloadable
     * 
     * @param  string $class 
     * @return void
     */
    public function autoload($class)
    {
        if (isset($this->map[$class])) {
            require_once $this->map[$class];
        }
    }

    /**
     * Register the autoloader with spl_autoload registry
     * 
     * @return void
     */
    public function register()
    {
        if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
            spl_autoload_register(array($this, 'autoload'), true, true);
        } else {
            spl_autoload_register(array($this, 'autoload'), 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 Zend_Loader_ClassMapAutoloader|mixed
     * @throws Zend_Loader_Exception_InvalidArgumentException for nonexistent locations
     */
    protected function loadMapFromFile($location)
    {
        if (!file_exists($location)) {
            require_once dirname(__FILE__) . '/Exception/InvalidArgumentException.php';
            throw new Zend_Loader_Exception_InvalidArgumentException('Map file provided does not exist');
        }

        if (!$path = self::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 (strpos($path, 'phar:///') !== 0) {
            return;
        }
        
        $parts = explode('/', str_replace(array('/','\\'), '/', substr($path, 8)));
        $parts = array_values(array_filter($parts, array(__CLASS__, 'concatPharParts')));

        array_walk($parts, array(__CLASS__, 'resolvePharParentPath'), $parts);

        if (file_exists($realPath = 'phar:///' . implode('/', $parts))) {
            return $realPath;
        }
    }

    /**
     * Helper callback for filtering phar paths
     * 
     * @param  string $part 
     * @return bool
     */
    public static function concatPharParts($part)
    {
        return ($part !== '' && $part !== '.');
    }

    /**
     * Helper callback to resolve a parent path in a Phar archive
     * 
     * @param  string $value 
     * @param  int $key 
     * @param  array $parts 
     * @return void
     */
    public static function resolvePharParentPath($value, $key, &$parts)
    {
        if ($value !== '...') {
            return;
        }
        unset($parts[$key], $parts[$key-1]);
        $parts = array_values($parts);
    }
}
PKƶL$ iconolab-b2702fa72a72/design/.keepmeUT6[PKƶL.qԾKQ+ ]iconolab-b2702fa72a72/design/components.odtUT6[PKƶL#&&> }Liconolab-b2702fa72a72/design/heatmap/Resources/SampleStyle.cssUT6[PKƶL4_4/ Miconolab-b2702fa72a72/design/heatmap/index.htmlUT6[PKƶL&rT` 9 Siconolab-b2702fa72a72/design/heatmap/pages/admin_page.pngUT6[PKƶL݌9 >iconolab-b2702fa72a72/design/heatmap/pages/admin_tags.pngUT6[PKƶL>`@ iconolab-b2702fa72a72/design/heatmap/pages/annotation_create.pngUT6[PKƶLQg L? iconolab-b2702fa72a72/design/heatmap/pages/annotation_saved.pngUT6[PKƶLQRs@ Ƶ iconolab-b2702fa72a72/design/heatmap/pages/choisir_une_image.pngUT6[PKƶL-\=9 K iconolab-b2702fa72a72/design/heatmap/pages/components.pngUT6[PKƶLx(R 5 iconolab-b2702fa72a72/design/heatmap/pages/folder.pngUT6[PKƶLҳ9^ O 6 (kiconolab-b2702fa72a72/design/heatmap/pages/heatmap.pngUT6[PKƶL4eϿ3 4kiconolab-b2702fa72a72/design/heatmap/pages/home.pngUT6[PKƶL`c' p ? jIiconolab-b2702fa72a72/design/heatmap/pages/image_principale.pngUT6[PKƶL'78 }q'iconolab-b2702fa72a72/design/heatmap/pages/image_tab.pngUT6[PKƶL]J.J6 s(iconolab-b2702fa72a72/design/heatmap/pages/landing.pngUT6[PKƶLC(4 *(iconolab-b2702fa72a72/design/heatmap/pages/login.pngUT6[PKƶLWb: (iconolab-b2702fa72a72/design/heatmap/pages/open_folder.pngUT6[PKƶLY@ rX.&I8 *7*iconolab-b2702fa72a72/design/heatmap/pages/user_page.pngUT6[PKƶLmtd ~9 e+iconolab-b2702fa72a72/design/heatmap/pages/user_pages.pngUT6[PKƶL#&&D y+iconolab-b2702fa72a72/design/iconolab/demo/Resources/SampleStyle.cssUT6[PKƶL*b~85 +iconolab-b2702fa72a72/design/iconolab/demo/index.htmlUT6[PKƶLG% n < `+iconolab-b2702fa72a72/design/iconolab/demo/pages/addatag.pngUT6[PKƶLgC W7iconolab-b2702fa72a72/design/iconolab/demo/pages/addtagwithlist.pngUT6[PKƶLIYI? 8>iconolab-b2702fa72a72/design/iconolab/demo/pages/admin_page.pngUT6[PKƶLk\v>/? @iconolab-b2702fa72a72/design/iconolab/demo/pages/admin_tags.pngUT6[PKƶL^5QC>fF RAiconolab-b2702fa72a72/design/iconolab/demo/pages/choisir_une_image.pngUT6[PKƶLFIF? Biconolab-b2702fa72a72/design/iconolab/demo/pages/components.pngUT6[PKƶL (riconolab-b2702fa72a72/design/iconolab/demo/pages/image_tab.pngUT6[PKƶL 7%VA< z>siconolab-b2702fa72a72/design/iconolab/demo/pages/landing.pngUT6[PKƶL( qMҾF@ $dsiconolab-b2702fa72a72/design/iconolab/demo/pages/links_pages.pngUT6[PKƶLC(: m#ticonolab-b2702fa72a72/design/iconolab/demo/pages/login.pngUT6[PKƶLw&fx B :ticonolab-b2702fa72a72/design/iconolab/demo/pages/qualification.pngUT6[PKƶL[(I ;ticonolab-b2702fa72a72/design/iconolab/demo/pages/save_detail_fragment.pngUT6[PKƶLYjdʚ}? 5 wiconolab-b2702fa72a72/design/iconolab/demo/pages/suggestion.pngUT6[PKƶLk~VG uwiconolab-b2702fa72a72/design/iconolab/demo/pages/suggestions_images.pngUT6[PKƶL wBE xiconolab-b2702fa72a72/design/iconolab/demo/pages/suggestions_tags.pngUT6[PKƶLyi F vyiconolab-b2702fa72a72/design/iconolab/demo/pages/user_notification.pngUT6[PKƶLŪQH yiconolab-b2702fa72a72/design/iconolab/demo/pages/user_notofication_2.pngUT6[PKƶLqƞ&A> Jziconolab-b2702fa72a72/design/iconolab/demo/pages/user_page.pngUT6[PKƶL{Zs? q{iconolab-b2702fa72a72/design/iconolab/demo/pages/user_pages.pngUT6[PKƶL= )D {iconolab-b2702fa72a72/design/iconolab/demo/pages/user_suggestion.pngUT6[PKƶL09g)M0 ~iconolab-b2702fa72a72/design/iconolab/dossier.epUT6[PKƶLFwPM 6 k~iconolab-b2702fa72a72/design/iconolab/ex_merge_form.epUT6[PK55tO/