13 * to license@zend.com so we can send you a copy immediately. |
13 * to license@zend.com so we can send you a copy immediately. |
14 * |
14 * |
15 * @category Zend |
15 * @category Zend |
16 * @package Zend_Tool |
16 * @package Zend_Tool |
17 * @subpackage Framework |
17 * @subpackage Framework |
18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
18 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
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 $ |
20 * @version $Id: Application.php 24593 2012-01-05 20:35:02Z matthew $ |
21 */ |
21 */ |
22 |
22 |
23 /** |
23 /** |
24 * @category Zend |
24 * @category Zend |
25 * @package Zend_Tool |
25 * @package Zend_Tool |
26 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
26 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
27 * @license http://framework.zend.com/license/new-bsd New BSD License |
27 * @license http://framework.zend.com/license/new-bsd New BSD License |
28 */ |
28 */ |
29 class Zend_Tool_Project_Provider_Application |
29 class Zend_Tool_Project_Provider_Application |
30 extends Zend_Tool_Project_Provider_Abstract |
30 extends Zend_Tool_Project_Provider_Abstract |
31 implements Zend_Tool_Framework_Provider_Pretendable |
31 implements Zend_Tool_Framework_Provider_Pretendable |
32 { |
32 { |
33 |
33 |
34 protected $_specialties = array('ClassNamePrefix'); |
34 protected $_specialties = array('ClassNamePrefix'); |
35 |
35 |
36 /** |
36 /** |
37 * |
37 * |
38 * @param $classNamePrefix Prefix of classes |
38 * @param string $classNamePrefix Prefix of classes |
39 * @param $force |
39 * @param bool $force |
40 */ |
40 */ |
41 public function changeClassNamePrefix($classNamePrefix /* , $force = false */) |
41 public function changeClassNamePrefix($classNamePrefix /* , $force = false */) |
42 { |
42 { |
43 $profile = $this->_loadProfile(self::NO_PROFILE_THROW_EXCEPTION); |
43 $profile = $this->_loadProfile(self::NO_PROFILE_THROW_EXCEPTION); |
44 |
44 |
45 $originalClassNamePrefix = $classNamePrefix; |
45 $originalClassNamePrefix = $classNamePrefix; |
46 |
46 |
47 if (substr($classNamePrefix, -1) != '_') { |
47 if (substr($classNamePrefix, -1) != '_') { |
48 $classNamePrefix .= '_'; |
48 $classNamePrefix .= '_'; |
49 } |
49 } |
50 |
50 |
51 $configFileResource = $profile->search('ApplicationConfigFile'); |
51 $configFileResource = $profile->search('ApplicationConfigFile'); |
52 $zc = $configFileResource->getAsZendConfig('production'); |
52 $zc = $configFileResource->getAsZendConfig('production'); |
53 if ($zc->appnamespace == $classNamePrefix) { |
53 if ($zc->appnamespace == $classNamePrefix) { |
54 throw new Zend_Tool_Project_Exception('The requested name ' . $classNamePrefix . ' is already the prefix.'); |
54 throw new Zend_Tool_Project_Exception('The requested name ' . $classNamePrefix . ' is already the prefix.'); |
55 } |
55 } |
56 |
56 |
57 // remove the old |
57 // remove the old |
58 $configFileResource->removeStringItem('appnamespace', 'production'); |
58 $configFileResource->removeStringItem('appnamespace', 'production'); |
59 $configFileResource->create(); |
59 $configFileResource->create(); |
60 |
60 |
61 // add the new |
61 // add the new |
62 $configFileResource->addStringItem('appnamespace', $classNamePrefix, 'production', true); |
62 $configFileResource->addStringItem('appnamespace', $classNamePrefix, 'production', true); |
63 $configFileResource->create(); |
63 $configFileResource->create(); |
64 |
64 |
65 // update the project profile |
65 // update the project profile |
66 $applicationDirectory = $profile->search('ApplicationDirectory'); |
66 $applicationDirectory = $profile->search('ApplicationDirectory'); |
67 $applicationDirectory->setClassNamePrefix($classNamePrefix); |
67 $applicationDirectory->setClassNamePrefix($classNamePrefix); |
68 |
68 |
69 $response = $this->_registry->getResponse(); |
69 $response = $this->_registry->getResponse(); |
70 |
70 |
71 if ($originalClassNamePrefix !== $classNamePrefix) { |
71 if ($originalClassNamePrefix !== $classNamePrefix) { |
72 $response->appendContent( |
72 $response->appendContent( |
73 'Note: the name provided "' . $originalClassNamePrefix . '" was' |
73 'Note: the name provided "' . $originalClassNamePrefix . '" was' |
74 . ' altered to "' . $classNamePrefix . '" for correctness.', |
74 . ' altered to "' . $classNamePrefix . '" for correctness.', |
75 array('color' => 'yellow') |
75 array('color' => 'yellow') |
76 ); |
76 ); |
77 } |
77 } |
78 |
78 |
79 // note to the user |
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')); |
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); |
81 $response->appendContent('application.ini updated with new appnamespace ' . $classNamePrefix); |
82 |
82 |
83 // store profile |
83 // store profile |
84 $this->_storeProfile(); |
84 $this->_storeProfile(); |
85 } |
85 } |
86 |
86 |
87 } |
87 } |