Ejemplo n.º 1
0
 /**
  * Method to bind data to the form for the group level.
  *
  * @param   string  $group  The dot-separated form group path on which to bind the data.
  * @param   mixed   $data   An array or object of data to bind to the form for the group level.
  * @return  void
  */
 protected function bindLevel($group, $data)
 {
     // Ensure the input data is an array.
     settype($data, 'array');
     // Process the input data.
     foreach ($data as $k => $v) {
         if ($this->findField($k, $group)) {
             // If the field exists set the value.
             $this->data->set($group . '.' . $k, $v);
         } elseif (is_object($v) || Arr::isAssociative($v)) {
             // If the value is an object or an associative array, hand it off to the recursive bind level method
             $this->bindLevel($group . '.' . $k, $v);
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Method to recursively bind data to a parent object.
  *
  * @param   object   $parent     The parent object on which to attach the data values.
  * @param   mixed    $data       An array or object of data to bind to the parent object.
  * @param   boolean  $recursive  True to support recursive bindData.
  * @param   boolean  $allowNull  True to allow null values.
  * @return  void
  */
 protected function bind($parent, $data, $recursive = true, $allowNull = true)
 {
     // Ensure the input data is an array.
     $data = is_object($data) ? get_object_vars($data) : (array) $data;
     foreach ($data as $k => $v) {
         if (!$allowNull && !($v !== null && $v !== '')) {
             continue;
         }
         if ($recursive && (is_array($v) && Arr::isAssociative($v) || is_object($v))) {
             if (!isset($parent->{$k})) {
                 $parent->{$k} = new stdClass();
             }
             $this->bind($parent->{$k}, $v);
             continue;
         }
         $parent->{$k} = $v;
     }
 }