Pull merge.
[yaffs-website] / web / core / lib / Drupal / Core / TypedData / Validation / TypedDataMetadata.php
1 <?php
2
3 namespace Drupal\Core\TypedData\Validation;
4
5 use Drupal\Core\TypedData\TypedDataInterface;
6 use Symfony\Component\Validator\Exception\BadMethodCallException;
7 use Symfony\Component\Validator\Mapping\CascadingStrategy;
8 use Symfony\Component\Validator\Mapping\MetadataInterface;
9 use Symfony\Component\Validator\Mapping\TraversalStrategy;
10 use Symfony\Component\Validator\ValidationVisitorInterface;
11
12 /**
13  * Validator metadata for typed data objects.
14  *
15  * @see \Drupal\Core\TypedData\Validation\RecursiveValidator::getMetadataFor()
16  */
17 class TypedDataMetadata implements MetadataInterface {
18
19   /**
20    * The typed data object the metadata is about.
21    *
22    * @var \Drupal\Core\TypedData\TypedDataInterface
23    */
24   protected $typedData;
25
26   /**
27    * Constructs the object.
28    *
29    * @param \Drupal\Core\TypedData\TypedDataInterface $typed_data
30    *   The typed data object the metadata is about.
31    */
32   public function __construct(TypedDataInterface $typed_data) {
33     $this->typedData = $typed_data;
34   }
35
36   /**
37    * {@inheritdoc}
38    */
39   public function accept(ValidationVisitorInterface $visitor, $typed_data, $group, $propertyPath) {
40     throw new BadMethodCallException('Not supported.');
41   }
42
43   /**
44    * {@inheritdoc}
45    */
46   public function findConstraints($group) {
47     return $this->getConstraints();
48   }
49
50   /**
51    * {@inheritdoc}
52    */
53   public function getConstraints() {
54     return $this->typedData->getConstraints();
55   }
56
57   /**
58    * {@inheritdoc}
59    */
60   public function getTraversalStrategy() {
61     return TraversalStrategy::NONE;
62   }
63
64   /**
65    * {@inheritdoc}
66    */
67   public function getCascadingStrategy() {
68     // By default, never cascade into validating referenced data structures.
69     return CascadingStrategy::NONE;
70   }
71
72 }