sfSingletonUpgrade.class.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /*
  3. * This file is part of the symfony package.
  4. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  5. *
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. /**
  10. * Upgrades all 1.0 singletons.
  11. *
  12. * @package symfony
  13. * @subpackage task
  14. * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  15. * @version SVN: $Id: sfSingletonUpgrade.class.php 7397 2008-02-08 06:48:35Z fabien $
  16. */
  17. class sfSingletonUpgrade extends sfUpgrade
  18. {
  19. public function upgrade()
  20. {
  21. $this->upgradeFactoryCalls();
  22. $this->upgradeFactoryConfiguration();
  23. $this->upgradeSettingConfiguration();
  24. }
  25. public function upgradeFactoryCalls()
  26. {
  27. $phpFinder = $this->getFinder('file')->name('*.php');
  28. foreach ($phpFinder->in($this->getProjectClassDirectories()) as $file)
  29. {
  30. $content = file_get_contents($file);
  31. $content = str_replace(
  32. array('sfI18N::getInstance()', 'sfRouting::getInstance()', 'sfLogger::getInstance()'),
  33. array('sfContext::getInstance()->getI18N()', 'sfContext::getInstance()->getRouting()', 'sfContext::getInstance()->getLogger()'),
  34. $content, $count
  35. );
  36. if ($count)
  37. {
  38. $this->logSection('singleton', sprintf('Migrating %s', $file));
  39. file_put_contents($file, $content);
  40. }
  41. }
  42. }
  43. public function upgradeFactoryConfiguration()
  44. {
  45. $phpFinder = $this->getFinder('file')->name('factories.yml');
  46. foreach ($phpFinder->in($this->getProjectConfigDirectories()) as $file)
  47. {
  48. $content = file_get_contents($file);
  49. if (false !== strpos($content, 'sfNoLogger'))
  50. {
  51. continue;
  52. }
  53. $content =
  54. <<<EOF
  55. prod:
  56. logger:
  57. class: sfNoLogger
  58. param:
  59. level: err
  60. loggers: ~
  61. EOF
  62. .$content;
  63. $this->logSection('factories.yml', sprintf('Migrating %s', $file));
  64. file_put_contents($file, $content);
  65. }
  66. }
  67. public function upgradeSettingConfiguration()
  68. {
  69. $phpFinder = $this->getFinder('file')->name('settings.yml');
  70. foreach ($phpFinder->in($this->getProjectConfigDirectories()) as $file)
  71. {
  72. $content = file_get_contents($file);
  73. if (false !== strpos($content, 'logging_enabled'))
  74. {
  75. continue;
  76. }
  77. $content = preg_replace('/(prod\:\s+\.settings\:)/s', "$1\n logging_enabled: off", $content);
  78. $this->logSection('settings.yml', sprintf('Migrating %s', $file));
  79. file_put_contents($file, $content);
  80. }
  81. }
  82. }