You are here

class ExistsValidator in Markdown 8.2

Validates that a class, interface, trait, or function exists.

@todo Move upstream to https://www.drupal.org/project/installable_plugins. @internal

Hierarchy

  • class \Drupal\markdown\Plugin\Validation\Constraint\ExistsValidator extends \Symfony\Component\Validator\ConstraintValidator

Expanded class hierarchy of ExistsValidator

File

src/Plugin/Validation/Constraint/ExistsValidator.php, line 15

Namespace

Drupal\markdown\Plugin\Validation\Constraint
View source
class ExistsValidator extends ConstraintValidator {
  public $name;

  /**
   * {@inheritdoc}
   */
  public function validate($class, Constraint $constraint) {
    if (!is_string($class) || empty($class) || !class_exists($class) && !interface_exists($class) && !trait_exists($class) && !function_exists($class) && !defined($class) && !is_callable($class)) {

      // Passing an already translated message allows markup to be preserved
      // when it passes to the theme system.
      $message = t($constraint->message, [
        '@name' => isset($constraint->name) ? Markup::create($constraint->name) : $class,
      ]);
      $this->context
        ->addViolation($message);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ExistsValidator::$name public property
ExistsValidator::validate public function Checks if the passed value is valid.