Beispiel #1
0
 function startRule()
 {
     return Rule::any(Rule::arrays(['REQUEST' => Rule::arrays(['path' => Rule::regexp('/^' . preg_quote($this->path, '/') . '($|\\/)/ui')->required()])]), Rule::arrays(['REQUEST' => Rule::arrays(['method' => Rule::eq('GET')->required(), 'confirm' => Rule::string()->required(), 'path' => Rule::regexp('/^' . preg_quote($this->path, '/') . '($|\\/)/ui')->required()])]));
 }
Beispiel #2
0
 function startRule()
 {
     return parent::startRule()->mix(Rule::arrays(['REQUEST' => Rule::arrays(['object' => Rule::any([Rule::entity(['is', '/vendor/boolive/basic/user/title']), Rule::entity(['is', '/vendor/boolive/basic/user/email']), Rule::entity(['is', '/vendor/boolive/basic/user/password'])])])]));
 }
Beispiel #3
0
 /**
  * Правило проверки по умолчанию
  * Правило используется если в аргументах методов не указывается правило
  * @param null $name Ключ элемента, для которого требуется правило. Если не указан, то возвращается общее правило
  * @return \boolive\core\values\Rule
  */
 function getRule($name = null)
 {
     // Если правила нет по умолчанию, то пробуем его установить
     if (!isset($this->_rule)) {
         $this->defineRule();
     }
     // Правило на элемент
     if (isset($name)) {
         if ($this->_rule instanceof Rule) {
             // Если правило на массив
             if (isset($this->_rule->arrays)) {
                 // Нормализация аргументов
                 $args = [[], null, false];
                 foreach ($this->_rule->arrays as $arg) {
                     if (is_array($arg)) {
                         $args[0] = $arg;
                     } else {
                         if ($arg instanceof Rule) {
                             $args[1] = $arg;
                         } else {
                             if (is_bool($arg)) {
                                 $args[2] = $arg;
                             }
                         }
                     }
                 }
                 $value = $this->getValue();
                 // Если элемент массив и правило рекурсивно, то отдаём всё правило
                 if (isset($value[$name]) && is_array($value[$name]) && $args[2]) {
                     return $this->_rule;
                 }
                 // Выбор правила для элемента
                 if (is_array($args[0]) && isset($args[0][$name])) {
                     // Правило на элемент
                     return $args[0][$name];
                 }
                 // Если правило рекурсивно и есть общее на все элементы, то создаётся два варианта правила
                 if ($args[1] instanceof Rule && $args[2]) {
                     return Rule::any($args[1], $this->_rule);
                 }
                 // Правило по умолчанию, если есть
                 return $args[1] instanceof Rule ? $args[1] : null;
             }
         }
         return null;
     }
     return $this->_rule;
 }
Beispiel #4
0
 /**
  * Правило на атрибуты
  * @return Rule
  */
 protected function rule()
 {
     return Rule::arrays(['name' => Rule::string()->regexp('|^[^/@:#\\\\]*$|')->min(IS_INSTALL ? 1 : 0)->max(100)->required(), 'parent' => Rule::any(Rule::uri(), Rule::null()), 'proto' => Rule::any(Rule::uri(), Rule::null()), 'author' => Rule::any(Rule::uri(), Rule::null()), 'order' => Rule::int()->max(Entity::MAX_ORDER), 'created' => Rule::int(), 'updated' => Rule::int(), 'value' => Rule::string()->max(65535), 'is_draft' => Rule::bool(), 'is_hidden' => Rule::bool(), 'is_mandatory' => Rule::bool(), 'is_property' => Rule::bool(), 'is_relative' => Rule::bool(), 'is_link' => Rule::bool(), 'is_default_value' => Rule::bool(), 'is_default_file' => Rule::bool(), 'is_default_logic' => Rule::bool(), 'file' => Rule::any([Rule::null(), Rule::string()->regexp('/[^\\/\\\\]+/ui'), Rule::arrays(['tmp_name' => Rule::string(), 'name' => Rule::lowercase()->ospatterns('*.*')->ignore('lowercase')->required(), 'size' => Rule::int(), 'error' => Rule::int()->eq(0, true), 'type' => Rule::string()])])]);
 }