convertSlice

Convert a slice.

@access protected
@param  array  $values
@param  string $name
@return array
247
protected function convertSlice(array $values, $name)
    {
        $type = $this->projection->getFieldType($name);
        $converter = $this->hydration_plan->getConverterForField($name);

        return array_map(
            function ($val) use ($converter, $type) {
                return $converter->fromPg($val, $type, $this->session);
            },
            $values
        );
    }
968519
public function encode($value, $name)
    {
        if ($this->isDynamicArray($name)) {
            $length = count($value);
            $nestedName = $this->nestedName($name);
            $result = [];
            $result[] = IntegerFormatter::format($length);

            foreach ($value as $val) {
                $result[] = $this->encode($val, $nestedName);
            }
            return $result;
        } elseif ($this->isStaticArray($name)) {
            $length = $this->staticArrayLength($name);
            $nestedName = $this->nestedName($name);
            $result = [];

            foreach ($value as $val) {
                $result[] = $this->encode($val, $nestedName);
            }
            return $result;
        }
        return $this->inputFormat($value, $name);
    }
1067242
private static function getValues(array $values)
    {
        $bag = MutableBag::from($values);
        foreach ($bag as $k => $v) {
            /** @var Bag $v */
            if (is_array($v) && !is_callable($v)) {
                $bag[$k] = Bag::from($v)
                    ->call(function (array $a) {
                        return [Json::dump($a)];
                    })
                    ->join(' ')
                ;
            } elseif (is_string($v) || (is_object($v) && method_exists($v, '__toString'))) {
                $bag[$k] = (string) $v;
            } else {
                $bag->remove($k);
            }
        }

        return $bag->immutable();
    }
1134972
public function arrayToMultiselect(array $values)
    {
        // First clean the array
        foreach ($values as $k => $v) {
            if (empty($v)) {
                unset($values[$k]);
            }
        }

        // Encode
        $values = (empty($values) ? '^^' : encodeMultienumValue($values));

        // Then return the array
        return $values;
    }
38570
protected function convert(array $value)
    {
        $return = array();
        foreach ($value as $name => $elements) {
            if (is_array($elements)) {
                // We have a checkbox hit for a subform/fieldset,
                if (isset($elements['__all__'])) {
                    if ('0' == $elements['__all__']) {
                        // The whole subform/fieldset shall be disabled, so add it and continue.
                        $return[] = $name;
                        continue;
                    } else {
                        // We do not need the toggle all checkbox value anymore.
                        unset($elements['__all__']);
                    }
                }
                // recurse with the subform/fieldset element toggle checkboxes.
                $result = $this->convert($elements);

                if (count($result)) {
                    // Some elements on the subform shall be disabled, so add the result array.
                    $return[$name] = $result;
                }
                continue;
            }

            if ('0' == $elements) {
                // We have a disabled element, add it to the array.
                $return[] = $name;
            }
        }
        return $return;
    }
212592
public function filter(string $name, array $values): Route{
		$this->filters[$name] = $values;
		return $this;
	}
1044317
private function normaliseVariable(string $name, $value): array
    {
        [$name, $value] = $this->sanitiseVariableValue(
            ...$this->sanitiseVariableName(
                ...$this->splitStringIntoParts($name, $value)
            )
        );

        $value = $this->resolveNestedVariables($value);

        return [$name, $value];
    }
290694
public function stripVOID($Values)
    {
        if (!is_array($Values)) {
            return [];
        }
        $Result = [];
        foreach ($Values as $Value) {
            if ($Value != VOID) {
                $Result[] = $Value;
            }
        }
        return $Result;
    }
474756
public function bitRemove($name, $value)
  {
    return $this->set($name, $this->get($name, 0) & ~ $value);
  }
670755
public function _setArray($values, $name, $parse_commas = true)
    {
        if (is_string($values) && $parse_commas && strpos($values, ',')) {
            $values = explode(',', $values);
        }
        if (!is_array($values)) {
            $values = array($values);
        }
        if (!isset($this->args[$name])) {
            $this->args[$name] = array();
        }
        $this->args[$name] = array_merge($this->args[$name], $values);

        return $this;
    }
659972
private function prepareValues($value): array
    {
        if (!self::hasMultipleValues($this->name)) {
            $values = is_array($value) ? $value : [trim($value)];
        } elseif (!is_array($value)) {
            $values = explode(',', (string) $value);
        } else {
            $values = $value;
        }

        foreach (array_keys($values) as $key) {
            $values[$key] = trim($values[$key]);

            if ($values[$key] == '') {
                unset($values[$key]);
            }
        }

        return array_values(array_unique($values));
    }
186213
public function toKeyValue(array $values)
    {
        $result = [];

        foreach ($values as $key => $value) {
            if (is_array($value)) {
                $result[$key] = $this->toKeyValue($value);
            } elseif (is_object($value)) {
                $result[$key] = $this->toKeyValue((array) $value);
            } else {
                $result[$key] = $value;
            }
        }

        return $result;
    }
28862
protected function parseRow(array $values)
    {
        $output_values = [];

        foreach ($values as $name => $value) {
            $output_values[$name] =
                $this->convertField($name, $value) ;
        }

        return $output_values;
    }
413181
public static function convertPayjpObjectToArray($values)
    {
        $results = array();
        foreach ($values as $k => $v) {
            // FIXME: this is an encapsulation violation
            if ($k[0] == '_') {
                continue;
            }
            if ($v instanceof PayjpObject) {
                $results[$k] = $v->__toArray(true);
            } elseif (is_array($v)) {
                $results[$k] = self::convertPayjpObjectToArray($v);
            } else {
                $results[$k] = $v;
            }
        }
        return $results;
    }
696433
public function loadRelated($name, $values)
    {
        if (array_key_exists($name, $this->_relations)) {
            $relation = $this->_relations[$name];
        } else {
            $relation = $this->_relations[$name] = $this->getRelation($name, false);
        }

        if ($relation === null) {
            return false;
        }
        $class = $relation->modelClass;
        $multiple = $relation->multiple;
        $link = $relation->link;
        if (array_key_exists($name, $this->_originalRelations)) {
            $children = $this->_originalRelations[$name];
        } else {
            $this->_originalRelations[$name] = $children = $this->$name;
        }

        if ($multiple) {
            $newChildren = [];
            foreach ($values as $index => $item) {
                if (isset($children[$index])) {
                    if ($item instanceof $class) {
                        if ($item->isNewRecord || $item->oldPrimaryKey == $children[$index]->oldPrimaryKey) {
                            $item->oldAttributes = $children[$index]->oldAttributes;
                            unset($children[$index]);
                        }
                        $newChildren[$index] = $item;
                        if (isset($this->_relatedScenario[$name])) {
                            $newChildren[$index]->setScenario($this->_relatedScenario[$name]);
                        }
                    } else {
                        $newChildren[$index] = $children[$index];
                        if (isset($this->_relatedScenario[$name])) {
                            $newChildren[$index]->setScenario($this->_relatedScenario[$name]);
                        }
                        $newChildren[$index]->setAttributes($item);
                        unset($children[$index]);
                    }
                } elseif ($item instanceof $class) {
                    $newChildren[$index] = $item;
                    if (isset($this->_relatedScenario[$name])) {
                        $newChildren[$index]->setScenario($this->_relatedScenario[$name]);
                    }
                } else {
                    $newChildren[$index] = new $class();
                    if (isset($this->_relatedScenario[$name])) {
                        $children[$index]->setScenario($this->_relatedScenario[$name]);
                    }
                    $newChildren[$index]->setAttributes($item);
                }
                foreach ($link as $from => $to) {
                    $newChildren[$index]->$from = $this->$to;
                }
            }
            $this->_oldRelations[$name] = $children;
        } else {
            $item = $values;
            $newChildren = null;
            if (isset($children)) {
                if ($item instanceof $class) {
                    if ($item->isNewRecord || $item->oldPrimaryKey == $children->oldPrimaryKey) {
                        $item->oldAttributes = $children->oldAttributes;
                        $children = null;
                    }
                    $newChildren = $item;
                    if (isset($this->_relatedScenario[$name])) {
                        $newChildren->setScenario($this->_relatedScenario[$name]);
                    }
                } elseif (isset($item)) {
                    $newChildren = $children;
                    if (isset($this->_relatedScenario[$name])) {
                        $newChildren->setScenario($this->_relatedScenario[$name]);
                    }
                    $newChildren->setAttributes($item);
                    $children = null;
                }
            } elseif ($item instanceof $class) {
                $newChildren = $item;
                if (isset($this->_relatedScenario[$name])) {
                    $newChildren->setScenario($this->_relatedScenario[$name]);
                }
            } elseif (isset($item)) {
                $newChildren = new $class();
                if (isset($this->_relatedScenario[$name])) {
                    $newChildren->setScenario($this->_relatedScenario[$name]);
                }
                $newChildren->setAttributes($item);
            }
            if ($newChildren) {
                foreach ($link as $from => $to) {
                    $newChildren->$from = $this->$to;
                }
            }
            $this->_oldRelations[$name] = isset($children) ? [$children] : [];
        }
        $this->populateRelation($name, $newChildren);
        $this->_processRelations[$name] = true;
        return true;
    }
1153435
public static function array_change_value_case(array $values)
    {
        $newValues = [];

        foreach ($values as $key => $value) {
            $newValues[$key] = self::strtolower($value);
        }

        return $newValues;
    }
731501
public static function convertMaestranoObjectToArray($values)
  {
    $results = array();
    foreach ($values as $k => $v) {
      // FIXME: this is an encapsulation violation
      if ($k[0] == '_') {
        continue;
      }

      // Convert key to underscore
      $kReal = self::toUnderscore($k);

      if ($v instanceof Maestrano_Api_Object) {
        $results[$kReal] = $v->__toArray(true);
      } else if (is_array($v)) {
        $results[$kReal] = self::convertMaestranoObjectToArray($v);
      } else if ($v instanceOf DateTime) {
        $results[$kReal] = $v->format(Maestrano_Helper_DateTime::ISO8601);
      } else {
        $results[$kReal] = $v;
      }
    }
    return $results;
  }