Layout.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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-2009 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: View.php 18386 2009-09-23 20:44:43Z ralph $
  21. */
  22. /**
  23. * @see Zend_Tool_Project_Provider_Abstract
  24. */
  25. require_once 'Zend/Tool/Project/Provider/Abstract.php';
  26. /**
  27. * @category Zend
  28. * @package Zend_Tool
  29. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  30. * @license http://framework.zend.com/license/new-bsd New BSD License
  31. */
  32. class Zend_Tool_Project_Provider_Layout extends Zend_Tool_Project_Provider_Abstract
  33. {
  34. public static function prepareApplicationConfig(Zend_Tool_Project_Profile $profile, $section = 'production', $layoutPath = 'layout/scripts/')
  35. {
  36. $appConfigFileResource = $profile->search('ApplicationConfigFile');
  37. if ($appConfigFileResource == false) {
  38. throw new Zend_Tool_Project_Exception('A project with an application config file is required to use this provider.');
  39. }
  40. $appConfigFilePath = $appConfigFileResource->getPath();
  41. $config = new Zend_Config_Ini($appConfigFilePath, null, array('skipExtends' => true, 'allowModifications' => true));
  42. if (!isset($config->{$section})) {
  43. throw new Zend_Tool_Project_Exception('The config does not have a ' . $section . ' section.');
  44. }
  45. $currentSection = $config->{$section};
  46. if (!isset($currentSection->resources)) {
  47. $currentSection->resources = array();
  48. }
  49. $configResources = $currentSection->resources;
  50. if (!isset($configResources->layout)) {
  51. $configResources->layout = array();
  52. }
  53. $layout = $configResources->layout;
  54. $layout->layoutPath = 'APPLICATION_PATH "layouts/scripts"';
  55. $writer = new Zend_Config_Writer_Ini(array(
  56. 'config' => $config,
  57. 'filename' => $appConfigFilePath
  58. ));
  59. $writer->write();
  60. }
  61. public static function createResource(Zend_Tool_Project_Profile $profile, $layoutName = 'layout')
  62. {
  63. $applicationDirectory = $profile->search('applicationDirectory');
  64. $layoutDirectory = $applicationDirectory->search('layoutsDirectory');
  65. if ($layoutDirectory == false) {
  66. $layoutDirectory = $applicationDirectory->createResource('layoutsDirectory');
  67. }
  68. $layoutScriptsDirectory = $layoutDirectory->search('layoutScriptsDirectory');
  69. if ($layoutScriptsDirectory == false) {
  70. $layoutScriptsDirectory = $layoutDirectory->createResource('layoutScriptsDirectory');
  71. }
  72. $layoutScriptFile = $layoutScriptsDirectory->search('layoutScriptFile', array('layoutName' => 'layout'));
  73. if ($layoutScriptFile == false) {
  74. $layoutScriptFile = $layoutScriptsDirectory->createResource('layoutScriptFile', array('layoutName' => 'layout'));
  75. }
  76. return $layoutScriptFile;
  77. }
  78. public function enable()
  79. {
  80. $profile = $this->_loadProfile(self::NO_PROFILE_THROW_EXCEPTION);
  81. self::prepareApplicationConfig($profile);
  82. $layoutScriptFile = self::createResource($profile);
  83. $layoutScriptFile->create();
  84. $this->_registry->getResponse()->appendContent(
  85. 'Layouts have been enabled, and a default layout created at '
  86. . $layoutScriptFile->getPath()
  87. );
  88. $this->_registry->getResponse()->appendContent('A layout entry has been added to the application config file.');
  89. }
  90. public function disable()
  91. {
  92. }
  93. }