Example #1
0
 public static function valid($rules, $data)
 {
     static::$errors = [];
     Event::triggerOnce('core.check.init');
     self::$data = $data;
     foreach ($rules as $field_name => $rule) {
         $current = isset($data[$field_name]) ? $data[$field_name] : null;
         if (is_callable($rule)) {
             static::$errors[$field_name] = call_user_func($rule, $current);
             continue;
         } elseif (is_string($rule)) {
             $current_rules = array_flip(preg_split('/\\s*\\|\\s*/', $rule));
         } else {
             $current_rules = (array) $rule;
         }
         static::$errors[$field_name] = true;
         foreach ($current_rules as $method => $message) {
             $meth_name = strtok($method, ':');
             $meth_opts = array_merge([$current], json_decode('[' . strtok(':') . ']'));
             if (static::$errors[$field_name] !== true) {
                 continue 2;
             }
             static::$errors[$field_name] = true;
             if (isset(static::$methods[$meth_name])) {
                 static::$errors[$field_name] = call_user_func_array(static::$methods[$meth_name], $meth_opts);
             }
         }
     }
     self::$data = [];
     // Clean non-errors
     static::$errors = array_filter(static::$errors, function ($v) {
         return $v !== true;
     });
     return empty(static::$errors);
 }
Example #2
0
 public static function isValid($data, $rules)
 {
     $validation = Validator::make($data, $rules);
     if ($validation->passes()) {
         return true;
     }
     static::$errors = $validation->messages();
     return false;
 }
Example #3
0
 public function is_valid($data)
 {
     $validator = Validator::make($data, static::$rules);
     if ($validator->passes()) {
         return true;
     }
     static::$errors = $validator->messages();
     return FALSE;
 }
Example #4
0
 public function __construct()
 {
     if (!isset(static::$errors)) {
         if (Session::started() and Session::has('errors')) {
             static::$errors = Session::get('errors');
         } else {
             static::$errors = new Messages();
         }
     }
 }
Example #5
0
 public static function validate($data, $rules = NULL, $messages = array())
 {
     if (is_null($rules)) {
         $rules = static::$rules;
     }
     $validation = Validator::make($data, $rules, $messages);
     if ($validation->fails()) {
         static::$errors = $validation->messages()->all();
         return FALSE;
     }
     return TRUE;
 }
 public static function validate($formData)
 {
     $factory = new Factory(new Translator('en'));
     $v = $factory->make($formData, static::$rules, static::$messages);
     if ($v->fails()) {
         $errors = array();
         foreach ($v->messages()->all('<li>:message</li>') as $error) {
             $errors[] = $error;
         }
         static::$errors = implode("", $errors);
         return false;
     }
     return true;
 }
Example #7
0
 public static function valid($rules, $data)
 {
     static::$errors = [];
     static::triggerOnce('init');
     self::$data = $data = (array) $data;
     foreach ((array) $rules as $field_name => $rule) {
         $current = isset($data[$field_name]) ? $data[$field_name] : null;
         if (is_callable($rule)) {
             static::$errors[$field_name] = call_user_func($rule, $current);
             continue;
         } elseif (is_string($rule)) {
             $current_rules = array_flip(preg_split('/\\s*\\|\\s*/', $rule));
         } else {
             $current_rules = (array) $rule;
         }
         static::$errors[$field_name] = true;
         foreach ($current_rules as $method => $message) {
             $meth_name = strtok($method, ':');
             $opts = strtok(':') ?: '';
             $opts = $opts ? json_decode("[{$opts}]") : [];
             $meth_opts = $opts ? array_merge([$current], $opts) : [$current];
             if (static::$errors[$field_name] !== true) {
                 continue 2;
             }
             if (empty(static::$methods[$meth_name])) {
                 static::$errors[$field_name] = true;
             } else {
                 if (call_user_func_array(static::$methods[$meth_name]->validate, $meth_opts)) {
                     static::$errors[$field_name] = true;
                 } else {
                     $arg = [];
                     foreach ($meth_opts as $key => $value) {
                         $arg["arg_{$key}"] = $value;
                     }
                     static::$errors[$field_name] = Text::render(static::$methods[$meth_name]->message, $arg);
                 }
             }
         }
     }
     self::$data = [];
     // Clean non-errors
     static::$errors = array_filter(static::$errors, function ($v) {
         return $v !== true;
     });
     return empty(static::$errors);
 }
Example #8
0
 public static function process($value, $settings, $model)
 {
     $settings = static::settings($settings);
     $disallowed = \Arr::get($settings, 'disallowed_prefixes');
     static::$errors = array();
     $rules = "";
     /*$extraRules = $value['extrarules'];
       unset($value['extrarules']);*/
     if (empty($value)) {
         return '';
     }
     foreach ($value as $val) {
         if (!is_array($val)) {
             continue;
         }
         $action = @$val['action'] ?: 301;
         $rules .= implode(static::ARG_SEPARATOR, array('RewriteRule', $val['from'], $val['to'], "[R={$action},L]\r\n"));
         if (!($fromValid = static::isValidRewriteArgument($val['from']))) {
             static::$errors[] = "An error was found in the syntax of '{$val['from']}'";
         }
         if (!($toValid = static::isValidRewriteArgument($val['to']))) {
             static::$errors[] = "An error was found in the syntax of '{$val['to']}'";
         }
         if ($fromValid && is_array($disallowed)) {
             foreach ($disallowed as $disallow) {
                 if (static::matchesPrefix($disallow, $val['from'])) {
                     static::$errors[] = "Cannot add a rule that matches '{$disallow}'";
                     break;
                 }
             }
         }
     }
     // Only insert if all the syntax is valid
     if (!count(static::$errors)) {
         self::insertToHtaccess($rules);
     }
     return $rules;
 }
Example #9
0
 /**
  * Clean errors
  */
 protected static function cleanErrors()
 {
     static::$errors = array();
 }
Example #10
0
 /**
  * Respone json errors payload.
  *
  * @param int $status
  *
  * @return \Response
  */
 public function response($status = 400, array $headers = [], $options = 0)
 {
     $errors = static::$errors;
     static::$errors = [];
     return response()->json(['errors' => $errors], $status, $headers, $options);
 }
Example #11
0
 /**
  * Reset internal variables for another validation run.
  *
  * @return void
  */
 protected static function _reset()
 {
     static::$errors = array();
 }
Example #12
0
 public static function disable($module_slug)
 {
     $module = Module::make($module_slug);
     if (!$module->is_valid()) {
         static::$errors = $module->errors;
         return false;
     }
     $dependencies = $module->has_dependencies();
     if (empty($dependencies)) {
         $db_module = Model\Module::where('slug', '=', $module_slug)->first();
         if (isset($db_module) and !empty($db_module)) {
             $db_module->enabled = 0;
             $db_module->save();
             \Bundle::disable($module_slug);
             return true;
         } else {
             static::$errors->add('installer', 'Module [' . $module_slug . '] must be installed.');
             return false;
         }
     } else {
         foreach ($dependencies as $dependency_slug => $module) {
             static::$errors->add('installer', 'Module [' . $module_slug . '] cannot be disabled. Please disable ' . $dependency_slug . ' module first.');
         }
         return false;
     }
 }
 /**
  * Collect messages retrieved from file processors.
  *
  * @param $messages
  * @param bool $error
  */
 protected function addMessageResponse($messages, $error = false)
 {
     if (is_string($messages)) {
         $messages = [$messages];
     } elseif ($messages instanceof MessageProviderInterface) {
         $messages = $messages->getMessageBag()->getMessages();
     } else {
         return null;
         // We don't have anything to add in this case.
     }
     if ($error) {
         static::$errors = array_merge(static::$errors, $messages);
     } else {
         static::$messages = array_merge(static::$messages, $messages);
     }
 }
Example #14
0
 /**
  * @param $product_ids
  * @throws \Exception
  * @throws \SmartyException
  */
 protected static function endProducts(array $product_ids)
 {
     static::$count_success = 0;
     static::$count_fail = 0;
     static::$count_skip = 0;
     static::$errors = array();
     static::$error_counter = array();
     $product_ids = array_filter($product_ids);
     $templates = $groups = array();
     fn_set_progress('parts', count($product_ids));
     foreach ($product_ids as $product_id) {
         $product = new Product($product_id, array('external'));
         if (empty($product->external_id) || $product->statusIsClosed()) {
             if (empty($product->external_id)) {
                 static::setError('100_' . $product_id, __('ebay_product_not_exported', array('[product]' => $product->original_title)), true);
             } else {
                 static::setError('101_' . $product_id, __('ebay_product_already_sales_closed', array('[product]' => $product->original_title)), true);
             }
             fn_set_progress('echo', '.');
             static::$count_skip++;
             continue;
         }
         if (!isset($templates[$product->template_id])) {
             $templates[$product->template_id] = $product->getTemplate();
         }
         $groups[$product->template_id][] = $product;
         if (count($groups[$product->template_id]) >= static::MAX_COUNT_END_PRODUCTS) {
             static::endGroupProducts($templates[$product->template_id], $groups[$product->template_id]);
             unset($groups[$product->template_id]);
         }
     }
     if (!empty($groups)) {
         foreach ($groups as $template_id => $products) {
             static::endGroupProducts($templates[$template_id], $products);
         }
     }
     /** @var \Smarty $smarty */
     $smarty = Tygh::$app['view'];
     $smarty->assign('end_result', array('count_success' => static::$count_success, 'count_fail' => static::$count_fail, 'count_skip' => static::$count_skip, 'errors' => static::$errors, 'error_counter' => static::$error_counter, 'count_external_error' => static::$count_external_error));
     fn_set_notification('I', __('ebay_end_summary_title'), $smarty->fetch('addons/ebay/views/ebay/components/end_summary.tpl'));
 }
Example #15
0
 /**
  * Reset internal variables for another validation run.
  *
  * @return void
  */
 protected static function _reset()
 {
     static::$errors = [];
 }
Example #16
0
 /**
  * Closes a form
  *
  * @return string A form closing tag
  */
 public static function close()
 {
     $close = static::form()->close();
     // Destroy Form instance
     static::$form = null;
     // Reset all values
     static::$values = null;
     static::$errors = null;
     static::$rules = null;
     return $close;
 }
Example #17
0
 /**
  * clear validator errors
  */
 public function clear()
 {
     static::$errors = array();
 }
Example #18
0
 /**
  * Set the errors to use for validations
  *
  * @param Message $validator The result from a validation
  */
 public static function withErrors($validator)
 {
     // If we're given a raw Validator, go fetch the errors in it
     if ($validator instanceof Validator) {
         $validator = $validator->errors;
     }
     static::$errors = $validator;
 }