8000 [Validator] New NodeTraverser implementation by webmozart · Pull Request #10287 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Validator] New NodeTraverser implementation #10287

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 86 commits into from
Mar 31, 2014
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
25cdc68
[Validator] Refactored ValidatorTest and ValidationVisitorTest into a…
webmozart Feb 12, 2014
a6ed4ca
[Validator] Prototype of the traverser implementation
webmozart Feb 17, 2014
a40189c
[Validator] Decoupled the new classes a bit
webmozart Feb 17, 2014
7e3a41d
[Validator] Moved visitors to NodeVisitor namespace
webmozart Feb 17, 2014
b1a9477
[Validator] Added ObjectInitializer visitor
webmozart Feb 17, 2014
1156bde
[Validator] Extracted code for group sequence resolving into GroupSeq…
webmozart Feb 17, 2014
321d5bb
[Validator] Throw exception if ObjectInitializer is constructed witho…
webmozart Feb 17, 2014
680f1ee
[Validator] Renamed $params to $parameters
webmozart Feb 17, 2014
8ae68c9
[Validator] Made tests green (yay!)
webmozart Feb 18, 2014
c1b1e03
[Validator] Added TODO reminder
webmozart Feb 18, 2014
5fbf848
[Validator] Added note about Callback constraint to CHANGELOG
webmozart Feb 18, 2014
8318286
[Validator] Completed GroupSequence implementation
webmozart Feb 18, 2014
f6b7288
[Validator] Removed unused use statement
webmozart Feb 18, 2014
4ea3ff6
[Validator] Finished inline documentation of ExecutionContext[Interface]
webmozart Feb 18, 2014
adc1437
[Validator] Fixed failing tests
webmozart Feb 18, 2014
499b2bb
[Validator] Completed test coverage of ExecutionContext
webmozart Feb 18, 2014
405a03b
[Validator] Updated deprecation notes in GroupSequence
webmozart Feb 18, 2014
9b07b0c
[Validator] Implemented BC validation of arrays through validate()
webmozart Feb 18, 2014
297ba4f
[Validator] Added a note why scalars are passed to cascadeObject() in…
webmozart Feb 18, 2014
09f744b
[Validator] Implemented BC traversal of traversables through validate()
webmozart Feb 18, 2014
ee1adad
[Validator] Implemented handling of arrays and Traversables in Legacy…
webmozart Feb 19, 2014
718601c
[Validator] Changed validateValue() to validate() in the new API
webmozart Feb 19, 2014
feb3d6f
[Validator] Tested the validation in a separate context
webmozart Feb 19, 2014
1e81f3b
[Validator] Finished test coverage and documentation of ExecutionCont…
webmozart Feb 19, 2014
9c9e715
[Validator] Completed documentation of GroupManagerInterface
webmozart Feb 19, 2014
2c65a28
[Validator] Completed test coverage and documentation of the Node cla…
webmozart Feb 19, 2014
a3555fb
[Validator] Fixed: Objects are not traversed unless they are instance…
webmozart Feb 19, 2014
bc29591
[Validator] Clearly separated classes supporting the API <2.5/2.5+
webmozart Feb 19, 2014
26eafa4
[Validator] Removed unused use statements
webmozart Feb 19, 2014
df41974
[Validator] Changed context manager to context factory
webmozart Feb 19, 2014
e440690
[Validator] Renamed validateCollection() to validateObjects()
webmozart Feb 19, 2014
e057b19
[Validator] Decoupled ContextRefresher from ExecutionContext
webmozart Feb 19, 2014
230f2a7
[Validator] Fixed exception message
webmozart Feb 19, 2014
cf1281f
[Validator] Added "Visitor" suffix to all node visitors
webmozart Feb 20, 2014
94583a9
[Validator] Changed NodeTraverser to traverse nodes iteratively, not …
webmozart Feb 20, 2014
117b1b9
[Validator] Wrapped collections into CollectionNode instances
webmozart Feb 20, 2014
51197f6
[Validator] Made traversal of Traversables consistent
webmozart Feb 20, 2014
08172bf
[Validator] Merged validate(), validateObject() and validateObjects()…
webmozart Feb 20, 2014
aeb6822
[Validator] Improved visitor names
webmozart Feb 20, 2014
4161371
[Validator] Removed unused use statements
webmozart Feb 20, 2014
76d8c9a
[Validator] Fixed typos
webmozart Feb 20, 2014
778ec24
[Validator] Removed helper class Traversal
webmozart Feb 20, 2014
6fc6ecd
[Validator] Fixed tests under PHP<5.3.9
webmozart Feb 20, 2014
2936d10
[Validator] Removed unused use statement
webmozart Feb 20, 2014
e8fa15b
[Validator] Fixed the new validator API under PHP < 5.3.9
webmozart Feb 20, 2014
8558377
[Validator] Added deprecation notes
webmozart Feb 20, 2014
dbce5a2
[Validator] Updated outdated doc blocks
webmozart Feb 20, 2014
822fe47
[Validator] Completed inline documentation of the Node classes and th…
webmozart Feb 21, 2014
186c115
[Validator] Improved test coverage of NonRecursiveNodeTraverser
webmozart Feb 21, 2014
299c2dc
[Validator] Improved test coverage and prevented duplicate validation…
webmozart Feb 21, 2014
be7f055
[Validator] Visitors may now abort the traversal by returning false f…
webmozart Feb 21, 2014
9986f03
[Validator] Added inline documentation for the PropertyPath utility c…
webmozart Feb 21, 2014
524a953
[Validator] Improved inline documentation of the validators
webmozart Feb 21, 2014
9ca61df
[Validator] Improved inline documentation of CascadingStrategy and Tr…
webmozart Feb 21, 2014
01ceeda
[Validator] Improved test coverage of the Traverse constraint
webmozart Feb 21, 2014
79387a7
[Validator] Improved inline documentation of the metadata classes
webmozart Feb 21, 2014
987313d
[Validator] Improved inline documentation of the violation builder
webmozart Feb 21, 2014
93fdff7
[Validator] The supported API versions can now be passed to the Valid…
webmozart Feb 21, 2014
886e05e
[Validator] Removed unused use statement
webmozart Feb 21, 2014
f61d31e
[Validator] Fixed grammar
webmozart Feb 21, 2014
23534ca
[Validator] Added a recursive clone of the new implementation for spe…
webmozart Feb 22, 2014
38e26fb
[Validator] Decoupled RecursiveContextualValidator from Node
webmozart Feb 22, 2014
274d4e6
[Validator] Changed ValidatorBuilder to always use LegacyExecutionCon…
webmozart Mar 11, 2014
eeed509
[Validator] Improved phpdoc of RecursiveValidator
webmozart Mar 11, 2014
5c479d8
[Validator] Simplified validateNodeForGroup
webmozart Mar 11, 2014
eed29d8
[Validator] Improved performance of *ContextualValidator::validate()
webmozart Mar 11, 2014
50bb84d
[Validator] Optimized RecursiveContextualValidator
webmozart Mar 11, 2014
be508e0
[Validator] Merged DefaultGroupReplacingVisitor and ContextUpdateVisi…
webmozart Mar 11, 2014
1622eb3
[Validator] Fixed reference to removed class in ValidatorBuilder
webmozart Mar 11, 2014
94ef21e
[Validator] Optimized use statements
webmozart Mar 17, 2014
73c9cc5
[Validator] Optimized performance by calling spl_object_hash() only o…
webmozart Mar 17, 2014
2f23d97
[Validator] Reduced number of method calls on the execution context
webmozart Mar 17, 2014
029a716
[Validator] Moved logic of replaceDefaultGroup() to validateNode()
webmozart Mar 17, 2014
3183aed
[Validator] Improved performance of cache key generation
webmozart Mar 17, 2014
90c27bb
[Validator] Removed traverser implementation
webmozart Mar 18, 2014
166d71a
[Validator] Removed unused property
webmozart Mar 18, 2014
7bc952d
[Validator] Improved inline documentation of RecursiveContextualValid…
webmozart Mar 18, 2014
1b111d0
[Validator] Fixed typos pointed out by @cordoval
webmozart Mar 18, 2014
0946dbe
[Validator] Adapted CHANGELOG
webmozart Mar 18, 2014
9b204c9
[FrameworkBundle] Implemented configuration to select the desired Val…
webmozart Mar 18, 2014
c5629bb
[Validator] Added getObject() to ExecutionContextInterface
webmozart Mar 18, 2014
3dc2b4d
[Validator] Made "symfony/property-access" an optional dependency
webmozart Mar 18, 2014
0bfde4a
[Validator] Fixed misnamed method calls in FrameworkExtension
webmozart Mar 18, 2014
b1badea
[Validator] Fixed failing CsrfFormLoginTest
webmozart Mar 30, 2014
68d8018
[Validator] Documen 10000 ted changes in the UPGRADE files
webmozart Mar 30, 2014
ca6a722
[Validator] Converted `@deprecate` doc comment into regular doc comment
webmozart Mar 30, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[Validator] Improved inline documentation of the violation builder
  • Loading branch information
webmozart committed Mar 30, 2014
commit 987313d315f1083e3e5a7fd6f25b91e93cbcccaa
59 changes: 37 additions & 22 deletions src/Symfony/Component/Validator/ConstraintViolation.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ class ConstraintViolation implements ConstraintViolationInterface
/**
* @var array
*/
private $messageParameters;
private $parameters;

/**
* @var integer|null
*/
private $messagePluralization;
private $plural;

/**
* @var mixed
Expand All @@ -61,27 +61,26 @@ class ConstraintViolation implements ConstraintViolationInterface
/**
* Creates a new constraint violation.
*
* @param string $message The violation message.
* @param string $messageTemplate The raw violation message.
* @param array $messageParameters The parameters to substitute
* in the raw message.
* @param mixed $root The value originally passed
* to the validator.
* @param string $propertyPath The property path from the
* root value to the invalid
* value.
* @param mixed $invalidValue The invalid value causing the
* violation.
* @param integer|null $messagePluralization The pluralization parameter.
* @param mixed $code The error code of the
* violation, if any.
*/
public function __construct($message, $messageTemplate, array $messageParameters, $root, $propertyPath, $invalidValue, $messagePluralization = null, $code = null)
* @param string $message The violation message
* @param string $messageTemplate The raw violation message
* @param array $parameters The parameters to substitute in the
* raw violation message
* @param mixed $root The value originally passed to the
* validator
* @param string $propertyPath The property path from the root
* value to the invalid value
* @param mixed $invalidValue The invalid value that caused this
* violation
* @param integer|null $plural The number for determining the plural
* form when translation the message
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

translating

* @param mixed $code The error code of the violation
*/
public function __construct($message, $messageTemplate, array $parameters, $root, $propertyPath, $invalidValue, $plural = null, $code = null)
{
$this->message = $message;
$this->messageTemplate = $messageTemplate;
$this->messageParameters = $messageParameters;
$this->messagePluralization = $messagePluralization;
$this->parameters = $parameters;
$this->plural = $plural;
$this->root = $root;
$this->propertyPath = $propertyPath;
$this->invalidValue = $invalidValue;
Expand Down Expand Up @@ -130,15 +129,31 @@ public function getMessageTemplate()
*/
public function getMessageParameters()
{
return $this->messageParameters;
return $this->parameters;
}

/**
* Alias of {@link getMessageParameters()}.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the reason for an alias? should the old one not get deprecated if the new one is better named?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@webmozart ^^ ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Tobion Yes, but we can't add the new version to ConstraintViolationInterface because that is marked as API. I don't want to simply deprecate a method without offering an alternative either.

The long versions are going to be removed in Symfony 3.0 when we can change the interface (and move it to the Violation sub-namespace, for that sake).

*/
public function getParameters()
{
return $this->parameters;
}

/**
* {@inheritDoc}
*/
public function getMessagePluralization()
{
return $this->messagePluralization;
return $this->plural;
}

/**
* Alias of {@link getMessagePluralization()}.
*/
public function getPlural()
{
return $this->plural;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @see ExecutionContextInterface
*
* @internal You should not instantiate or use this class. Code against
* {@link ExecutionContextInterface} instead.
*/
class ExecutionContext implements ExecutionContextInterface
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
*
* @since 2.5
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @internal You should not instantiate or use this class. Code against
* {@link ExecutionContextFactoryInterface} instead.
*/
class ExecutionContextFactory implements ExecutionContextFactoryInterface
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ public function testAddCustomizedViolation()
$context->buildViolation('Message %param%')
->setParameter('%param%', 'value')
->setInvalidValue('Invalid value')
->setPluralization(2)
->setPlural(2)
->setCode('Code')
->addViolation();
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,64 @@
use Symfony\Component\Validator\Util\PropertyPath;

/**
* @since %%NextVersion%%
* Default implementation of {@link ConstraintViolationBuilderInterface}.
*
* @since 2.5
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @internal You should not instantiate or use this class. Code against
* {@link ConstraintViolationBuilderInterface} instead.
*/
class ConstraintViolationBuilder implements ConstraintViolationBuilderInterface
{
/**
* @var ConstraintViolationList
*/
private $violations;

/**
* @var string
*/
private $message;

/**
* @var array
*/
private $parameters;

/**
* @var mixed
*/
private $root;

/**
* @var mixed
*/
private $invalidValue;

/**
* @var string
*/
private $propertyPath;

/**
* @var TranslatorInterface
*/
private $translator;

/**
* @var string|null
*/
private $translationDomain;

private $pluralization;
/**
* @var integer|null
*/
private $plural;

/**
* @var mixed
*/
private $code;

public function __construct(ConstraintViolationList $violations, $message, array $parameters, $root, $propertyPath, $invalidValue, TranslatorInterface $translator, $translationDomain = null)
Expand All @@ -54,58 +89,82 @@ public function __construct(ConstraintViolationList $violations, $message, array
$this->translationDomain = $translationDomain;
}

public function atPath($subPath)
/**
* {@inheritdoc}
*/
public function atPath($path)
{
$this->propertyPath = PropertyPath::append($this->propertyPath, $subPath);
$this->propertyPath = PropertyPath::append($this->propertyPath, $path);

return $this;
}

/**
* {@inheritdoc}
*/
public function setParameter($key, $value)
{
$this->parameters[$key] = $value;

return $this;
}

/**
* {@inheritdoc}
*/
public function setParameters(array $parameters)
{
$this->parameters = $parameters;

return $this;
}

/**
* {@inheritdoc}
*/
public function setTranslationDomain($translationDomain)
{
$this->translationDomain = $translationDomain;

return $this;
}

/**
* {@inheritdoc}
*/
public function setInvalidValue($invalidValue)
{
$this->invalidValue = $invalidValue;

return $this;
}

public function setPluralization($pluralization)
/**
* {@inheritdoc}
*/
public function setPlural($number)
{
$this->pluralization = $pluralization;
$this->plural = $number;

return $this;
}

/**
* {@inheritdoc}
*/
public function setCode($code)
{
$this->code = $code;

return $this;
}

/**
* {@inheritdoc}
*/
public function addViolation()
{
if (null === $this->pluralization) {
if (null === $this->plural) {
$translatedMessage = $this->translator->trans(
$this->message,
$this->parameters,
Expand All @@ -115,7 +174,7 @@ public function addViolation()
try {
$translatedMessage = $this->translator->transChoice(
$this->message,
$this->pluralization,
$this->plural,
$this->parameters,
$this->translationDomain#
);
Expand All @@ -135,7 +194,7 @@ public function addViolation()
$this->root,
$this->propertyPath,
$this->invalidValue,
$this->pluralization,
$this->plural,
$this->code
));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,97 @@
namespace Symfony\Component\Validator\Violation;

/**
* @since %%NextVersion%%
* Builds {@link \Symfony\Component\Validator\ConstraintViolationInterface}
* objects.
*
* Use the various methods on this interface to configure the built violation.
* Finally, call {@link addViolation()} to add the violation to the current
* execution context.
*
* @since 2.5
* @author Bernhard Schussek <bschussek@gmail.com>
*/
interface ConstraintViolationBuilderInterface
{
public function atPath($subPath);
/**
* Stores the property path at which the violation should be generated.
*
* The passed path will be appended to the current property path of the
* execution context.
*
* @param string $path The property path
*
* @return ConstraintViolationBuilderInterface This builder
*/
public function atPath($path);

/**
* Sets a parameter to be inserted into the violation message.
*
* @param string $key The name of the parameter
* @param string $value The value to be inserted in the parameter's place
*
* @return ConstraintViolationBuilderInterface This builder
*/
public function setParameter($key, $value);

/**
* Sets all parameters to be inserted into the violation message.
*
* @param array $parameters An array with the parameter names as keys and
* the values to be inserted in their place as
* values
*
* @return ConstraintViolationBuilderInterface This builder
*/
public function setParameters(array $parameters);
93C6
/**
* Sets the translation domain which should be used for translating the
* violation message.
*
* @param string $translationDomain The translation domain
*
* @return ConstraintViolationBuilderInterface This builder
*
* @see \Symfony\Component\Translation\TranslatorInterface
*/
public function setTranslationDomain($translationDomain);

/**
* Sets the invalid value that caused this violation.
*
* @param mixed $invalidValue The invalid value
*
* @return ConstraintViolationBuilderInterface This builder
*/
public function setInvalidValue($invalidValue);

public function setPluralization($pluralization);
/**
* Sets the number which determines how the plural form of the violation
* message is chosen when it is translated.
*
* @param integer $number The number for determining the plural form
*
* @return ConstraintViolationBuilderInterface This builder
*
* @see \Symfony\Component\Translation\TranslatorInterface::transChoice()
*/
public function setPlural($number);

/**
* Sets the violation code.
*
* @param mixed $code The violation code
*
* @return ConstraintViolationBuilderInterface This builder
*
* @internal This method is internal and should not be used by user code
*/
public function setCode($code);

/**
* Adds the violation to the current execution context.
*/
public function addViolation();
}
0