2
0

Layout.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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: 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-2010 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 implements Zend_Tool_Framework_Provider_Pretendable
  33. {
  34. public static function createResource(Zend_Tool_Project_Profile $profile, $layoutName = 'layout')
  35. {
  36. $applicationDirectory = $profile->search('applicationDirectory');
  37. $layoutDirectory = $applicationDirectory->search('layoutsDirectory');
  38. if ($layoutDirectory == false) {
  39. $layoutDirectory = $applicationDirectory->createResource('layoutsDirectory');
  40. }
  41. $layoutScriptsDirectory = $layoutDirectory->search('layoutScriptsDirectory');
  42. if ($layoutScriptsDirectory == false) {
  43. $layoutScriptsDirectory = $layoutDirectory->createResource('layoutScriptsDirectory');
  44. }
  45. $layoutScriptFile = $layoutScriptsDirectory->search('layoutScriptFile', array('layoutName' => 'layout'));
  46. if ($layoutScriptFile == false) {
  47. $layoutScriptFile = $layoutScriptsDirectory->createResource('layoutScriptFile', array('layoutName' => 'layout'));
  48. }
  49. return $layoutScriptFile;
  50. }
  51. public function enable()
  52. {
  53. $profile = $this->_loadProfile(self::NO_PROFILE_THROW_EXCEPTION);
  54. $applicationConfigResource = $profile->search('ApplicationConfigFile');
  55. if (!$applicationConfigResource) {
  56. throw new Zend_Tool_Project_Exception('A project with an application config file is required to use this provider.');
  57. }
  58. $zc = $applicationConfigResource->getAsZendConfig();
  59. if (isset($zc->resources) && isset($zf->resources->layout)) {
  60. $this->_registry->getResponse()->appendContent('A layout resource already exists in this project\'s application configuration file.');
  61. return;
  62. }
  63. $layoutPath = 'APPLICATION_PATH "/layouts/scripts/"';
  64. if ($this->_registry->getRequest()->isPretend()) {
  65. $this->_registry->getResponse()->appendContent('Would add "resources.layout.layoutPath" key to the application config file.');
  66. } else {
  67. $applicationConfigResource->addStringItem('resources.layout.layoutPath', $layoutPath, 'production', false);
  68. $applicationConfigResource->create();
  69. $layoutScriptFile = self::createResource($profile);
  70. $layoutScriptFile->create();
  71. $this->_registry->getResponse()->appendContent(
  72. 'Layouts have been enabled, and a default layout created at '
  73. . $layoutScriptFile->getPath()
  74. );
  75. $this->_registry->getResponse()->appendContent('A layout entry has been added to the application config file.');
  76. }
  77. }
  78. public function disable()
  79. {
  80. // @todo
  81. }
  82. }