| 1 |
lars |
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 |
* Finds usage of array notation with a parameter holder.
|
|
|
13 |
*
|
|
|
14 |
* @package symfony
|
|
|
15 |
* @subpackage task
|
|
|
16 |
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
|
|
17 |
* @version SVN: $Id: sfParameterHolderValidation.class.php 25411 2009-12-15 15:31:29Z fabien $
|
|
|
18 |
*/
|
|
|
19 |
class sfParameterHolderValidation extends sfValidation
|
|
|
20 |
{
|
|
|
21 |
public function getHeader()
|
|
|
22 |
{
|
|
|
23 |
return 'Checking usage of array notation with a parameter holder';
|
|
|
24 |
}
|
|
|
25 |
|
|
|
26 |
public function getExplanation()
|
|
|
27 |
{
|
|
|
28 |
return array(
|
|
|
29 |
'',
|
|
|
30 |
' The files above use the array notation with a parameter holder,',
|
|
|
31 |
' which is not supported anymore in symfony 1.4.',
|
|
|
32 |
' For instance, you need to change this construct:',
|
|
|
33 |
'',
|
|
|
34 |
' $foo = $request->getParameter(\'foo[bar]\')',
|
|
|
35 |
'',
|
|
|
36 |
' to this one:',
|
|
|
37 |
'',
|
|
|
38 |
' $params = $request->getParameter(\'foo\')',
|
|
|
39 |
' $foo = $params[\'bar\'])',
|
|
|
40 |
'',
|
|
|
41 |
);
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
public function validate()
|
|
|
45 |
{
|
|
|
46 |
$found = array();
|
|
|
47 |
$files = sfFinder::type('file')->name('*.php')->prune('vendor')->in(array(
|
|
|
48 |
sfConfig::get('sf_apps_dir'),
|
|
|
49 |
sfConfig::get('sf_lib_dir'),
|
|
|
50 |
sfConfig::get('sf_test_dir'),
|
|
|
51 |
sfConfig::get('sf_plugins_dir'),
|
|
|
52 |
));
|
|
|
53 |
foreach ($files as $file)
|
|
|
54 |
{
|
|
|
55 |
$content = sfToolkit::stripComments(file_get_contents($file));
|
|
|
56 |
|
|
|
57 |
if (preg_match('#\b(get|has|remove)(Request)*Parameter\(\s*[\'"][^\),]*?\[[^\),]#', $content))
|
|
|
58 |
{
|
|
|
59 |
$found[$file] = true;
|
|
|
60 |
}
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
return $found;
|
|
|
64 |
}
|
|
|
65 |
}
|