web/lib/Zend/Tool/Project/Provider/Application.php
changeset 64 162c1de6545a
parent 19 1c2f13fd785c
child 68 ecaf28ffe26e
equal deleted inserted replaced
63:5b37998e522e 64:162c1de6545a
       
     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: Application.php 20851 2010-02-02 21:45:51Z ralph $
       
    21  */
       
    22 
       
    23 /**
       
    24  * @category   Zend
       
    25  * @package    Zend_Tool
       
    26  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    27  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    28  */
       
    29 class Zend_Tool_Project_Provider_Application 
       
    30     extends Zend_Tool_Project_Provider_Abstract
       
    31     implements Zend_Tool_Framework_Provider_Pretendable
       
    32 {
       
    33     
       
    34     protected $_specialties = array('ClassNamePrefix');
       
    35     
       
    36     /**
       
    37      * 
       
    38      * @param $classNamePrefix Prefix of classes
       
    39      * @param $force
       
    40      */
       
    41     public function changeClassNamePrefix($classNamePrefix /* , $force = false */)
       
    42     {
       
    43         $profile = $this->_loadProfile(self::NO_PROFILE_THROW_EXCEPTION);
       
    44         
       
    45         $originalClassNamePrefix = $classNamePrefix;
       
    46         
       
    47         if (substr($classNamePrefix, -1) != '_') {
       
    48             $classNamePrefix .= '_';
       
    49         }
       
    50         
       
    51         $configFileResource = $profile->search('ApplicationConfigFile');
       
    52         $zc = $configFileResource->getAsZendConfig('production');
       
    53         if ($zc->appnamespace == $classNamePrefix) {
       
    54             throw new Zend_Tool_Project_Exception('The requested name ' . $classNamePrefix . ' is already the prefix.');
       
    55         }
       
    56 
       
    57         // remove the old
       
    58         $configFileResource->removeStringItem('appnamespace', 'production');
       
    59         $configFileResource->create();
       
    60         
       
    61         // add the new
       
    62         $configFileResource->addStringItem('appnamespace', $classNamePrefix, 'production', true);
       
    63         $configFileResource->create();
       
    64         
       
    65         // update the project profile
       
    66         $applicationDirectory = $profile->search('ApplicationDirectory');
       
    67         $applicationDirectory->setClassNamePrefix($classNamePrefix);
       
    68 
       
    69         $response = $this->_registry->getResponse();
       
    70         
       
    71         if ($originalClassNamePrefix !== $classNamePrefix) {
       
    72             $response->appendContent(
       
    73                 'Note: the name provided "' . $originalClassNamePrefix . '" was'
       
    74                     . ' altered to "' . $classNamePrefix . '" for correctness.',
       
    75                 array('color' => 'yellow')
       
    76                 );
       
    77         } 
       
    78         
       
    79         // note to the user
       
    80         $response->appendContent('Note: All existing models will need to be altered to this new namespace by hand', array('color' => 'yellow'));
       
    81         $response->appendContent('application.ini updated with new appnamespace ' . $classNamePrefix);
       
    82         
       
    83         // store profile
       
    84         $this->_storeProfile();
       
    85     }
       
    86     
       
    87 }