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

Debug toolbar