53 $this->_constraints = $constraints;
54 $this->_constraintFactory = $constraintFactory;
55 $this->_validatorFactory = $validatorFactory;
56 $this->_oneValidatorFactory = $oneValidatorFactory;
70 $allowedKeys = [
'arguments',
'callback',
'method',
'methods',
'breakChainOnFailure'];
72 throw new \InvalidArgumentException(
'Configuration has incorrect format');
75 if ($argumentsIsArray) {
87 throw new \InvalidArgumentException(
'Arguments must be an array');
101 throw new \InvalidArgumentException(
'Method has to be passed as string');
104 throw new \InvalidArgumentException(
'Method arguments must be an array');
119 if ($callbackIsArray) {
124 foreach ($callbacks as $callback) {
126 throw new \InvalidArgumentException(
127 'Callback must be instance of \Magento\Framework\Validator\Constraint\Option\Callback' 151 $validator = $this->_validatorFactory->create();
152 foreach ($this->_constraints as $constraintData) {
154 $breakChainOnFailure = !empty($constraintData[
'options'][
'breakChainOnFailure']);
155 $validator->addValidator($this->
_createConstraint($constraintData), $breakChainOnFailure);
204 if (!array_key_exists(
'callback',
$constraint[
'options'])) {
220 if (!array_key_exists(
'methods',
$constraint[
'options'])) {
235 foreach ($configurations as
$alias => $concreteConfigs) {
253 if (isset(
$data[
'options']) && is_array(
$data[
'options'])) {
254 $this->_configureConstraintValidator($validator,
$data[
'options']);
258 $result = new \Magento\Framework\Validator\Constraint\Property(
264 $result = $this->_constraintFactory->create([
'validator' => $validator,
'alias' =>
$data[
'alias']]);
279 $validator = $this->_oneValidatorFactory->create(
282 $data[
'options'][
'arguments']
284 $data[
'options'][
'arguments']
290 throw new \InvalidArgumentException(
292 'Constraint class "%s" must implement \Magento\Framework\Validator\ValidatorInterface',
308 protected function _configureConstraintValidator(
314 foreach (
$options[
'methods'] as $methodData) {
315 $methodName = $methodData[
'method'];
316 if (method_exists($validator, $methodName)) {
317 if (array_key_exists(
'arguments', $methodData)) {
319 call_user_func_array([$validator, $methodName],
$arguments);
330 foreach (
$options[
'callback'] as $callback) {
331 $callback->setArguments($validator);
332 $callback->getValue();
346 if (is_array($argument)) {
349 $argument = $argument->getValue();
_createConstraintValidator(array $data)
elseif(isset( $params[ 'redirect_parent']))
call_user_func($callable, $param)
const CONSTRAINT_TYPE_PROPERTY
__construct(\Magento\Framework\Validator\ConstraintFactory $constraintFactory, \Magento\Framework\ValidatorFactory $validatorFactory, \Magento\Framework\Validator\UniversalFactory $oneValidatorFactory, array $constraints)
addConfigurations(array $configurations)
_createConstraint(array $data)
_applyArgumentsCallback(array $arguments)
_checkMethodArguments(array $configuration)
_checkConfigurationCallback(array $configuration, $callbackIsArray)
_createValidatorInstance()
_checkConfigurationArguments(array $configuration, $argumentsIsArray)
_addConstraintCallback(array $constraint, \Magento\Framework\Validator\Constraint\Option\Callback $callback)
addConfiguration($alias, array $configuration)
_addConstraintMethod(array $constraint, array $configuration)