removed the message interpolator system in the Validator component (i18n management should be done globally, not in a specific component)

This commit is contained in:
Fabien Potencier 2010-09-24 16:34:58 +02:00
parent 15ca8b4076
commit 866c306dc8
42 changed files with 69 additions and 2936 deletions

View File

@ -344,12 +344,9 @@ class FrameworkExtension extends Extension
$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));
@ -363,11 +360,6 @@ class FrameworkExtension extends Extension
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);
}
}
}
@ -383,7 +375,6 @@ class FrameworkExtension extends Extension
$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));
@ -393,10 +384,6 @@ class FrameworkExtension extends Extension
$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);

View File

@ -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>
@ -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%">
@ -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" />

View File

@ -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>
@ -21,12 +21,12 @@
</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>
@ -34,8 +34,8 @@
<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>

View File

@ -1,23 +0,0 @@
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" datatype="plaintext" original="file.ext">
<body>
<trans-unit id="1">
<source>Symfony.Form.FieldGroup.extraFieldsMessage</source>
<target>This field group should not contain extra fields</target>
</trans-unit>
<trans-unit id="2">
<source>Symfony.Form.Form.postMaxSizeMessage</source>
<target>The uploaded file was too large. Please try to upload a smaller file.</target>
</trans-unit>
<trans-unit id="3">
<source>Symfony.Form.Form.csrfInvalidMessage</source>
<target>The CSRF token is invalid</target>
</trans-unit>
<trans-unit id="4">
<source>Symfony.Form.RepeatedField.invalidMessage</source>
<target>The two values should be equal</target>
</trans-unit>
</body>
</file>
</xliff>

View File

@ -4,22 +4,41 @@ namespace Symfony\Component\Validator;
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()

View File

@ -4,5 +4,5 @@ namespace Symfony\Component\Validator\Constraints;
class AssertFalse extends \Symfony\Component\Validator\Constraint
{
public $message = 'Symfony.Validator.AssertFalse.message';
public $message = 'This value should be false';
}

View File

@ -4,5 +4,5 @@ namespace Symfony\Component\Validator\Constraints;
class AssertTrue extends \Symfony\Component\Validator\Constraint
{
public $message = 'Symfony.Validator.AssertTrue.message';
public $message = 'This value should be true';
}

View File

@ -4,7 +4,7 @@ namespace Symfony\Component\Validator\Constraints;
class AssertType extends \Symfony\Component\Validator\Constraint
{
public $message = 'Symfony.Validator.AssertType.message';
public $message = 'This value should be of type %type%';
public $type;
/**

View File

@ -4,5 +4,5 @@ namespace Symfony\Component\Validator\Constraints;
class Blank extends \Symfony\Component\Validator\Constraint
{
public $message = 'Symfony.Validator.Blank.message';
public $message = 'This value should be blank';
}

View File

@ -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}

View File

@ -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()
{

View File

@ -4,5 +4,5 @@ namespace Symfony\Component\Validator\Constraints;
class Date extends \Symfony\Component\Validator\Constraint
{
public $message = 'Symfony.Validator.Date.message';
public $message = 'This value is not a valid date';
}

View File

@ -4,5 +4,5 @@ namespace Symfony\Component\Validator\Constraints;
class DateTime extends \Symfony\Component\Validator\Constraint
{
public $message = 'Symfony.Validator.DateTime.message';
public $message = 'This value is not a valid datetime';
}

View File

@ -4,6 +4,6 @@ namespace Symfony\Component\Validator\Constraints;
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;
}

View File

@ -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%';
}

View File

@ -4,7 +4,7 @@ namespace Symfony\Component\Validator\Constraints;
class Max extends \Symfony\Component\Validator\Constraint
{
public $message = 'Symfony.Validator.Max.message';
public $message = 'This value should be %limit% or less';
public $limit;
/**

View File

@ -4,7 +4,7 @@ namespace Symfony\Component\Validator\Constraints;
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';

View File

@ -4,7 +4,7 @@ namespace Symfony\Component\Validator\Constraints;
class Min extends \Symfony\Component\Validator\Constraint
{
public $message = 'Symfony.Validator.Min.message';
public $message = 'This value should be %limit% or more';
public $limit;
/**

View File

@ -4,7 +4,7 @@ namespace Symfony\Component\Validator\Constraints;
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';

View File

@ -4,5 +4,5 @@ namespace Symfony\Component\Validator\Constraints;
class NotBlank extends \Symfony\Component\Validator\Constraint
{
public $message = 'Symfony.Validator.NotBlank.message';
public $message = 'This value should not be blank';
}

View File

@ -4,5 +4,5 @@ namespace Symfony\Component\Validator\Constraints;
class NotNull extends \Symfony\Component\Validator\Constraint
{
public $message = 'Symfony.Validator.NotNull.message';
public $message = 'This value should not be null';
}

View File

@ -4,5 +4,5 @@ namespace Symfony\Component\Validator\Constraints;
class Null extends \Symfony\Component\Validator\Constraint
{
public $message = 'Symfony.Validator.Null.message';
public $message = 'This value should be null';
}

View File

@ -4,7 +4,7 @@ namespace Symfony\Component\Validator\Constraints;
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;

View File

@ -4,5 +4,5 @@ namespace Symfony\Component\Validator\Constraints;
class Time extends \Symfony\Component\Validator\Constraint
{
public $message = 'Symfony.Validator.Time.message';
public $message = 'This value is not a valid time';
}

View File

@ -4,6 +4,6 @@ namespace Symfony\Component\Validator\Constraints;
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');
}

View File

@ -4,6 +4,6 @@ namespace Symfony\Component\Validator\Constraints;
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;
}

View File

@ -10,7 +10,6 @@ use Symfony\Component\Validator\Exception\UnexpectedTypeException;
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
{
@ -18,9 +17,9 @@ class GraphWalker
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;
}

View File

@ -1,15 +0,0 @@
<?php
namespace Symfony\Component\Validator\MessageInterpolator;
interface MessageInterpolatorInterface
{
/**
* Interpolates a text and inserts the given parameters
*
* @param string $text The text to interpolate
* @param array $parameters The parameters to insert into the text
* @return string The interpolated text
*/
function interpolate($text, array $parameters = array());
}

View File

@ -1,103 +0,0 @@
<?php
namespace Symfony\Component\Validator\MessageInterpolator;
class XliffMessageInterpolator implements MessageInterpolatorInterface
{
protected $translations = array();
/**
* Constructs an interpolator from the given XLIFF file
*
* @param string|array $file One or more paths to existing XLIFF files
*/
public function __construct($file)
{
$files = (array)$file;
foreach ($files as $file) {
$xml = $this->parseFile($file);
$xml->registerXPathNamespace('xliff', 'urn:oasis:names:tc:xliff:document:1.2');
foreach ($xml->xpath('//xliff:trans-unit') as $translation) {
$this->translations[(string)$translation->source] = (string)$translation->target;
}
}
}
/**
* {@inheritDoc}
*/
public function interpolate($text, array $parameters = array())
{
if (isset($this->translations[$text])) {
$text = $this->translations[$text];
}
$sources = array();
$targets = array();
foreach ($parameters as $key => $value) {
$sources[] = '%'.$key.'%';
$targets[] = (string)$value;
}
return str_replace($sources, $targets, $text);
}
/**
* Validates and parses the given file into a SimpleXMLElement
*
* @param string $file
* @return SimpleXMLElement
*/
protected function parseFile($file)
{
$dom = new \DOMDocument();
$current = libxml_use_internal_errors(true);
if (!@$dom->load($file, LIBXML_COMPACT)) {
throw new \Exception(implode("\n", $this->getXmlErrors()));
}
$parts = explode('/', str_replace('\\', '/', __DIR__).'/schema/dic/xliff-core/xml.xsd');
$drive = '\\' === DIRECTORY_SEPARATOR ? array_shift($parts).'/' : '';
$location = 'file:///'.$drive.implode('/', array_map('rawurlencode', $parts));
$source = file_get_contents(__DIR__.'/schema/dic/xliff-core/xliff-core-1.2-strict.xsd');
$source = str_replace('http://www.w3.org/2001/xml.xsd', $location, $source);
if (!@$dom->schemaValidateSource($source)) {
throw new \Exception(implode("\n", $this->getXmlErrors()));
}
$dom->validateOnParse = true;
$dom->normalizeDocument();
libxml_use_internal_errors($current);
return simplexml_import_dom($dom);
}
/**
* Returns the XML errors of the internal XML parser
*
* @return array An array of errors
*/
protected function getXmlErrors()
{
$errors = array();
foreach (libxml_get_errors() as $error) {
$errors[] = sprintf('[%s %s] %s (in %s - line %d, column %d)',
LIBXML_ERR_WARNING == $error->level ? 'WARNING' : 'ERROR',
$error->code,
trim($error->message),
$error->file ? $error->file : 'n/a',
$error->line,
$error->column
);
}
libxml_clear_errors();
libxml_use_internal_errors(false);
return $errors;
}
}

View File

@ -1,309 +0,0 @@
<?xml version='1.0'?>
<?xml-stylesheet href="../2008/09/xsd.xsl" type="text/xsl"?>
<xs:schema targetNamespace="http://www.w3.org/XML/1998/namespace"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns ="http://www.w3.org/1999/xhtml"
xml:lang="en">
<xs:annotation>
<xs:documentation>
<div>
<h1>About the XML namespace</h1>
<div class="bodytext">
<p>
This schema document describes the XML namespace, in a form
suitable for import by other schema documents.
</p>
<p>
See <a href="http://www.w3.org/XML/1998/namespace.html">
http://www.w3.org/XML/1998/namespace.html</a> and
<a href="http://www.w3.org/TR/REC-xml">
http://www.w3.org/TR/REC-xml</a> for information
about this namespace.
</p>
<p>
Note that local names in this namespace are intended to be
defined only by the World Wide Web Consortium or its subgroups.
The names currently defined in this namespace are listed below.
They should not be used with conflicting semantics by any Working
Group, specification, or document instance.
</p>
<p>
See further below in this document for more information about <a
href="#usage">how to refer to this schema document from your own
XSD schema documents</a> and about <a href="#nsversioning">the
namespace-versioning policy governing this schema document</a>.
</p>
</div>
</div>
</xs:documentation>
</xs:annotation>
<xs:attribute name="lang">
<xs:annotation>
<xs:documentation>
<div>
<h3>lang (as an attribute name)</h3>
<p>
denotes an attribute whose value
is a language code for the natural language of the content of
any element; its value is inherited. This name is reserved
by virtue of its definition in the XML specification.</p>
</div>
<div>
<h4>Notes</h4>
<p>
Attempting to install the relevant ISO 2- and 3-letter
codes as the enumerated possible values is probably never
going to be a realistic possibility.
</p>
<p>
See BCP 47 at <a href="http://www.rfc-editor.org/rfc/bcp/bcp47.txt">
http://www.rfc-editor.org/rfc/bcp/bcp47.txt</a>
and the IANA language subtag registry at
<a href="http://www.iana.org/assignments/language-subtag-registry">
http://www.iana.org/assignments/language-subtag-registry</a>
for further information.
</p>
<p>
The union allows for the 'un-declaration' of xml:lang with
the empty string.
</p>
</div>
</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:union memberTypes="xs:language">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value=""/>
</xs:restriction>
</xs:simpleType>
</xs:union>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="space">
<xs:annotation>
<xs:documentation>
<div>
<h3>space (as an attribute name)</h3>
<p>
denotes an attribute whose
value is a keyword indicating what whitespace processing
discipline is intended for the content of the element; its
value is inherited. This name is reserved by virtue of its
definition in the XML specification.</p>
</div>
</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:NCName">
<xs:enumeration value="default"/>
<xs:enumeration value="preserve"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="base" type="xs:anyURI"> <xs:annotation>
<xs:documentation>
<div>
<h3>base (as an attribute name)</h3>
<p>
denotes an attribute whose value
provides a URI to be used as the base for interpreting any
relative URIs in the scope of the element on which it
appears; its value is inherited. This name is reserved
by virtue of its definition in the XML Base specification.</p>
<p>
See <a
href="http://www.w3.org/TR/xmlbase/">http://www.w3.org/TR/xmlbase/</a>
for information about this attribute.
</p>
</div>
</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="id" type="xs:ID">
<xs:annotation>
<xs:documentation>
<div>
<h3>id (as an attribute name)</h3>
<p>
denotes an attribute whose value
should be interpreted as if declared to be of type ID.
This name is reserved by virtue of its definition in the
xml:id specification.</p>
<p>
See <a
href="http://www.w3.org/TR/xml-id/">http://www.w3.org/TR/xml-id/</a>
for information about this attribute.
</p>
</div>
</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attributeGroup name="specialAttrs">
<xs:attribute ref="xml:base"/>
<xs:attribute ref="xml:lang"/>
<xs:attribute ref="xml:space"/>
<xs:attribute ref="xml:id"/>
</xs:attributeGroup>
<xs:annotation>
<xs:documentation>
<div>
<h3>Father (in any context at all)</h3>
<div class="bodytext">
<p>
denotes Jon Bosak, the chair of
the original XML Working Group. This name is reserved by
the following decision of the W3C XML Plenary and
XML Coordination groups:
</p>
<blockquote>
<p>
In appreciation for his vision, leadership and
dedication the W3C XML Plenary on this 10th day of
February, 2000, reserves for Jon Bosak in perpetuity
the XML name "xml:Father".
</p>
</blockquote>
</div>
</div>
</xs:documentation>
</xs:annotation>
<xs:annotation>
<xs:documentation>
<div xml:id="usage" id="usage">
<h2><a name="usage">About this schema document</a></h2>
<div class="bodytext">
<p>
This schema defines attributes and an attribute group suitable
for use by schemas wishing to allow <code>xml:base</code>,
<code>xml:lang</code>, <code>xml:space</code> or
<code>xml:id</code> attributes on elements they define.
</p>
<p>
To enable this, such a schema must import this schema for
the XML namespace, e.g. as follows:
</p>
<pre>
&lt;schema . . .>
. . .
&lt;import namespace="http://www.w3.org/XML/1998/namespace"
schemaLocation="http://www.w3.org/2001/xml.xsd"/>
</pre>
<p>
or
</p>
<pre>
&lt;import namespace="http://www.w3.org/XML/1998/namespace"
schemaLocation="http://www.w3.org/2009/01/xml.xsd"/>
</pre>
<p>
Subsequently, qualified reference to any of the attributes or the
group defined below will have the desired effect, e.g.
</p>
<pre>
&lt;type . . .>
. . .
&lt;attributeGroup ref="xml:specialAttrs"/>
</pre>
<p>
will define a type which will schema-validate an instance element
with any of those attributes.
</p>
</div>
</div>
</xs:documentation>
</xs:annotation>
<xs:annotation>
<xs:documentation>
<div id="nsversioning" xml:id="nsversioning">
<h2><a name="nsversioning">Versioning policy for this schema document</a></h2>
<div class="bodytext">
<p>
In keeping with the XML Schema WG's standard versioning
policy, this schema document will persist at
<a href="http://www.w3.org/2009/01/xml.xsd">
http://www.w3.org/2009/01/xml.xsd</a>.
</p>
<p>
At the date of issue it can also be found at
<a href="http://www.w3.org/2001/xml.xsd">
http://www.w3.org/2001/xml.xsd</a>.
</p>
<p>
The schema document at that URI may however change in the future,
in order to remain compatible with the latest version of XML
Schema itself, or with the XML namespace itself. In other words,
if the XML Schema or XML namespaces change, the version of this
document at <a href="http://www.w3.org/2001/xml.xsd">
http://www.w3.org/2001/xml.xsd
</a>
will change accordingly; the version at
<a href="http://www.w3.org/2009/01/xml.xsd">
http://www.w3.org/2009/01/xml.xsd
</a>
will not change.
</p>
<p>
Previous dated (and unchanging) versions of this schema
document are at:
</p>
<ul>
<li><a href="http://www.w3.org/2009/01/xml.xsd">
http://www.w3.org/2009/01/xml.xsd</a></li>
<li><a href="http://www.w3.org/2007/08/xml.xsd">
http://www.w3.org/2007/08/xml.xsd</a></li>
<li><a href="http://www.w3.org/2004/10/xml.xsd">
http://www.w3.org/2004/10/xml.xsd</a></li>
<li><a href="http://www.w3.org/2001/03/xml.xsd">
http://www.w3.org/2001/03/xml.xsd</a></li>
</ul>
</div>
</div>
</xs:documentation>
</xs:annotation>
</xs:schema>

View File

@ -1,115 +0,0 @@
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" datatype="plaintext" original="file.ext">
<body>
<trans-unit id="1">
<source>Symfony.Validator.AssertFalse.message</source>
<target>This value should be false</target>
</trans-unit>
<trans-unit id="2">
<source>Symfony.Validator.AssertTrue.message</source>
<target>This value should be true</target>
</trans-unit>
<trans-unit id="3">
<source>Symfony.Validator.AssertType.message</source>
<target>This value should be of type %type%</target>
</trans-unit>
<trans-unit id="4">
<source>Symfony.Validator.Blank.message</source>
<target>This value should be blank</target>
</trans-unit>
<trans-unit id="5">
<source>Symfony.Validator.Choice.message</source>
<target>This value should be one of the given choices</target>
</trans-unit>
<trans-unit id="6">
<source>Symfony.Validator.Choice.minMessage</source>
<target>You should select at least %limit% choices</target>
</trans-unit>
<trans-unit id="7">
<source>Symfony.Validator.Choice.maxMessage</source>
<target>You should select at most %limit% choices</target>
</trans-unit>
<trans-unit id="8">
<source>Symfony.Validator.Collection.extraFieldsMessage</source>
<target>The fields %fields% were not expected</target>
</trans-unit>
<trans-unit id="9">
<source>Symfony.Validator.Collection.missingFieldsMessage</source>
<target>The fields %fields% are missing</target>
</trans-unit>
<trans-unit id="10">
<source>Symfony.Validator.Date.message</source>
<target>This value is not a valid date</target>
</trans-unit>
<trans-unit id="11">
<source>Symfony.Validator.DateTime.message</source>
<target>This value is not a valid datetime</target>
</trans-unit>
<trans-unit id="12">
<source>Symfony.Validator.Email.message</source>
<target>This value is not a valid email address</target>
</trans-unit>
<trans-unit id="13">
<source>Symfony.Validator.File.notFoundMessage</source>
<target>The file could not be found</target>
</trans-unit>
<trans-unit id="14">
<source>Symfony.Validator.File.notReadableMessage</source>
<target>The file is not readable</target>
</trans-unit>
<trans-unit id="15">
<source>Symfony.Validator.File.maxSizeMessage</source>
<target>The file is too large (%size%). Allowed maximum size is %limit%</target>
</trans-unit>
<trans-unit id="16">
<source>Symfony.Validator.File.mimeTypesMessage</source>
<target>The mime type of the file is invalid (%type%). Allowed mime types are %types%</target>
</trans-unit>
<trans-unit id="17">
<source>Symfony.Validator.Max.message</source>
<target>This value should be %limit% or less</target>
</trans-unit>
<trans-unit id="18">
<source>Symfony.Validator.MaxLength.message</source>
<target>This value is too long. It should have %limit% characters or less</target>
</trans-unit>
<trans-unit id="19">
<source>Symfony.Validator.Min.message</source>
<target>This value should be %limit% or more</target>
</trans-unit>
<trans-unit id="20">
<source>Symfony.Validator.MinLength.message</source>
<target>This value is too short. It should have %limit% characters or more</target>
</trans-unit>
<trans-unit id="21">
<source>Symfony.Validator.NotBlank.message</source>
<target>This value should not be blank</target>
</trans-unit>
<trans-unit id="22">
<source>Symfony.Validator.NotNull.message</source>
<target>This value should not be null</target>
</trans-unit>
<trans-unit id="23">
<source>Symfony.Validator.Null.message</source>
<target>This value should be null</target>
</trans-unit>
<trans-unit id="24">
<source>Symfony.Validator.Regex.message</source>
<target>This value is not valid</target>
</trans-unit>
<trans-unit id="25">
<source>Symfony.Validator.Time.message</source>
<target>This value is not a valid time</target>
</trans-unit>
<trans-unit id="26">
<source>Symfony.Validator.Url.message</source>
<target>This value is not a valid URL</target>
</trans-unit>
<trans-unit id="27">
<source>Symfony.Validator.Valid.message</source>
<target>This value should be instance of class %class%</target>
</trans-unit>
</body>
</file>
</xliff>

View File

@ -2,7 +2,6 @@
namespace Symfony\Component\Validator;
use Symfony\Component\Validator\MessageInterpolator\MessageInterpolatorInterface;
use Symfony\Component\Validator\Mapping\ClassMetadataFactoryInterface;
class ValidationContext
@ -15,18 +14,15 @@ class ValidationContext
protected $violations;
protected $graphWalker;
protected $metadataFactory;
protected $messageInterpolator;
public function __construct(
$root,
GraphWalker $graphWalker,
ClassMetadataFactoryInterface $metadataFactory,
MessageInterpolatorInterface $messageInterpolator
ClassMetadataFactoryInterface $metadataFactory
)
{
$this->root = $root;
$this->graphWalker = $graphWalker;
$this->messageInterpolator = $messageInterpolator;
$this->metadataFactory = $metadataFactory;
$this->violations = new ConstraintViolationList();
}
@ -39,7 +35,8 @@ class ValidationContext
public function addViolation($message, array $params, $invalidValue)
{
$this->violations->add(new ConstraintViolation(
$this->messageInterpolator->interpolate($message, $params),
$message,
$params,
$this->root,
$this->propertyPath,
$invalidValue

View File

@ -5,23 +5,19 @@ namespace Symfony\Component\Validator;
use Symfony\Component\Validator\Mapping\ElementMetadata;
use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\Mapping\ClassMetadataFactoryInterface;
use Symfony\Component\Validator\MessageInterpolator\MessageInterpolatorInterface;
class Validator implements ValidatorInterface
{
protected $metadataFactory;
protected $validatorFactory;
protected $messageInterpolator;
public function __construct(
ClassMetadataFactoryInterface $metadataFactory,
ConstraintValidatorFactoryInterface $validatorFactory,
MessageInterpolatorInterface $messageInterpolator
ConstraintValidatorFactoryInterface $validatorFactory
)
{
$this->metadataFactory = $metadataFactory;
$this->validatorFactory = $validatorFactory;
$this->messageInterpolator = $messageInterpolator;
}
public function validate($object, $groups = null)
@ -73,7 +69,7 @@ class Validator implements ValidatorInterface
protected function validateGraph($root, \Closure $closure, GroupChain $groupChain)
{
$walker = new GraphWalker($root, $this->metadataFactory, $this->validatorFactory, $this->messageInterpolator);
$walker = new GraphWalker($root, $this->metadataFactory, $this->validatorFactory);
foreach ($groupChain->getGroups() as $group) {
$closure($walker, $group);

View File

@ -17,9 +17,8 @@ class AllValidatorTest extends \PHPUnit_Framework_TestCase
{
$this->walker = $this->getMock('Symfony\Component\Validator\GraphWalker', array(), array(), '', false);
$metadataFactory = $this->getMock('Symfony\Component\Validator\Mapping\ClassMetadataFactoryInterface');
$messageInterpolator = $this->getMock('Symfony\Component\Validator\MessageInterpolator\MessageInterpolatorInterface');
$this->context = new ValidationContext('Root', $this->walker, $metadataFactory, $messageInterpolator);
$this->context = new ValidationContext('Root', $this->walker, $metadataFactory);
$this->validator = new AllValidator();
$this->validator->initialize($this->context);

View File

@ -22,10 +22,9 @@ class ChoiceValidatorTest extends \PHPUnit_Framework_TestCase
public function setUp()
{
$interpolator = $this->getMock('Symfony\Component\Validator\MessageInterpolator\MessageInterpolatorInterface');
$walker = $this->getMock('Symfony\Component\Validator\GraphWalker', array(), array(), '', false);
$factory = $this->getMock('Symfony\Component\Validator\Mapping\ClassMetadataFactoryInterface');
$context = new ValidationContext('root', $walker, $factory, $interpolator);
$context = new ValidationContext('root', $walker, $factory);
$context->setCurrentClass(__CLASS__);
$this->validator = new ChoiceValidator();
$this->validator->initialize($context);

View File

@ -17,9 +17,8 @@ class CollectionValidatorTest extends \PHPUnit_Framework_TestCase
{
$this->walker = $this->getMock('Symfony\Component\Validator\GraphWalker', array(), array(), '', false);
$metadataFactory = $this->getMock('Symfony\Component\Validator\Mapping\ClassMetadataFactoryInterface');
$messageInterpolator = $this->getMock('Symfony\Component\Validator\MessageInterpolator\MessageInterpolatorInterface');
$this->context = new ValidationContext('Root', $this->walker, $metadataFactory, $messageInterpolator);
$this->context = new ValidationContext('Root', $this->walker, $metadataFactory);
$this->validator = new CollectionValidator();
$this->validator->initialize($this->context);

View File

@ -22,9 +22,8 @@ class ValidValidatorTest extends \PHPUnit_Framework_TestCase
{
$this->walker = $this->getMock('Symfony\Component\Validator\GraphWalker', array(), array(), '', false);
$this->factory = $this->getMock('Symfony\Component\Validator\Mapping\ClassMetadataFactoryInterface');
$messageInterpolator = $this->getMock('Symfony\Component\Validator\MessageInterpolator\MessageInterpolatorInterface');
$this->context = new ValidationContext('Root', $this->walker, $this->factory, $messageInterpolator);
$this->context = new ValidationContext('Root', $this->walker, $this->factory);
$this->validator = new ValidValidator();
$this->validator->initialize($this->context);

View File

@ -22,15 +22,13 @@ class GraphWalkerTest extends \PHPUnit_Framework_TestCase
{
const CLASSNAME = 'Symfony\Tests\Component\Validator\Fixtures\Entity';
protected $interpolator;
protected $factory;
protected $metadata;
public function setUp()
{
$this->interpolator = $this->getMock('Symfony\Component\Validator\MessageInterpolator\MessageInterpolatorInterface');
$this->factory = $this->getMock('Symfony\Component\Validator\Mapping\ClassMetadataFactoryInterface');
$this->walker = new GraphWalker('Root', $this->factory, new ConstraintValidatorFactory(), $this->interpolator);
$this->walker = new GraphWalker('Root', $this->factory, new ConstraintValidatorFactory());
$this->metadata = new ClassMetadata(self::CLASSNAME);
}
@ -74,16 +72,12 @@ class GraphWalkerTest extends \PHPUnit_Framework_TestCase
{
$constraint = new ConstraintA();
$this->interpolator->expects($this->once())
->method('interpolate')
->with($this->equalTo('message'), $this->equalTo(array('param' => 'value')))
->will($this->returnValue('interpolated text'));
$this->walker->walkConstraint($constraint, 'foobar', 'Default', 'firstName.path');
$violations = new ConstraintViolationList();
$violations->add(new ConstraintViolation(
'interpolated text',
'message',
array('param' => 'value'),
'Root',
'firstName.path',
'foobar'

View File

@ -1,39 +0,0 @@
<?php
namespace Symfony\Tests\Component\Validator\MessageInterpolator;
use Symfony\Component\Validator\MessageInterpolator\XliffMessageInterpolator;
class XliffMessageInterpolatorTest extends \PHPUnit_Framework_TestCase
{
public function testInterpolateText()
{
$interpolator = new XliffMessageInterpolator(__DIR__.'/xliff.xml');
$text = $interpolator->interpolate('original', array('param' => 'foobar'));
$this->assertEquals('translation with param foobar', $text);
}
public function testInterpolateFromMultipleFiles()
{
$interpolator = new XliffMessageInterpolator(array(
__DIR__.'/xliff.xml',
__DIR__.'/xliff2.xml',
));
$text1 = $interpolator->interpolate('original', array('param' => 'foobar'));
$text2 = $interpolator->interpolate('second', array('param' => 'baz'));
$this->assertEquals('translation with param foobar', $text1);
$this->assertEquals('second translation with param baz', $text2);
}
public function testConvertParamsToStrings()
{
$interpolator = new XliffMessageInterpolator(__DIR__.'/xliff.xml');
$text = $interpolator->interpolate('original', array('param' => array()));
$this->assertEquals('translation with param Array', $text);
}
}

View File

@ -1,11 +0,0 @@
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" datatype="plaintext" original="file.ext">
<body>
<trans-unit id="1">
<source>original</source>
<target>translation with param %param%</target>
</trans-unit>
</body>
</file>
</xliff>

View File

@ -1,11 +0,0 @@
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" datatype="plaintext" original="file.ext">
<body>
<trans-unit id="1">
<source>second</source>
<target>second translation with param %param%</target>
</trans-unit>
</body>
</file>
</xliff>