コード例 #1
1
ファイル: Argument.php プロジェクト: wouterrr/mangoutils
 public function assert(Acl $acl, $role = null, $resource = null, $privilege = null)
 {
     foreach ($this->_arguments as $role_key => $resource_key) {
         // normalize arguments & compare
         $allow_same = TRUE;
         if (strpos($role_key, '!') === 0) {
             $role_key = substr($role_key, 1);
             $allow_same = !$allow_same;
         }
         if (strpos($resource_key, '!') === 0) {
             $resource_key = substr($resource_key, 1);
             $allow_same = !$allow_same;
         }
         if (Mango::normalize($role->{$role_key}) === Mango::normalize($resource->{$resource_key})) {
             if (!$allow_same) {
                 // fields are the same, not allowed
                 return FALSE;
             }
         } else {
             if ($allow_same) {
                 // fields are different, not allowed
                 return FALSE;
             }
         }
     }
     return TRUE;
 }
コード例 #2
0
ファイル: arrayobject.php プロジェクト: memakeit/MangoDB
 /**
  * Find a path in array
  *
  * @param   string|array  delimiter notated keystring or array
  * @param   mixed         default value to return if key not found
  * @param   string        delimiter (defaults to dot '.')
  * @return  mixed         value (if found) or default value
  */
 public function path_get($path, $default = NULL, $delimiter = '.')
 {
     if (!is_array($path)) {
         $path = explode($delimiter, (string) $path);
     }
     $next = $this;
     while (count($path) && (is_array($next) || $next instanceof ArrayObject)) {
         $key = array_shift($path);
         $next = isset($next[$key]) ? $next[$key] : $default;
     }
     return !count($path) ? Mango::normalize($next) : $default;
 }
コード例 #3
0
ファイル: Mango.php プロジェクト: tscms/mangodb
 /**
  * Validates data. If no data supplied, uses current data in document. Checks embedded_documents as well.
  *
  * @throws  Validation_Exception  when an error is found
  * @param   subject  specify what part of $data should be subjected to validation, Mango::CHECK_FULL, Mango::CHECK_LOCAL, Mango::CHECK_ONLY
  * @param   array    data to check, defaults to current document data (including embedded documents)
  * @return  Mango    $this
  */
 public function check(array $data = NULL, $subject = 0)
 {
     if ($data !== NULL) {
         // create a new object with data, and validate
         Mango::factory($this->_model, $data)->check(NULL, $subject);
         return $this;
     }
     $local = array();
     foreach ($this->_fields as $field_name => $field_data) {
         if (!in_array($field_data['type'], array('has_one', 'has_many')) || $this->__isset($field_name)) {
             // Don't check if regular fields are set, to include default values
             // Do check if embedded objects are set, they don't have default values and we cannot instantiate extended models
             $local[$field_name] = Mango::normalize($this->__get($field_name));
         }
     }
     if ($subject !== Mango::CHECK_ONLY || count($local)) {
         // validate local data
         $array = Validation::factory($local)->bind(':model', $this);
         // add validation rules
         $array = $this->_check($array);
         if ($subject === Mango::CHECK_ONLY) {
             foreach ($this->_fields as $field_name => $field_data) {
                 if (!$this->__isset($field_name)) {
                     // do not validate this field
                     unset($array[$field_name]);
                 }
             }
         }
         if (!$array->check()) {
             throw new Mango_Validation_Exception($this->_model, $array);
         }
     }
     if ($subject !== Mango::CHECK_LOCAL) {
         // validate embedded documents
         foreach ($this->_fields as $field_name => $field_data) {
             if ($this->__isset($field_name) && in_array($field_data['type'], array('has_one', 'has_many'))) {
                 if ($field_data['type'] === 'has_one') {
                     $this->__get($field_name)->check(NULL, $subject);
                 } else {
                     foreach ($this->__get($field_name) as $seq => $hm) {
                         try {
                             $hm->check(NULL, $subject);
                         } catch (Mango_Validation_Exception $e) {
                             // add sequence number of failed object to exception
                             $e->seq = $seq;
                             throw $e;
                         }
                     }
                 }
             }
         }
     }
     return $this;
 }
コード例 #4
0
ファイル: core.php プロジェクト: Naatan/FuelPHP-MangoDB
 /**
  * Validates data. If no data supplied, uses current data in document. Checks embedded_documents as well.
  *
  * @throws  Validation_Exception  when an error is found
  * @param   subject  specify what part of $data should be subjected to validation, Mango::CHECK_FULL, Mango::CHECK_LOCAL, Mango::CHECK_ONLY
  * @param   array    data to check, defaults to current document data (including embedded documents)
  * @return  Mango    $this
  */
 public function check(array $data = NULL, $subject = 0)
 {
     if ($data !== NULL) {
         // create a new object with data, and validate
         Mango::factory($this->_model, $data)->check(NULL, $subject);
         return $this;
     }
     $local = array();
     foreach ($this->_fields as $field_name => $field_data) {
         if (!in_array($field_data['type'], array('has_one', 'has_many'))) {
             // by not checking if the field has been set, we also include default values (if any)
             $local[$field_name] = Mango::normalize($this->__get($field_name));
         }
     }
     if ($subject !== Mango::CHECK_ONLY || count($local)) {
         // validate local data
         $array = Kohana_Validation::factory($local)->bind(':model', $this);
         // add validation rules
         $array = $this->_check($array);
         if ($subject === Mango::CHECK_ONLY) {
             foreach ($this->_fields as $field_name => $field_data) {
                 if (!$this->__isset($field_name)) {
                     // do not validate this field
                     unset($array[$field_name]);
                 }
             }
         }
         //$validation = Validation::factory(get_class($this));
         //foreach ($this->_fields AS $field_name => $field_data) {
         //	if ( $subject === Mango::CHECK_ONLY && ! $this->__isset($field_name))
         //		continue;
         //
         //	$field = $validation->add($field_name);
         //
         //	if ( $field_data['type'] === 'email')
         //	{
         //		$field->add_rule('valid_email');
         //	}
         //
         //	if ( Arr::element($field_data,'required'))
         //	{
         //		$field->add_rule('required');
         //	}
         //
         //	if ( Arr::element($field_data,'unique'))
         //	{
         //		$field->add_rule($field_name, array($this,'_is_unique'),array(':validation', $name));
         //	}
         //
         //	foreach ( array('min_value','max_value','min_length','max_length') as $rule)
         //	{
         //		if ( Arr::element($field, $rule) !== NULL)
         //		{
         //			$data->rule($name, $rule, array(':value', $field[$rule]));
         //		}
         //	}
         //}
         if (!$array->check()) {
             throw new Mango_Validation_Exception($this->_model, $array);
         }
     }
     if ($subject !== Mango::CHECK_LOCAL) {
         // validate embedded documents
         foreach ($this->_fields as $field_name => $field_data) {
             if ($this->__isset($field_name) && in_array($field_data['type'], array('has_one', 'has_many'))) {
                 if ($field_data['type'] === 'has_one') {
                     $this->__get($field_name)->check(NULL, $subject);
                 } else {
                     foreach ($this->__get($field_name) as $seq => $hm) {
                         try {
                             $hm->check(NULL, $subject);
                         } catch (Mango_Validation_Exception $e) {
                             // add sequence number of failed object to exception
                             $e->seq = $seq;
                             throw $e;
                         }
                     }
                 }
             }
         }
     }
     return $this;
 }