class ClassResolverConstraint

Checks if a method on a service or instantiated object returns true.

For example to call the method 'isValidScheme' on the service 'stream_wrapper_manager', use: ['stream_wrapper_manager', 'isValidScheme']. It is also possible to use a class if it implements ContainerInjectionInterface. It will use the ClassResolver to resolve the class and return an instance. Then it will call the configured method on that instance.

The called method should return TRUE when the result is valid. All other values will be considered as invalid.

Hierarchy

  • class \Drupal\Core\Validation\Plugin\Validation\Constraint\ClassResolverConstraint extends \Symfony\Component\Validator\Constraint

Expanded class hierarchy of ClassResolverConstraint

File

core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/ClassResolverConstraint.php, line 24

Namespace

Drupal\Core\Validation\Plugin\Validation\Constraint
View source
class ClassResolverConstraint extends SymfonyConstraint {
    
    /**
     * The error message if validation fails.
     *
     * @var string
     */
    public string $message = "Calling '@method' method with value '@value' on '@classOrService' evaluated as invalid.";
    
    /**
     * Class or service.
     *
     * @var array
     */
    public string $classOrService;
    
    /**
     * Method to call.
     *
     * @var string
     */
    public string $method;
    
    /**
     * {@inheritdoc}
     */
    public function getRequiredOptions() : array {
        return [
            'classOrService',
            'method',
        ];
    }

}

Members

Title Sort descending Modifiers Object type Summary
ClassResolverConstraint::$classOrService public property Class or service.
ClassResolverConstraint::$message public property The error message if validation fails.
ClassResolverConstraint::$method public property Method to call.
ClassResolverConstraint::getRequiredOptions public function

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.