Adds a new validation rule callback that is tied to the current
instance only.

@param string   $name
@param callable $callback
@param string   $message

@return $this
@throws \InvalidArgumentException
181141
public function addInstanceRule(string $name, callable $callback, string $message = null): self
    {
        static::assertRuleCallback($callback);

        $this->_instanceRules[$name] = $callback;
        $this->_instanceRuleMessage[$name] = $message;

        return $this;
    }
864173
public static function warning($message = null, $name = null)
    {
        return self::generic($message, WarningMessage::$CSSClass, $name);
    }
415159
public function addMethod(string $name, Closure $callback): Package
    {
        $this->methods[$name] = $callback->bindTo($this, get_class($this));

        return $this;
    }
1369834
protected function callMessageBuilder($callback, $message)
    {
        if ($callback instanceof Closure) {
            return call_user_func($callback, $message);
        } else if (is_string($callback)) {
            return $this->container[$callback]->mail($message);
        }

        throw new \InvalidArgumentException("Callback is not valid.");
    }
136832
public static function createCallback(string $name, callable $callback): DenormalizationFieldMappingBuilderInterface
    {
        $self = new self($name);
        $self->fieldDenormalizer = new CallbackFieldDenormalizer($callback);

        return $self;
    }
883629
public T validationCallback(ValidationCallback callback) {
        if (callback instanceof ApplicationContextAware) {
            ((ApplicationContextAware) callback).setApplicationContext(applicationContext);
        }

        getAction().setValidationCallback(callback);
        return self;
    }
580643
public function setCallback($callback)
    {
        if (!$callback instanceof Closure) {
            throw new Exception\InvalidArgumentException(sprintf(
                'Invalid parameter for callback: must be %s',
                Closure::class
            ));
        }

        return parent::setCallback($callback);
    }
144058
public static function success($message = null, $name = null)
    {
        return self::generic($message, SuccessMessage::$CSSClass, $name);
    }
1318025
public function after(\Closure $callback) : ValidatorInterface
    {
        $this->after[] = function () use ($callback) {
            return call_user_func_array($callback, [$this]);
        };

        return $this;
    }
1100374
public static function create($message, $name = null)
    {
        return Message::generic($message, self::$CSSClass, $name);
    }
1054081
public function addRule(string $name, callable $callback, string $message = null): self
    {
        if ($message === null) {
            $message = static::ERROR_DEFAULT;
        }

        static::assertRuleCallback($callback);

        static::$_rules[$name] = $callback;
        static::$_ruleMessages[$name] = $message;

        return $this;
    }
768094
protected function addStage(string $name, string $message, callable $callback): void
	{
		$this->stages[$name] = ["message" => $message, "callback" => $callback];
	}
279715
public function addListener($name, callable $callback) {
        if(!array_key_exists($name, $this->registered_events)) {
            $this->registered_events[$name] = [];
        }

        $this->registered_events[$name][] = $callback;
    }
818723
public static function createFromClosure(Validator $validator, callable $callback): self
    {
        $self = new static($validator);

        $self->setCallback(function (array $attributes, string $name, array $parameters) use ($callback) {
            return $callback($attributes, $name, $parameters);
        });

        return $self;
    }
1119003
public function addValidation(string $name, string $validation): void{
        $this->validations[$name] = $validation;
    }
135055
public function setMessage(
        $message,
        $messageType = ValidationResult::TYPE_ERROR,
        $messageCast = ValidationResult::CAST_TEXT
    ) {
        if (!in_array($messageCast, [ValidationResult::CAST_TEXT, ValidationResult::CAST_HTML])) {
            throw new InvalidArgumentException("Invalid message cast type");
        }
        $this->message = $message;
        $this->messageType = $messageType;
        $this->messageCast = $messageCast;
        return $this;
    }
148861
public function on(string $event, $callback)
    {
        if (! is_string($callback) && ! is_callable($callback)) {
            throw new InvalidArgumentException(
                'Invalid websocket callback. Must be a string or callable.'
            );
        }

        $this->callbacks[$event] = $callback;

        return $this;
    }