Application.php 3.0 KB

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