Application.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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: Model.php 18386 2009-09-23 20:44:43Z ralph $
  21. */
  22. /**
  23. * @category Zend
  24. * @package Zend_Tool
  25. * @copyright Copyright (c) 2005-2010 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. public function changeClassNamePrefix($classNamePrefix, $force = false)
  34. {
  35. $profile = $this->_loadProfile(self::NO_PROFILE_THROW_EXCEPTION);
  36. $configFileResource = $profile->search('ApplicationConfigFile');
  37. $zc = $configFileResource->getAsZendConfig('production');
  38. if ($zc->appnamespace == $classNamePrefix) {
  39. throw new Zend_Tool_Project_Exception('The requested name ' . $classNamePrefix . ' is already the prefix.');
  40. }
  41. // remove the old
  42. $configFileResource->removeStringItem('appnamespace', 'production');
  43. $configFileResource->create();
  44. // add the new
  45. $configFileResource->addStringItem('appnamespace', $classNamePrefix, 'production', true);
  46. $configFileResource->create();
  47. // update the project profile
  48. $applicationDirectory = $profile->search('ApplicationDirectory');
  49. $applicationDirectory->setClassNamePrefix($classNamePrefix);
  50. // note to the user
  51. $this->_registry->getResponse()->appendContent('application.ini updated with new appnamespace ' . $classNamePrefix);
  52. $this->_registry->getResponse()->appendContent('Note: All existing models will need to be altered to this new namespace by hand', array('color' => 'yellow'));
  53. // store profile
  54. $this->_storeProfile();
  55. }
  56. }