TypedDataAwareValidatorTrait.php in Zircon Profile 8.0
Same filename and directory in other branches
Namespace
Drupal\Core\TypedData\ValidationFile
core/lib/Drupal/Core/TypedData/Validation/TypedDataAwareValidatorTrait.phpView source
<?php
/**
* @file
* Contains \Drupal\Core\TypedData\Validation\TypedDataAwareValidatorTrait.
*/
namespace Drupal\Core\TypedData\Validation;
use Drupal\Core\TypedData\TypedDataInterface;
/**
* Defines a trait to access the typed data object of a validated value.
*
* The trait assumes to be used on classes extending
* \Symfony\Component\Validator\ConstraintValidator.
*/
trait TypedDataAwareValidatorTrait {
/**
* Gets the typed data object for the validated value.
*
* @return \Drupal\Core\TypedData\TypedDataInterface
* The typed data object.
*/
public function getTypedData() {
$context = $this->context;
/** @var \Symfony\Component\Validator\Context\ExecutionContextInterface $context */
$data = $context
->getObject();
if (!$data instanceof TypedDataInterface) {
throw new \LogicException("There is no Typed Data object available.");
}
return $data;
}
}
Traits
Name | Description |
---|---|
TypedDataAwareValidatorTrait | Defines a trait to access the typed data object of a validated value. |