Development

/branches/1.3/lib/task/project/upgrade1.3/sfFormsUpgrade.class.php

You must first sign up to be able to contribute.

root/branches/1.3/lib/task/project/upgrade1.3/sfFormsUpgrade.class.php

Revision 23810, 2.1 kB (checked in by Kris.Wallsmith, 5 years ago)

[1.3] set svn:eol-style property to native and svn:keywords property to Id on all .php files

  • 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  * Migrates form classes.
13  *
14  * @package    symfony
15  * @subpackage task
16  * @author     Pascal Borreli <pborreli@sqli.com>
17  * @version    SVN: $Id$
18  */
19 class sfFormsUpgrade extends sfUpgrade
20 {
21   public function upgrade()
22   {
23     if (!file_exists($file = sfConfig::get('sf_lib_dir').'/form/BaseForm.class.php'))
24     {
25       $properties = parse_ini_file(sfConfig::get('sf_config_dir').'/properties.ini', true);
26       $tokens = array(
27         'PROJECT_NAME' => isset($properties['symfony']['name']) ? $properties['symfony']['name'] : 'symfony',
28         'AUTHOR_NAME'  => isset($properties['symfony']['author']) ? $properties['symfony']['author'] : 'Your name here'
29       );
30
31       $this->getFilesystem()->copy(sfConfig::get('sf_symfony_lib_dir').'/task/generator/skeleton/project/lib/form/BaseForm.class.php', $file);
32       $this->getFilesystem()->replaceTokens(array($file), '##', '##', $tokens);
33     }
34
35     $finder = sfFinder::type('file')->name('*.php');
36     foreach ($finder->in($this->getProjectLibDirectories('/form')) as $file)
37     {
38       $contents = file_get_contents($file);
39       $changed = false;
40
41       // forms that extend sfForm should now extend BaseForm
42       $contents = preg_replace('/(\bextends\s+)sfForm\b/i', '\\1BaseForm', $contents, -1, $count);
43       $changed = $count || $changed;
44
45       // change instances of sfWidgetFormInput to sfWidgetFormInputText
46       $contents = preg_replace('/\bnew\s+sfWidgetFormInput\b/i', '\\0Text', $contents, -1, $count);
47       $changed = $count || $changed;
48
49       // change signature of sfFormDoctrine::processValues()
50       $contents = preg_replace('/public\s+function\s+processValues\s*\(\s*\$\w+(\s*=\s*null\s*)\)/ie', "str_replace('$1', '', '$0')", $contents, -1, $count);
51       $changed = $count || $changed;
52
53       if ($changed)
54       {
55         $this->logSection('form', 'Migrating '.$file);
56         file_put_contents($file, $contents);
57       }
58     }
59   }
60 }
61
Note: See TracBrowser for help on using the browser.