Security update for Core, with self-updated composer
[yaffs-website] / web / core / lib / Drupal / Core / TypedData / Validation / TypedDataAwareValidatorTrait.php
1 <?php
2
3 namespace Drupal\Core\TypedData\Validation;
4
5 use Drupal\Core\TypedData\TypedDataInterface;
6
7 /**
8  * Defines a trait to access the typed data object of a validated value.
9  *
10  * The trait assumes to be used on classes extending
11  * \Symfony\Component\Validator\ConstraintValidator.
12  */
13 trait TypedDataAwareValidatorTrait {
14
15   /**
16    * Gets the typed data object for the validated value.
17    *
18    * @return \Drupal\Core\TypedData\TypedDataInterface
19    *   The typed data object.
20    */
21   public function getTypedData() {
22     $context = $this->context;
23     /** @var \Symfony\Component\Validator\Context\ExecutionContextInterface $context */
24     $data = $context->getObject();
25     if (!$data instanceof TypedDataInterface) {
26       throw new \LogicException("There is no Typed Data object available.");
27     }
28     return $data;
29   }
30
31 }