1. sfI18nYamlValidateExtractor.class.php
  2. /** * @package symfony * @subpackage i18n * @author Fabien Potencier * @version SVN: $Id: sfI18nYamlValidateExtractor.class.php 9128 2008-05-21 00:58:19Z Carl.Vondrick $ */
  3. class sfI18nYamlValidateExtractor extends sfI18nYamlExtractor
  4. {
  5. /**
  6. * Extract i18n strings for the given content.
  7. *
  8. * @param string $content The content
  9. *
  10. * @return array An array of i18n strings
  11. */
  12. public function extract($content)
  13. {
  14. $strings = array();
  15. $config = sfYaml::load($content);
  16. // New validate.yml format
  17. // fields
  18. if (isset($config['fields']))
  19. {
  20. foreach ($config['fields'] as $field => $validation)
  21. {
  22. foreach ($validation as $type => $parameters)
  23. {
  24. if (!is_array($parameters))
  25. {
  26. continue;
  27. }
  28. foreach ($parameters as $key => $value)
  29. {
  30. if (preg_match('/(msg|error)$/', $key))
  31. {
  32. $strings[] = $value;
  33. }
  34. }
  35. }
  36. }
  37. }
  38. // validators
  39. if (isset($config['validators']))
  40. {
  41. foreach (array_keys($config['validators']) as $name)
  42. {
  43. if (!isset($config['validators'][$name]['param']))
  44. {
  45. continue;
  46. }
  47. foreach ($config['validators'][$name]['param'] as $key => $value)
  48. {
  49. if (preg_match('/(msg|error)$/', $key))
  50. {
  51. $strings[] = $value;
  52. }
  53. }
  54. }
  55. }
  56. // Old validate.yml format
  57. // required messages
  58. if (isset($config['names']))
  59. {
  60. foreach ($config['names'] as $key => $value)
  61. {
  62. if (isset($value['required_msg']))
  63. {
  64. $strings[] = $value['required_msg'];
  65. }
  66. }
  67. }
  68. // validators
  69. foreach ($config as $key => $value)
  70. {
  71. if (isset($value['param']) && isset($value['class']))
  72. {
  73. foreach ($value['param'] as $key => $value)
  74. {
  75. if (preg_match('/(msg|error)$/', $key))
  76. {
  77. $strings[] = $value;
  78. }
  79. }
  80. }
  81. }
  82. return $strings;
  83. }
  84. }

Debug toolbar