Development

/branches/1.2/lib/task/project/upgrade1.1/sfSingletonUpgrade.class.php

You must first sign up to be able to contribute.

root/branches/1.2/lib/task/project/upgrade1.1/sfSingletonUpgrade.class.php

Revision 7397, 2.4 kB (checked in by fabien, 7 years ago)

added sfTask::log() and sfTask::logSection() shortcuts

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