class CdnStreamWrapperConstraintValidator in CDN 8.3
CDN-supported stream wrapper constraint validator.
Hierarchy
- class \Drupal\cdn\Plugin\Validation\Constraint\CdnStreamWrapperConstraintValidator extends \Symfony\Component\Validator\ConstraintValidator
Expanded class hierarchy of CdnStreamWrapperConstraintValidator
1 file declares its use of CdnStreamWrapperConstraintValidator
File
- src/
Plugin/ Validation/ Constraint/ CdnStreamWrapperConstraintValidator.php, line 14
Namespace
Drupal\cdn\Plugin\Validation\ConstraintView source
class CdnStreamWrapperConstraintValidator extends ConstraintValidator {
/**
* {@inheritdoc}
*/
public function validate($stream_wrapper, Constraint $constraint) {
if (!$constraint instanceof CdnStreamWrapperConstraint) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__ . '\\CdnStreamWrapper');
}
if ($stream_wrapper === NULL) {
return;
}
if (!static::isValidCdnStreamWrapper($stream_wrapper)) {
$this->context
->buildViolation($constraint->message)
->setParameter('%stream_wrapper', $stream_wrapper)
->setInvalidValue($stream_wrapper)
->addViolation();
}
}
/**
* Validates the given stream wrapper, with an exception for "private".
*
* @param string $stream_wrapper
* A stream wrapper configured for use in Drupal.
*
* @return bool
*/
protected static function isValidCdnStreamWrapper(string $stream_wrapper) : bool {
/** @var \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface $stream_wrapper_manager */
$stream_wrapper_manager = \Drupal::service('stream_wrapper_manager');
$forbidden_wrappers = [
'private',
];
return !in_array($stream_wrapper, $forbidden_wrappers, TRUE) && $stream_wrapper_manager
->getClass($stream_wrapper) !== FALSE;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CdnStreamWrapperConstraintValidator:: |
protected static | function | Validates the given stream wrapper, with an exception for "private". | |
CdnStreamWrapperConstraintValidator:: |
public | function | Checks if the passed value is valid. |