File indexing completed on 2024-06-23 05:55:51

0001 <?php
0002 /**
0003  * Zend Framework
0004  *
0005  * LICENSE
0006  *
0007  * This source file is subject to the new BSD license that is bundled
0008  * with this package in the file LICENSE.txt.
0009  * It is also available through the world-wide-web at this URL:
0010  * http://framework.zend.com/license/new-bsd
0011  * If you did not receive a copy of the license and are unable to
0012  * obtain it through the world-wide-web, please send an email
0013  * to license@zend.com so we can send you a copy immediately.
0014  *
0015  * @category   Zend
0016  * @package    Zend_Tool
0017  * @subpackage Framework
0018  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0019  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0020  * @version    $Id$
0021  */
0022 
0023 /**
0024  * @category   Zend
0025  * @package    Zend_Tool
0026  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0027  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0028  */
0029 class Zend_Tool_Project_Provider_Application
0030     extends Zend_Tool_Project_Provider_Abstract
0031     implements Zend_Tool_Framework_Provider_Pretendable
0032 {
0033 
0034     protected $_specialties = array('ClassNamePrefix');
0035 
0036     /**
0037      *
0038      * @param string $classNamePrefix Prefix of classes
0039      * @param bool   $force
0040      */
0041     public function changeClassNamePrefix($classNamePrefix /* , $force = false */)
0042     {
0043         $profile = $this->_loadProfile(self::NO_PROFILE_THROW_EXCEPTION);
0044 
0045         $originalClassNamePrefix = $classNamePrefix;
0046 
0047         if (substr($classNamePrefix, -1) != '_') {
0048             $classNamePrefix .= '_';
0049         }
0050 
0051         $configFileResource = $profile->search('ApplicationConfigFile');
0052         $zc = $configFileResource->getAsZendConfig('production');
0053         if ($zc->appnamespace == $classNamePrefix) {
0054             throw new Zend_Tool_Project_Exception('The requested name ' . $classNamePrefix . ' is already the prefix.');
0055         }
0056 
0057         // remove the old
0058         $configFileResource->removeStringItem('appnamespace', 'production');
0059         $configFileResource->create();
0060 
0061         // add the new
0062         $configFileResource->addStringItem('appnamespace', $classNamePrefix, 'production', true);
0063         $configFileResource->create();
0064 
0065         // update the project profile
0066         $applicationDirectory = $profile->search('ApplicationDirectory');
0067         $applicationDirectory->setClassNamePrefix($classNamePrefix);
0068 
0069         $response = $this->_registry->getResponse();
0070 
0071         if ($originalClassNamePrefix !== $classNamePrefix) {
0072             $response->appendContent(
0073                 'Note: the name provided "' . $originalClassNamePrefix . '" was'
0074                     . ' altered to "' . $classNamePrefix . '" for correctness.',
0075                 array('color' => 'yellow')
0076                 );
0077         }
0078 
0079         // note to the user
0080         $response->appendContent('Note: All existing models will need to be altered to this new namespace by hand', array('color' => 'yellow'));
0081         $response->appendContent('application.ini updated with new appnamespace ' . $classNamePrefix);
0082 
0083         // store profile
0084         $this->_storeProfile();
0085     }
0086 
0087 }