Example #1
0
 /**
  * This method does the main work of the validation
  * @ Accepts three parameters
  * @ Param 1 = Array [REQUIRED]
  * @ Param 2 = String or Array [PARTIAL REQUIRED]
  *	-String 
  *		-format 1[ filter: login + username password ] ( NON GREEDY: Take from login the listed *after the + sign )
  *		-format 2[ filter: login - username password ] ( PARTIAL GREEDY: takes all rules at login *exclude username )
  *		-format 3[ filter: login] ( GREEDY FORMAT: takes all the rules at login )
  *	-Array
  *		-format[ Just the array of validation rules ]
  * @ Param 3 = Custom error message for validation rules parsed [ OPTIONAL ]
  * @ Return mix
  */
 public static function these($data, $type = '', $message = '')
 {
     $rules = array();
     static::$rules = static::$rules === FALSE ? Config::get('validaterule') : static::$rules;
     if (!empty($data)) {
         //Lets check the type of filter validation
         $house_filters = array();
         if (!empty($type) && is_string($type)) {
             $type = trim($type);
             $house_filters[] = $type;
         }
         $join_filters = array_merge(static::$filters, $house_filters);
         $rules = static::workfilter($join_filters);
         if (!empty($type) && is_array($type)) {
             if (!empty($rules)) {
                 $rules += $type;
             } else {
                 $rules = $type;
             }
         }
         //We have to reset the static rules property. VERY IMPORTANT LINE
         static::$rules = FALSE;
         return $message == '' ? Validator::make($data, $rules) : Validator::make($data, $rules, $message);
     }
 }
 public function __construct(array $attributes = [])
 {
     $this->attributes['status'] = true;
     static::$rules = array_add(static::$rules, 'name', 'required|max:255');
     static::$rules = array_add(static::$rules, 'price', 'required|numeric|min:0');
     parent::__construct($attributes);
 }
 public function __construct(array $attributes = [])
 {
     $this->attributes['status'] = true;
     static::$rules = array_add(static::$rules, 'first_name', 'required|max:100');
     static::$rules = array_add(static::$rules, 'phone', 'required|max:100');
     static::$rules = array_add(static::$rules, 'email', 'required|email|max:100');
     parent::__construct($attributes);
 }
Example #4
0
 /**
  * Prefixes any tables that need it
  */
 public function __construct(array $attributes = array())
 {
     parent::__construct($attributes);
     static::$dbprefix = \Config::get('empower::dbprefix');
     // Change any unique:table_name or exists:table_name to prefixed table names
     static::$rules = preg_replace(array('/exists:(?:' . static::$dbprefix . '|)/', '/unique:(?:' . static::$dbprefix . '|)/'), array('exists:' . static::$dbprefix, 'unique:' . static::$dbprefix), static::$rules);
     $this->table = static::$dbprefix . $this->table;
 }
Example #5
0
 /**
  * Resets the form model to its vanilla form. Mostly used for tests.
  */
 public static function reset()
 {
     static::$field_data = array();
     static::$rules = array();
     static::$messages = array();
     static::$validation = false;
     static::$loaded = null;
     static::$custom_validators_loaded = null;
 }
Example #6
0
 /**
  * Gets the table names
  */
 public static function _init()
 {
     static::$table = strtolower(Config::get('sentry.table.groups'));
     static::$join_table = strtolower(Config::get('sentry.table.users_groups'));
     $_db_instance = trim(Config::get('sentry.db_instance'));
     static::$rules = Config::get('sentry.permissions.rules');
     // db_instance check
     if (!empty($_db_instance)) {
         static::$db_instance = $_db_instance;
     }
 }
Example #7
0
 public function passes($rules = array())
 {
     if ($rules) {
         static::$rules = $rules;
     }
     $validation = \Validator::make($this->data, static::$rules);
     if ($validation->passes()) {
         return true;
     }
     $this->errors = $validation->messages();
     return false;
 }
Example #8
0
 /**
  * Clear the ACL rules altogether (no arg) or for a specific actor
  *
  * @param   string|NULL         $actor
  *
  * @return  void
  */
 public static function clear($actor = NULL)
 {
     if ($actor != NULL) {
         foreach (static::$actors as &$actor) {
             unset($actor);
         }
         unset(static::$rules->{$actor});
     } else {
         static::$actors = (object) array();
         static::$rules = (object) array();
     }
 }
Example #9
0
 public function __construct($start = null, $end = null, $tz = null)
 {
     // initialize all properties
     static::$start = null;
     static::$end = null;
     static::$from = null;
     static::$rules = [];
     static::$exceptions = [];
     static::$tz = 'UTC';
     // Check if the first parameter is an options array
     if (is_array($start)) {
         $options = $start;
     }
     if ($tz) {
         static::$tz = $tz;
     }
     static::$tz = !empty($options['timezone']) ? $options['timezone'] : static::$tz;
     // Setup the start date
     if (!empty($options["start"])) {
         $start = $options["start"];
     }
     // If the start date is not provided then assume today
     if (empty($start)) {
         $start = Carbon::now(static::$tz)->hour(0)->minute(0)->second(0);
     }
     if (!$start instanceof \Carbon\Carbon) {
         $start = Carbon::parse($start, static::$tz)->hour(0)->minute(0)->second(0);
     }
     static::$start = $start;
     // Setup the from date
     if (!empty($options["from"])) {
         $from = $options["from"];
         if (!$from instanceof \Carbon\Carbon) {
             $from = Carbon::parse($from, static::$tz)->hour(0)->minute(0)->second(0);
         }
         static::$from = $from;
     }
     // Setup the end date
     if (!empty($options["end"])) {
         $end = $options["end"];
     }
     if (!empty($end)) {
         $end = Carbon::parse($end, static::$tz)->hour(0)->minute(0)->second(0);
         static::$end = $end;
     }
     static::$rules = !empty($options['rules']) ? $options['rules'] : [];
     $exceptions = !empty($options['exceptions']) ? $options['exceptions'] : [];
     foreach ($exceptions as $exception) {
         $this->except($exception);
     }
 }
 public function __construct(array $attributes = [])
 {
     $this->attributes['status'] = true;
     static::$rules = array_add(static::$rules, 'name', 'required|max:100');
     // static::$rules = array_add(static::$rules, 'description', 'required|max:100');
     // static::$rules = array_add(static::$rules, 'phone', 'required|max:100');
     // static::$rules = array_add(static::$rules, 'email', 'required');
     // static::$rules = array_add(static::$rules, 'location', 'required');
     // static::$rules = array_add(static::$rules, 'website', 'required');
     // static::$rules = array_add(static::$rules, 'logo', 'required|mimes:jpeg,bmp,png,jpg');
     // static::$rules = array_add(static::$rules, 'background_image', 'required|mimes:jpeg,bmp,png,jpg');
     // static::$rules = array_add(static::$rules, 'start_at_hh', 'required');
     // static::$rules = array_add(static::$rules, 'end_at_hh', 'required');
     // static::$rules = array_add(static::$rules, 'days', 'required');
     // static::$rules = array_add(static::$rules, 'capacity_max', 'required');
     // static::$rules = array_add(static::$rules, 'extends_tables', '');
     parent::__construct($attributes);
 }
Example #11
0
 public function __construct($data = null, $level = null)
 {
     parent::__construct($data, $level);
     static::$rules = Config::get('core::validator.group');
 }
 /**
  * User to reset static rules to default values
  */
 public static function resetStatic()
 {
     static::$rules = ["email" => ["required", "email"], "password" => ["confirmed"]];
 }
Example #13
0
 /**
  * Set the rules for the validator.
  *
  * @param	array	Array of rules
  * @return	void
  */
 public function setRules(array $rules)
 {
     static::$rules = $rules;
 }
Example #14
0
 public function __construct($data = null, $level = null)
 {
     parent::__construct($data, $level);
     static::$rules = Config::get('usermanager::validator.user');
 }
Example #15
0
 /**
  * Returns the array of rules.
  * 
  * @return array
  */
 public function get()
 {
     $rules = static::$rules;
     static::$rules = array();
     return $rules;
 }
Example #16
0
 public static function open($action = null, $method = 'POST', $attributes = array(), $https = null, $rules = array())
 {
     static::$rules = $rules;
     return parent::open($action, $method, $attributes, $https);
 }
Example #17
0
 public static function mergeRules(array $rules)
 {
     $temp = static::$rules;
     static::$rules = array_merge((array) $temp, $rules);
 }
 public function __construct(array $rules = array())
 {
     if (count($rules)) {
         static::$rules = $rules;
     }
 }
Example #19
0
 /**
  * Returns the array of rules
  * 
  * @return array
  */
 public function get()
 {
     $rules = static::$rules;
     static::$rules = [];
     return $rules;
 }
Example #20
0
 protected static function generate_rules()
 {
     // set rules array
     static::$rules = array();
     static::$bundle_rules = array();
     // set source property
     if (Config::get('sentry::sentry.permissions.rules_source') == 'database') {
         static::$source = 'database';
         $db_rules_container = array();
         $db_rules = DB::table(Config::get('sentry::sentry.table.rules'))->get(array('rule'));
         // if there was a result - populate the rules
         if ($db_rules !== null) {
             foreach ($db_rules as &$db_rule) {
                 $db_rule = get_object_vars($db_rule);
                 $db_rules_container[] = $db_rule['rule'];
             }
             static::$rules = $db_rules_container;
         }
     } else {
         static::$source = 'file';
         // load global rules
         static::$rules = Config::get('sentry::sentry.permissions.rules');
     }
     // get permissions file config options
     $permission_file = Config::get('sentry::sentry.permissions.file');
     foreach (static::$rules as $rule) {
         static::$bundle_rules['sentry'][] = $rule;
     }
     // see if type is config
     if ($permission_file['type'] == 'config' or empty($permission_file['type']) or $permission_file['type'] == null) {
         foreach (Bundle::$bundles as $bundle => $values) {
             $bundle_rules = Config::get($bundle . '::permissions.rules');
             if (!empty($bundle_rules)) {
                 // add rules to the rules array if they don't exist already
                 foreach ($bundle_rules as $rule) {
                     if (!in_array($rule, static::$rules)) {
                         static::$rules[] = $rule;
                         static::$bundle_rules[$bundle][] = $rule;
                     }
                 }
             }
         }
     }
     // The type was not a config, need to find the set file and see if it exists.
     foreach (Bundle::$bundles as $bundle => $values) {
         // Set the path to the file according to the config
         $path = Bundle::path($bundle) . Config::get('sentry::sentry.permissions.file.path');
         $path = str_finish($path, '/');
         // get the file name
         $file = Config::get('sentry::sentry.permissions.file.name') . EXT;
         // if the file exists pull in rules if they are set
         if (file_exists($path . $file)) {
             $info = (require $path . $file);
             if (isset($info['rules'])) {
                 // add rules to the rules array if they don't exist already
                 foreach ($info['rules'] as $rule) {
                     if (!in_array($rule, static::$rules)) {
                         static::$rules[] = $rule;
                         static::$bundle_rules[$bundle][] = $rule;
                     }
                 }
             }
         }
     }
 }
Example #21
0
 /**
  * Reset current user roles, this is mean switch to be a "Guest".
  *
  * @return void
  */
 public static function reset()
 {
     static::$user_roles = array();
     static::$roles = array();
     static::$rules = array();
 }
Example #22
0
 public function __construct($data = null, $level = null)
 {
     parent::__construct($data, $level);
     static::$rules = Config::get('syntara::validator.permission');
 }
Example #23
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;
 }