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 8000
[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] Documented 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 metadata classes
  • Loading branch information
webmozart committed Mar 30, 2014
commit 79387a7d5e80ab3e0bbce6f35e275c778a9f9c85
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,30 @@

namespace Symfony\Component\Validator\Mapping;

use Symfony\Component\Validator\Exception\NoSuchMetadataException;
use Symfony\Component\Validator\MetadataFactoryInterface;

/**
* Simple implementation of MetadataFactoryInterface that can be used when using ValidatorInterface::validateValue().
* Metadata factory that does not store metadata.
*
* This implementation is useful if you want to validate values against
* constraints only and you don't need to add constraints to classes and
* properties.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class BlackholeMetadataFactory implements MetadataFactoryInterface
{
/**
* @inheritdoc
* {@inheritdoc}
*/
public function getMetadataFor($value)
{
throw new \LogicException('BlackholeClassMetadataFactory only works with ValidatorInterface::validateValue().');
throw new NoSuchMetadataException('This class does not support metadata.');
}

/**
* @inheritdoc
* {@inheritdoc}
*/
public function hasMetadataFor($value)
{
Expand Down
65 changes: 46 additions & 19 deletions src/Symfony/Component/Validator/Mapping/ClassMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
use Symfony\Component\Validator\Exception\GroupDefinitionException;

/**
* Represents all the configured constraints on a given class.
* Default implementation of {@link ClassMetadataInterface}.
*
* This class supports serialization and cloning.
*
* @author Bernhard Schussek <bschussek@gmail.com>
* @author Fabien Potencier <fabien@symfony.com>
Expand All @@ -31,36 +33,64 @@ class ClassMetadata extends ElementMetadata implements LegacyMetadataInterface,
{
/**
* @var string
*
* @internal This property is public in order to reduce the size of the
* class' serialized representation. Do not access it. Use
* {@link getClassName()} instead.
*/
public $name;

/**
* @var string
*
* @internal This property is public in order to reduce the size of the
* class' serialized representation. Do not access it. Use
* {@link getDefaultGroup()} instead.
*/
public $defaultGroup;

/**
* @var MemberMetadata[]
*
* @internal This property is public in order to reduce the size of the
* class' serialized representation. Do not access it. Use
* {@link getPropertyMetadata()} instead.
*/
public $members = array();

/**
* @var PropertyMetadata[]
*
* @internal This property is public in order to reduce the size of the
* class' serialized representation. Do not access it. Use
* {@link getPropertyMetadata()} instead.
*/
public $properties = array();

/**
* @var GetterMetadata[]
*
* @internal This property is public in order to reduce the size of the
* class' serialized representation. Do not access it. Use
* {@link getPropertyMetadata()} instead.
*/
public $getters = array();

/**
* @var array
*
* @internal This property is public in order to reduce the size of the
* class' serialized representation. Do not access it. Use
* {@link getGroupSequence()} instead.
*/
public $groupSequence = array();

/**
* @var Boolean
*
* @internal This property is public in order to reduce the size of the
* class' serialized representation. Do not access it. Use
* {@link isGroupSequenceProvider()} instead.
*/
public $groupSequenceProvider = false;

Expand All @@ -70,6 +100,10 @@ class ClassMetadata extends ElementMetadata implements LegacyMetadataInterface,
* By default, only instances of {@link \Traversable} are traversed.
*
* @var integer
*
* @internal This property is public in order to reduce the size of the
* class' serialized representation. Do not access it. Use
* {@link getTraversalStrategy()} instead.
*/
public $traversalStrategy = TraversalStrategy::IMPLICIT;

Expand All @@ -94,6 +128,11 @@ public function __construct($class)
}
}

/**
* {@inheritdoc}
*
* @deprecated Deprecated since version 2.5, to be removed in Symfony 3.0.
*/
public function accept(ValidationVisitorInterface $visitor, $value, $group, $propertyPath, $propagatedGroup = null)
{
if (null === $propagatedGroup && Constraint::DEFAULT_GROUP === $group
Expand Down Expand Up @@ -129,9 +168,7 @@ public function accept(ValidationVisitorInterface $visitor, $value, $group, $pro
}

/**
* Returns the properties to be serialized
*
* @return array
* {@inheritdoc}
*/
public function __sleep()
{
Expand All @@ -152,9 +189,7 @@ public function __sleep()
}

/**
* Returns the fully qualified name of the class
*
* @return string The fully qualified class name
* {@inheritdoc}
*/
public function getClassName()
{
Expand Down Expand Up @@ -356,9 +391,7 @@ public function getPropertyMetadata($property)
}

/**
* Returns all properties for which constraints are defined.
*
* @return array An array of property names
* {@inheritdoc}
*/
public function getConstrainedProperties()
{
Expand Down Expand Up @@ -398,19 +431,15 @@ public function setGroupSequence($groupSequence)
}

/**
* Returns whether this class has an overridden default group sequence.
*
* @return Boolean
* {@inheritdoc}
*/
public function hasGroupSequence()
{
return count($this->groupSeque F438 nce) > 0;
}

/**
* Returns the default group sequence for this class.
*
* @return GroupSequence The group sequence or null
* {@inheritdoc}
*/
public function getGroupSequence()
{
Expand Down Expand Up @@ -452,9 +481,7 @@ public function setGroupSequenceProvider($active)
}

/**
* Returns whether the class is a group sequence provider.
*
* @return Boolean
* {@inheritdoc}
*/
public function isGroupSequenceProvider()
{
Expand Down
58 changes: 55 additions & 3 deletions src/Symfony/Component/Validator/Mapping/ClassMetadataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,81 @@
use Symfony\Component\Validator\Mapping\Cache\CacheInterface;

/**
* A factory for creating metadata for PHP classes.
* Creates new {@link ClassMetadataInterface} instances.
*
* Whenever {@link getMetadataFor()} is called for the first time with a given
* class name or object of that class, a new metadata instance is created and
* returned. On subsequent requests for the same class, the same metadata
* instance will be returned.
*
* You can optionally pass a {@link LoaderInterface} instance to the constructor.
* Whenever a new metadata instance, it will be passed to the loader, which can
Copy link
Member

Choose a reason for hiding this comment

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

missing verb in Whenever a new metadata instance

* configure the metadata based on configuration loaded from the filesystem or
* a database. If you want to use multiple loaders, wrap them in a
* {@link Loader\LoaderChain}.
*
* You can also optionally pass a {@link CacheInterface} instance to the
* constructor. This cache will be used for persisting the generated metadata
* between multiple PHP requests.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class ClassMetadataFactory implements MetadataFactoryInterface
{
/**
* The loader for loading the class metadata
*
* @var LoaderInterface
*/
protected $loader;

/**
* The cache for caching class metadata
*
* @var CacheInterface
*/
protected $cache;

/**
* The loaded metadata, indexed by class name
*
* @var ClassMetadata[]
*/
protected $loadedClasses = array();

/**
* Creates a new metadata factory.
*
* @param LoaderInterface|null $loader The loader for configuring new metadata
* @param CacheInterface|null $cache The cache for persisting metadata
* between multiple PHP requests
*/
public function __construct(LoaderInterface $loader = null, CacheInterface $cache = null)
{
$this->loader = $loader;
$this->cache = $cache;
}

/**
* {@inheritdoc}
* Returns the metadata for the given class name or object.
*
* If the method was called with the same class name (or an object of that
* class) before, the same metadata instance is returned.
*
* If the factory was configured with a cache, this method will first look
* for an existing metadata instance in the cache. If an existing instance
* is found, it will be returned without further ado.
*
* Otherwise, a new metadata instance is created. If the factory was
* configured with a loader, the metadata is passed to the
* {@link LoaderInterface::loadClassMetadata()} method for further
* configuration. At last, the new object is returned.
*
* @param string|object $value A class name or an object
*
* @return MetadataInterface The metadata for the value
*
* @throws NoSuchMetadataException If no metadata exists for the given value
*/
public function getMetadataFor($value)
{
Expand Down Expand Up @@ -93,7 +140,12 @@ public function getMetadataFor($value)
}

/**
* {@inheritdoc}
* Returns whether the factory is able to return metadata for the given
* class name or object.
*
* @param string|object $value A class name or an object
*
* @return Boolean Whether metadata can be returned for that class
*/
public function hasMetadataFor($value)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,66 @@
use Symfony\Component\Validator\PropertyMetadataContainerInterface as LegacyPropertyMetadataContainerInterface;;

/**
* @since %%NextVersion%%
* Stores all metadata needed for validating objects of specific class.
*
* Most importantly, the metadata stores the constraints against which an object
Copy link
Contributor

Choose a reason for hiding this comment

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

sounds like this line could be altogether removed as its phrasing seems equivalent to the one in L20?

* and its properties should be validated.
*
* Additionally, the metadata stores whether the "Default" group is overridden
* by a group sequence for that class and whether instances of that class
* should be traversed or not.
*
* @since 2.5
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @see MetadataInterface
* @see \Symfony\Component\Validator\Constraints\GroupSequence
* @see \Symfony\Component\Validator\GroupSequenceProviderInterface
* @see TraversalStrategy
*/
interface ClassMetadataInterface extends MetadataInterface, LegacyPropertyMetadataContainerInterface, ClassBasedInterface
{
/**
* Returns the names of all constrained properties.
*
* @return string[] A list of property names
*/
public function getConstrainedProperties();

/**
* Returns whether the "Default" group is overridden by a group sequence.
*
* If it is, you can access the group sequence with {@link getGroupSequence()}.
*
* @return Boolean Returns true if the "Default" group is overridden
*
* @see \Symfony\Component\Validator\Constraints\GroupSequence
*/
public function hasGroupSequence();

/**
* Returns the group sequence that overrides the "Default" group for this
* class.
*
* @return \Symfony\Component\Validator\Constraints\GroupSequence|null The group sequence or null
*
* @see \Symfony\Component\Validator\Constraints\GroupSequence
*/
public function getGroupSequence();

/**
* Returns whether the "Default" group is overridden by a dynamic group
* sequence obtained by the validated objects.
*
* If this method returns true, the class must implement
* {@link \Symfony\Component\Validator\GroupSequenceProviderInterface}.
* This interface will be used to obtain the group sequence when an object
* of this class is validated.
*
* @return Boolean Returns true if the "Default" group is overridden by
* a dynamic group sequence
*
* @see \Symfony\Component\Validator\GroupSequenceProviderInterface
*/
public function isGroupSequenceProvider();
}
8 changes: 8 additions & 0 deletions src/Symfony/Component/Validator/Mapping/ElementMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@

namespace Symfony\Component\Validator\Mapping;

/**
* Contains the metadata of a structural element.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated Deprecated since version 2.5, to be removed in Symfony 3.0.
* Extend {@link GenericMetadata} instead.
*/
abstract class ElementMetadata extends GenericMetadata
{
}
Loading
0