ApplicationConfigWriter.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. */
  20. /**
  21. * @category Zend
  22. * @package Zend_Tool
  23. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  24. * @license http://framework.zend.com/license/new-bsd New BSD License
  25. */
  26. class Zend_Tool_Project_Utility_ApplicationConfigWriter
  27. {
  28. public function setFilename()
  29. {
  30. }
  31. protected function _writeArrayToConfig($configArray)
  32. {
  33. }
  34. protected function _writeStringToConfig()
  35. {
  36. $configKeyNames = array('resources', 'db');
  37. $newDbLines = array();
  38. $originalLines = file($this->_appConfigFilePath);
  39. $newLines = array();
  40. $insideSection = false;
  41. foreach ($originalLines as $originalLineIndex => $originalLine) {
  42. if ($insideSection === false && preg_match('#^\[' . $this->_sectionName . '#', $originalLine)) {
  43. $insideSection = true;
  44. }
  45. if ($insideSection) {
  46. if ((trim($originalLine) == null) || ($originalLines[$originalLineIndex + 1][0] == '[')) {
  47. foreach ($newDbLines as $newDbLine) {
  48. $newLines[] = $newDbLine;
  49. }
  50. $insideSection = null;
  51. }
  52. }
  53. $newLines[] = $originalLine;
  54. }
  55. $newConfigContents = implode('', $newLines);
  56. if (!$isPretend) {
  57. file_put_contents($this->_appConfigFilePath, $newConfigContents);
  58. }
  59. return $newConfigContents;
  60. }
  61. }