Получение конфигурации компонента
Вывод в шаблон переменной $app с конфигом компонента, переменной $validator для JSValidation.
@return $this
199747
public function shareConfig()
    {
        $this->tabs = collect();
        $this->tabs_data = collect();
        View::share('package', $this);
        $this->valid = $this->getValid();
        View::share('validator', JsValidator::make($this->getValid()));

        return $this;
    }
117004
public function validationDefault(Validator $validator)
    {
        $validator
            ->uuid('id')
            ->allowEmpty('id', 'create');

        $validator
            ->requirePresence('label', 'create')
            ->notEmpty('label');

        $validator
            ->allowEmpty('url');

        $validator
            ->boolean('new_window')
            ->allowEmpty('new_window');

        $validator
            ->requirePresence('menu_id', 'create')
            ->notEmpty('menu_id');

        $validator
            ->allowEmpty('icon');

        $validator
            ->requirePresence('type', 'create')
            ->notEmpty('type');

        return $validator;
    }
994877
public function addValidator($validator)
    {
        if (!($validator instanceof \Pop\Validator\AbstractValidator) && !is_callable($validator)) {
            throw new Exception('Error: The validator must be an instance of Pop\Validator\AbstractValidator or a callable object.');
        }
        $this->validators[] = $validator;
        return $this;
    }
417960
public function validationDefault(Validator $validator)
    {
        $validator
            ->add('id', 'valid', ['rule' => 'numeric'])
            ->allowEmpty('id', 'create');

        $validator
            ->add('email', 'valid', ['rule' => 'email'])
            ->notEmpty('email');

        $validator
            ->notEmpty('password');

        $validator
            ->allowEmpty('new_password');


        $validator
            ->allowEmpty('confirm_password');

        $validator
            ->add('new_password', 'custom', [
                'rule' => function ($value, $context) {
                    if (!array_key_exists('confirm_password', $context['data'])) {
                        return false;
                    }
                    if ($value !== $context['data']['confirm_password']) {
                        return false;
                    }
                    return true;
                },
                'message' => __d('CakeAdmin', 'Passwords are not equal.')]);

        $validator
            ->add('confirm_password', 'custom', ['rule' => function ($value, $context) {
                if (!array_key_exists('new_password', $context['data'])) {
                    return false;
                }
                if ($value !== $context['data']['new_password']) {
                    return false;
                }
                return true;
            },
                'message' => __d('CakeAdmin', 'Passwords are not equal.')]);

        return $validator;
    }
1333893
public function validationDefault(Validator $validator)
    {
        $validator
            ->add('id', 'valid', ['rule' => 'numeric'])
            ->allowEmpty('id', 'create');

        $validator
            ->add('email', 'valid', ['rule' => 'email'])
            ->allowEmpty('email');

        $validator
            ->allowEmpty('password');

        $validator
            ->add('active', 'valid', ['rule' => 'numeric'])
            ->allowEmpty('active');

        $validator
            ->allowEmpty('usercode');

        $validator
            ->allowEmpty('new_password');


        $validator
            ->allowEmpty('confirm_password');

        $validator
            ->add('new_password', 'custom', [
                'rule' => function ($value, $context) {
                    if ($value !== $context['data']['confirm_password']) {
                        return false;
                    }
                    return true;
                },
                'message' => __d('users', 'Passwords are not equal.'),
            ]);

        $validator
            ->add('confirm_password', 'custom', [
                'rule' => function ($value, $context) {
                    if ($value !== $context['data']['new_password']) {
                        return false;
                    }
                    return true;
                },
                'message' => __d('users', 'Passwords are not equal.'),
            ]);

        return $validator;
    }
1202754
public function validate(Validator $validator)
    {
        $handler = $this->get('metadata')->get('handler');
        if (class_exists($handler)) {
            $handler = new $handler();

            return $handler->validate($this, $validator);
        }
    }
1309413
function Validator(config) {
  
  // Instance properties
  this.rules = {};
  this.rulesCount = 0;
  this.messages = {};
  this.optional = [];
  this.filters = {};
  this.postFilters = {};
  this.postValidations = [];
  
  // Options
  this.config = protos.extend({
    cleanup: true
  }, config || {});
  
  // Set context
  Object.defineProperty(this, '__context', {
    value: {},
    writable: true,
    enumerable: false,
    configurable: false
  });

  // App property
  Object.defineProperty(this, 'app', {
    value: protos.app,
    writable: true,
    enumerable: false,
    configurable: false
  });
  
}
91560
public static function validator($validator = null)
    {
        if (func_num_args()) {
            static::$_validators[static::class] = $validator;
            return;
        }
        $self = static::class;
        if (isset(static::$_validators[$self])) {
            return static::$_validators[$self];
        }
        $class = static::$_classes['validator'];
        $validator = static::$_validators[$self] = new $class();
        static::_rules($validator);
        return $validator;
    }
721552
public function validationEnabled(Validator $validator) : Validator
    {
        $className = App::shortName(get_class($this), 'Model/Table', 'Table');
        $config = (new ModuleConfig(ConfigType::MIGRATION(), $className))->parse();
        $config = json_encode($config);
        if (false === $config) {
            return $validator;
        }
        $config = json_decode($config, true);
        $factory = new FieldHandlerFactory();

        foreach ($config as $column) {
            $validator = $factory->setValidationRules($this, $column['name'], $validator);
        }

        return $validator;
    }
27584
public function validationDefault(Validator $validator)
    {
        $validator
            ->integer('id')
            ->allowEmpty('id', 'create');

        $validator
            ->allowEmpty('uid', 'create');

        $validator
            ->requirePresence('username', 'create')
            ->notEmpty('username');

        $validator
            ->requirePresence('password', 'create')
            ->notEmpty('password');

        $validator
            ->requirePresence('role', 'create')
            ->notEmpty('role')
            ->add('role', 'inList', [
                'rule' => ['inList', ['admin', 'author']],
                'message' => 'Please enter a valid role'
            ]);

        $validator
            ->boolean('verified')
            ->requirePresence('verified', 'create')
            ->notEmpty('verified');

        $validator
            ->email('email')
            ->requirePresence('email', 'create')
            ->notEmpty('email');

        return $validator;
    }
954009
public function setValidator(Validator $validator) {
        $this->_validator = $validator;

        // Only set model events if we plan on validating
        $this->on('model', $this);

        return $this;
    }
953309
public function validationDefault(Validator $validator)
    {
        $validator
            ->requirePresence('name')
            ->notEmpty('name', __d('user', 'You must provide a name.'))
            ->requirePresence('username', 'create')
            ->add('username', [
                'characters' => [
                    'rule' => function ($value, $context) {
                        return preg_match('/^[a-zA-Z0-9\_]{3,}$/', $value) === 1;
                    },
                    'provider' => 'table',
                    'message' => __d('user', 'Invalid username. Only letters, numbers and "_" symbol, and at least three characters long.'),
                ],
            ])
            ->requirePresence('email')
            ->notEmpty('email', __d('user', 'e-mail cannot be empty.'))
            ->requirePresence('password', 'create')
            ->allowEmpty('password', 'update')
            ->add('password', [
                'compare' => [
                    'rule' => function ($value, $context) {
                        $value2 = isset($context['data']['password2']) ? $context['data']['password2'] : false;

                        return (new DefaultPasswordHasher)->check($value2, $value) || $value == $value2;
                    },
                    'message' => __d('user', 'Password mismatch.'),
                ]
            ])
            ->allowEmpty('web')
            ->add('web', 'validUrl', [
                'rule' => 'url',
                'message' => __d('user', 'Invalid URL.'),
            ]);

        return $this->_applyPasswordPolicies($validator);
    }
1232397
public function setOptionValidator(\JBBCode\InputValidator $validator, $option=null)
    {
        if (empty($option)) {
            $option = $this->tagName;
        }
        $this->optionValidator[$option] = $validator;
        return $this;
    }
104671
public function setValidationRules(Validator $validator, array $options = []) : Validator
    {
        $options = array_merge($this->defaultOptions, $this->fixOptions($options));

        $provider = $this->config->getProvider('validationRules');
        $validator = (new $provider($this->config))->provide($validator, $options);
        if (! $validator instanceof Validator) {
            throw new RuntimeException(
                sprintf('Provider returned value must be an instance of %s.', Validator::class)
            );
        }

        return $validator;
    }
1042024
protected function _buildValidator(Validator $validator)
    {
        $validator = new AppValidator;

        //First name
        $validator->requirePresence('first_name');

        //Last name
        $validator->requirePresence('last_name');

        //Email
        $validator->requirePresence('email');

        //Message
        $validator->add('message', [
            'lengthBetween' => [
                'message' => __d('me_cms', 'Must be between {0} and {1} chars', 10, 1000),
                'rule' => ['lengthBetween', 10, 1000],
            ],
        ])->requirePresence('message');

        return $validator;
    }
739770
protected function removeValidator(Validator $validator) : Component
    {
        $hash = spl_object_hash($validator);
        unset($this->validators[$hash]);

        return $this;
    }
693987
public function validationDefault(Validator $validator)
    {
        $validator
            ->add('id', 'valid', ['rule' => 'numeric'])
            ->allowEmpty('id', 'create');

        $validator
            ->requirePresence('upload_id', 'create')
            ->notEmpty('upload_id');

        $validator
            ->requirePresence('original_filename', 'create')
            ->notEmpty('original_filename');

        $validator
            ->requirePresence('unique_filename', 'create')
            ->notEmpty('unique_filename');

        $validator
            ->allowEmpty('subfolder');

        $validator
            ->allowEmpty('mimetype');

        $validator
            ->add('size', 'valid', ['rule' => 'numeric'])
            ->requirePresence('size', 'create')
            ->notEmpty('size');

        $validator
            ->requirePresence('hash', 'create')
            ->notEmpty('hash');

        $validator
            ->add('upload_complete', 'valid', ['rule' => 'boolean'])
            ->requirePresence('upload_complete', 'create')
            ->notEmpty('upload_complete');

        $validator
            ->allowEmpty('label');

        $validator
            ->add('created_by', 'valid', ['rule' => 'numeric'])
            ->requirePresence('created_by', 'create')
            ->notEmpty('created_by');

        $validator
            ->add('modified_by', 'valid', ['rule' => 'numeric'])
            ->allowEmpty('modified_by');

        return $validator;
    }