Skip to content

Commit

Permalink
removed the message interpolator system in the Validator component (i…
Browse files Browse the repository at this point in the history
…18n management should be done globally, not in a specific component)
  • Loading branch information
fabpot committed Sep 24, 2010
1 parent 15ca8b4 commit 866c306
Show file tree
Hide file tree
Showing 42 changed files with 69 additions and 2,936 deletions.
Expand Up @@ -344,12 +344,9 @@ protected function registerValidationConfiguration($config, ContainerBuilder $co

$xmlMappingFiles = array();
$yamlMappingFiles = array();
$messageFiles = array();

// default entries by the framework
$xmlMappingFiles[] = __DIR__.'/../../../Component/Form/Resources/config/validation.xml';
$messageFiles[] = __DIR__ . '/../../../Component/Validator/Resources/i18n/messages.en.xml';
$messageFiles[] = __DIR__ . '/../../../Component/Form/Resources/i18n/messages.en.xml';

foreach ($container->getParameter('kernel.bundles') as $className) {
$tmp = dirname(str_replace('\\', '/', $className));
Expand All @@ -363,11 +360,6 @@ protected function registerValidationConfiguration($config, ContainerBuilder $co
if (file_exists($file = $dir.'/'.$bundle.'/Resources/config/validation.yml')) {
$yamlMappingFiles[] = realpath($file);
}

// TODO do we really want the message files of all cultures?
foreach (glob($dir.'/'.$bundle.'/Resources/i18n/messages.*.xml') as $file) {
$messageFiles[] = realpath($file);
}
}
}

Expand All @@ -383,7 +375,6 @@ protected function registerValidationConfiguration($config, ContainerBuilder $co

$container->setDefinition('validator.mapping.loader.xml_files_loader', $xmlFilesLoader);
$container->setDefinition('validator.mapping.loader.yaml_files_loader', $yamlFilesLoader);
$container->setParameter('validator.message_interpolator.files', $messageFiles);

foreach ($xmlMappingFiles as $file) {
$container->addResource(new FileResource($file));
Expand All @@ -393,10 +384,6 @@ protected function registerValidationConfiguration($config, ContainerBuilder $co
$container->addResource(new FileResource($file));
}

foreach ($messageFiles as $file) {
$container->addResource(new FileResource($file));
}

if (isset($config['validation']['annotations']) && $config['validation']['annotations'] === true) {
$annotationLoader = new Definition($container->getParameter('validator.mapping.loader.annotation_loader.class'));
$container->setDefinition('validator.mapping.loader.annotation_loader', $annotationLoader);
Expand Down
Expand Up @@ -7,7 +7,6 @@
<parameters>
<parameter key="validator.class">Symfony\Component\Validator\Validator</parameter>
<parameter key="validator.validator_factory.class">Symfony\Component\Validator\Extension\DependencyInjectionValidatorFactory</parameter>
<parameter key="validator.message_interpolator.class">Symfony\Component\Validator\MessageInterpolator\XliffMessageInterpolator</parameter>
<parameter key="validator.mapping.class_metadata_factory.class">Symfony\Component\Validator\Mapping\ClassMetadataFactory</parameter>
<parameter key="validator.mapping.loader.loader_chain.class">Symfony\Component\Validator\Mapping\Loader\LoaderChain</parameter>
<parameter key="validator.mapping.loader.static_method_loader.class">Symfony\Component\Validator\Mapping\Loader\StaticMethodLoader</parameter>
Expand All @@ -23,7 +22,6 @@
<service id="validator" class="%validator.class%">
<argument type="service" id="validator.mapping.class_metadata_factory" />
<argument type="service" id="validator.validator_factory" />
<argument type="service" id="validator.message_interpolator" />
</service>

<service id="validator.mapping.class_metadata_factory" class="%validator.mapping.class_metadata_factory.class%">
Expand All @@ -34,10 +32,6 @@
<argument type="service" id="service_container" />
</service>

<service id="validator.message_interpolator" class="%validator.message_interpolator.class%">
<argument>%validator.message_interpolator.files%</argument>
</service>

<service id="validator.mapping.loader.loader_chain" class="%validator.mapping.loader.loader_chain.class%">
<argument type="collection">
<argument type="service" id="validator.mapping.loader.static_method_loader" />
Expand Down
10 changes: 5 additions & 5 deletions src/Symfony/Component/Form/Resources/config/validation.xml
Expand Up @@ -10,7 +10,7 @@
</property>
<getter property="boundWithExtraFields">
<constraint name="AssertFalse">
<option name="message">Symfony.Form.FieldGroup.extraFieldsMessage</option>
<option name="message">This field group should not contain extra fields</option>
</constraint>
</getter>
</class>
Expand All @@ -21,21 +21,21 @@
</getter>
<getter property="postMaxSizeReached">
<constraint name="AssertFalse">
<option name="message">Symfony.Form.Form.postMaxSizeMessage</option>
<option name="message">The uploaded file was too large. Please try to upload a smaller file</option>
</constraint>
</getter>
<getter property="csrfTokenValid">
<constraint name="AssertTrue">
<option name="message">Symfony.Form.Form.csrfInvalidMessage</option>
<option name="message">The CSRF token is invalid</option>
</constraint>
</getter>
</class>

<class name="Symfony\Component\Form\RepeatedField">
<getter property="firstEqualToSecond">
<constraint name="AssertTrue">
<option name="message">Symfony.Form.RepeatedField.invalidMessage</option>
<option name="message">The two values should be equal</option>
</constraint>
</getter>
</class>
</constraint-mapping>
</constraint-mapping>
23 changes: 0 additions & 23 deletions src/Symfony/Component/Form/Resources/i18n/messages.en.xml

This file was deleted.

27 changes: 23 additions & 4 deletions src/Symfony/Component/Validator/ConstraintViolation.php
Expand Up @@ -4,22 +4,41 @@

class ConstraintViolation
{
protected $message;
protected $messageTemplate;
protected $messageParameters;
protected $root;
protected $propertyPath;
protected $invalidValue;

public function __construct($message, $root, $propertyPath, $invalidValue)
public function __construct($messageTemplate, array $messageParameters, $root, $propertyPath, $invalidValue)
{
$this->message = $message;
$this->messageTemplate = $messageTemplate;
$this->messageParameters = $messageParameters;
$this->root = $root;
$this->propertyPath = $propertyPath;
$this->invalidValue = $invalidValue;
}

public function getMessageTemplate()
{
return $this->messageTemplate;
}

public function getMessageParameters()
{
return $this->messageParameters;
}

public function getMessage()
{
return $this->message;
$sources = array();
$targets = array();
foreach ($this->messageParameters as $key => $value) {
$sources[] = '%'.$key.'%';
$targets[] = (string) $value;
}

return str_replace($sources, $targets, $this->messageTemplate);
}

public function getRoot()
Expand Down
Expand Up @@ -4,5 +4,5 @@

class AssertFalse extends \Symfony\Component\Validator\Constraint
{
public $message = 'Symfony.Validator.AssertFalse.message';
public $message = 'This value should be false';
}
2 changes: 1 addition & 1 deletion src/Symfony/Component/Validator/Constraints/AssertTrue.php
Expand Up @@ -4,5 +4,5 @@

class AssertTrue extends \Symfony\Component\Validator\Constraint
{
public $message = 'Symfony.Validator.AssertTrue.message';
public $message = 'This value should be true';
}
2 changes: 1 addition & 1 deletion src/Symfony/Component/Validator/Constraints/AssertType.php
Expand Up @@ -4,7 +4,7 @@

class AssertType extends \Symfony\Component\Validator\Constraint
{
public $message = 'Symfony.Validator.AssertType.message';
public $message = 'This value should be of type %type%';
public $type;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Validator/Constraints/Blank.php
Expand Up @@ -4,5 +4,5 @@

class Blank extends \Symfony\Component\Validator\Constraint
{
public $message = 'Symfony.Validator.Blank.message';
public $message = 'This value should be blank';
}
6 changes: 3 additions & 3 deletions src/Symfony/Component/Validator/Constraints/Choice.php
Expand Up @@ -17,9 +17,9 @@ class Choice extends \Symfony\Component\Validator\Constraint
public $multiple = false;
public $min = null;
public $max = null;
public $message = 'Symfony.Validator.Choice.message';
public $minMessage = 'Symfony.Validator.Choice.minMessage';
public $maxMessage = 'Symfony.Validator.Choice.maxMessage';
public $message = 'This value should be one of the given choices';
public $minMessage = 'You should select at least %limit% choices';
public $maxMessage = 'You should select at most %limit% choices';

/**
* {@inheritDoc}
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Validator/Constraints/Collection.php
Expand Up @@ -7,8 +7,8 @@ class Collection extends \Symfony\Component\Validator\Constraint
public $fields;
public $allowExtraFields = false;
public $allowMissingFields = false;
public $extraFieldsMessage = 'Symfony.Validator.Collection.extraFieldsMessage';
public $missingFieldsMessage = 'Symfony.Validator.Collection.missingFieldsMessage';
public $extraFieldsMessage = 'The fields %fields% were not expected';
public $missingFieldsMessage = 'The fields %fields% are missing';

public function requiredOptions()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Validator/Constraints/Date.php
Expand Up @@ -4,5 +4,5 @@

class Date extends \Symfony\Component\Validator\Constraint
{
public $message = 'Symfony.Validator.Date.message';
public $message = 'This value is not a valid date';
}
2 changes: 1 addition & 1 deletion src/Symfony/Component/Validator/Constraints/DateTime.php
Expand Up @@ -4,5 +4,5 @@

class DateTime extends \Symfony\Component\Validator\Constraint
{
public $message = 'Symfony.Validator.DateTime.message';
public $message = 'This value is not a valid datetime';
}
2 changes: 1 addition & 1 deletion src/Symfony/Component/Validator/Constraints/Email.php
Expand Up @@ -4,6 +4,6 @@

class Email extends \Symfony\Component\Validator\Constraint
{
public $message = 'Symfony.Validator.Email.message';
public $message = 'This value is not a valid email address';
public $checkMX = false;
}
8 changes: 4 additions & 4 deletions src/Symfony/Component/Validator/Constraints/File.php
Expand Up @@ -6,8 +6,8 @@ class File extends \Symfony\Component\Validator\Constraint
{
public $maxSize = null;
public $mimeTypes = array();
public $notFoundMessage = 'Symfony.Validator.File.notFoundMessage';
public $notReadableMessage = 'Symfony.Validator.File.notReadableMessage';
public $maxSizeMessage = 'Symfony.Validator.File.maxSizeMessage';
public $mimeTypesMessage = 'Symfony.Validator.File.mimeTypesMessage';
public $notFoundMessage = 'The file could not be found';
public $notReadableMessage = 'The file is not readable';
public $maxSizeMessage = 'The file is too large (%size%). Allowed maximum size is %limit%';
public $mimeTypesMessage = 'The mime type of the file is invalid (%type%). Allowed mime types are %types%';
}
2 changes: 1 addition & 1 deletion src/Symfony/Component/Validator/Constraints/Max.php
Expand Up @@ -4,7 +4,7 @@

class Max extends \Symfony\Component\Validator\Constraint
{
public $message = 'Symfony.Validator.Max.message';
public $message = 'This value should be %limit% or less';
public $limit;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Validator/Constraints/MaxLength.php
Expand Up @@ -4,7 +4,7 @@

class MaxLength extends \Symfony\Component\Validator\Constraint
{
public $message = 'Symfony.Validator.MaxLength.message';
public $message = 'This value is too long. It should have %limit% characters or less';
public $limit;
public $charset = 'UTF-8';

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Validator/Constraints/Min.php
Expand Up @@ -4,7 +4,7 @@

class Min extends \Symfony\Component\Validator\Constraint
{
public $message = 'Symfony.Validator.Min.message';
public $message = 'This value should be %limit% or more';
public $limit;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Validator/Constraints/MinLength.php
Expand Up @@ -4,7 +4,7 @@

class MinLength extends \Symfony\Component\Validator\Constraint
{
public $message = 'Symfony.Validator.MinLength.message';
public $message = 'This value is too short. It should have %limit% characters or more';
public $limit;
public $charset = 'UTF-8';

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Validator/Constraints/NotBlank.php
Expand Up @@ -4,5 +4,5 @@

class NotBlank extends \Symfony\Component\Validator\Constraint
{
public $message = 'Symfony.Validator.NotBlank.message';
public $message = 'This value should not be blank';
}
2 changes: 1 addition & 1 deletion src/Symfony/Component/Validator/Constraints/NotNull.php
Expand Up @@ -4,5 +4,5 @@

class NotNull extends \Symfony\Component\Validator\Constraint
{
public $message = 'Symfony.Validator.NotNull.message';
public $message = 'This value should not be null';
}
2 changes: 1 addition & 1 deletion src/Symfony/Component/Validator/Constraints/Null.php
Expand Up @@ -4,5 +4,5 @@

class Null extends \Symfony\Component\Validator\Constraint
{
public $message = 'Symfony.Validator.Null.message';
public $message = 'This value should be null';
}
2 changes: 1 addition & 1 deletion src/Symfony/Component/Validator/Constraints/Regex.php
Expand Up @@ -4,7 +4,7 @@

class Regex extends \Symfony\Component\Validator\Constraint
{
public $message = 'Symfony.Validator.Regex.message';
public $message = 'This value is not valid';
public $pattern;
public $match = true;

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Validator/Constraints/Time.php
Expand Up @@ -4,5 +4,5 @@

class Time extends \Symfony\Component\Validator\Constraint
{
public $message = 'Symfony.Validator.Time.message';
public $message = 'This value is not a valid time';
}
2 changes: 1 addition & 1 deletion src/Symfony/Component/Validator/Constraints/Url.php
Expand Up @@ -4,6 +4,6 @@

class Url extends \Symfony\Component\Validator\Constraint
{
public $message = 'Symfony.Validator.Url.message';
public $message = 'This value is not a valid URL';
public $protocols = array('http', 'https', 'ftp', 'ftps');
}
2 changes: 1 addition & 1 deletion src/Symfony/Component/Validator/Constraints/Valid.php
Expand Up @@ -4,6 +4,6 @@

class Valid extends \Symfony\Component\Validator\Constraint
{
public $message = 'Symfony.Validator.Valid.message';
public $message = 'This value should be instance of class %class%';
public $class;
}
5 changes: 2 additions & 3 deletions src/Symfony/Component/Validator/GraphWalker.php
Expand Up @@ -10,17 +10,16 @@
use Symfony\Component\Validator\Mapping\ClassMetadataFactoryInterface;
use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\Mapping\MemberMetadata;
use Symfony\Component\Validator\MessageInterpolator\MessageInterpolatorInterface;

class GraphWalker
{
protected $context;
protected $validatorFactory;
protected $metadataFactory;

public function __construct($root, ClassMetadataFactoryInterface $metadataFactory, ConstraintValidatorFactoryInterface $factory, MessageInterpolatorInterface $messageInterpolator)
public function __construct($root, ClassMetadataFactoryInterface $metadataFactory, ConstraintValidatorFactoryInterface $factory)
{
$this->context = new ValidationContext($root, $this, $metadataFactory, $messageInterpolator);
$this->context = new ValidationContext($root, $this, $metadataFactory);
$this->validatorFactory = $factory;
$this->metadataFactory = $metadataFactory;
}
Expand Down

This file was deleted.

0 comments on commit 866c306

Please sign in to comment.