web/Zend/Tool/Project/Context/Zf/ZfStandardLibraryDirectory.php
changeset 0 4eba9c11703f
equal deleted inserted replaced
-1:000000000000 0:4eba9c11703f
       
     1 <?php
       
     2 /**
       
     3  * Zend Framework
       
     4  *
       
     5  * LICENSE
       
     6  *
       
     7  * This source file is subject to the new BSD license that is bundled
       
     8  * with this package in the file LICENSE.txt.
       
     9  * It is also available through the world-wide-web at this URL:
       
    10  * http://framework.zend.com/license/new-bsd
       
    11  * If you did not receive a copy of the license and are unable to
       
    12  * obtain it through the world-wide-web, please send an email
       
    13  * to license@zend.com so we can send you a copy immediately.
       
    14  *
       
    15  * @category   Zend
       
    16  * @package    Zend_Tool
       
    17  * @subpackage Framework
       
    18  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    20  * @version    $Id: ZfStandardLibraryDirectory.php 20904 2010-02-04 16:18:18Z matthew $
       
    21  */
       
    22 
       
    23 /**
       
    24  * @see Zend_Tool_Project_Context_Filesystem_Directory
       
    25  */
       
    26 require_once 'Zend/Tool/Project/Context/Filesystem/Directory.php';
       
    27 
       
    28 /**
       
    29  * This class is the front most class for utilizing Zend_Tool_Project
       
    30  *
       
    31  * A profile is a hierarchical set of resources that keep track of
       
    32  * items within a specific project.
       
    33  *
       
    34  * @category   Zend
       
    35  * @package    Zend_Tool
       
    36  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    37  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    38  */
       
    39 class Zend_Tool_Project_Context_Zf_ZfStandardLibraryDirectory extends Zend_Tool_Project_Context_Filesystem_Directory
       
    40 {
       
    41 
       
    42     /**
       
    43      * @var string
       
    44      */
       
    45     protected $_filesystemName = 'Zend';
       
    46 
       
    47     /**
       
    48      * getName()
       
    49      *
       
    50      * @return string
       
    51      */
       
    52     public function getName()
       
    53     {
       
    54         return 'ZfStandardLibraryDirectory';
       
    55     }
       
    56 
       
    57     /**
       
    58      * create()
       
    59      *
       
    60      */
       
    61     public function create()
       
    62     {
       
    63         parent::create();
       
    64         $zfPath = $this->_getZfPath();
       
    65         if ($zfPath != false) {
       
    66             $zfIterator = new RecursiveDirectoryIterator($zfPath);
       
    67             foreach ($rii = new RecursiveIteratorIterator($zfIterator, RecursiveIteratorIterator::SELF_FIRST) as $file) {
       
    68                 $relativePath = preg_replace('#^'.preg_quote(realpath($zfPath), '#').'#', '', realpath($file->getPath())) . DIRECTORY_SEPARATOR . $file->getFilename();
       
    69                 if (strpos($relativePath, DIRECTORY_SEPARATOR . '.') !== false) {
       
    70                     continue;
       
    71                 }
       
    72 
       
    73                 if ($file->isDir()) {
       
    74                     mkdir($this->getBaseDirectory() . DIRECTORY_SEPARATOR . $this->getFilesystemName() . $relativePath);
       
    75                 } else {
       
    76                     copy($file->getPathname(), $this->getBaseDirectory() . DIRECTORY_SEPARATOR . $this->getFilesystemName() . $relativePath);
       
    77                 }
       
    78 
       
    79             }
       
    80         }
       
    81     }
       
    82 
       
    83     /**
       
    84      * _getZfPath()
       
    85      *
       
    86      * @return string|false
       
    87      */
       
    88     protected function _getZfPath()
       
    89     {
       
    90         require_once 'Zend/Loader.php';
       
    91         foreach (Zend_Loader::explodeIncludePath() as $includePath) {
       
    92             if (!file_exists($includePath) || $includePath[0] == '.') {
       
    93                 continue;
       
    94             }
       
    95 
       
    96             if (realpath($checkedPath = rtrim($includePath, '\\/') . '/Zend/Loader.php') !== false && file_exists($checkedPath)) {
       
    97                 return dirname($checkedPath);
       
    98             }
       
    99         }
       
   100 
       
   101         return false;
       
   102     }
       
   103 
       
   104 }