/** * Updates resource using modified references * @param array $updates * @throws \InvalidArgumentException */ protected function save($updates) { $out = ''; if (qtil\ArrayUtil::isIterable($updates)) { foreach ($updates as $section => $values) { if (is_numeric($section)) { throw new \InvalidArgumentException(); } $this->array[$section] = $updates[$section]; } } if (qtil\ArrayUtil::isIterable($this->array)) { foreach ($this->array as $section => $values) { $out .= '[' . $section . ']' . PHP_EOL; foreach ($values as $key => $value) { $out .= $key . '=' . $value . PHP_EOL; } $out .= PHP_EOL; } } $stream = $this->getStream(); if (!$stream->isOpen()) { $stream->open(); } $stream->truncate(0); $writer = new qio\File\Writer($stream); $writer->write($out); $stream->close(); }
/** * modifies xpath to limit to elements which contain input * @throws \InvalidArgumentException */ function execute() { $query = $this->getQuery(); $args = $this->getArguments(); $numArgs = count($args); if ($numArgs == 2) { $name = $args[0]; $value = $args[1]; } else { throw new \InvalidArgumentException("XPath Contains must have 2 arguments"); } $valueFn = function ($value) { if ($value !== '.') { return "'{$value}'"; } else { return $value; } }; if (qtil\ArrayUtil::isIterable($value)) { $nvalue = []; foreach ($value as $v) { $nvalue[] = $valueFn($v); } $value = implode(',', $nvalue); } else { $value = $valueFn($value); } $query['xpath'] .= '[contains(' . $name . ',' . $value . ')]'; }
protected function searchResult($k, $v, $path, &$results, $cpaths, $depth, $clauses) { if (qtil\ArrayUtil::isIterable($v) && $k == $path) { if (count($cpaths) - 1 > $depth) { foreach ($v as $i) { $search = $this->recursiveSearch($i, $cpaths, $depth + 1); if (!isset($results[$k])) { $results[$k] = []; } $keys = array_keys($search); foreach ($keys as $k2) { if (!isset($results[$k][$k2])) { $results[$k][$k2] = []; } $results[$k][$k2] = array_merge($results[$k][$k2], [$search[$k2]]); } } } else { if (!empty($clauses)) { $results[$k] = $this->match($v, $clauses); } else { $results[$k] = $v; } } } elseif ($k == $path) { $results[$k] = $v; } }
function __construct() { $this->setFactory(new GenericFactory()); $this->setMapping(['section' => 'xral\\Tests\\Mock\\Section'], function ($input) { if (!qtil\ArrayUtil::isMulti($input) && qtil\ArrayUtil::isIterable($input)) { return 'section'; } }); }
/** * Default constructor for adapter * @param qtil\Collection|xral\Data\View|array $views */ public function __construct($views = null) { if ($views instanceof View) { $views = new qtil\Collection([$views]); } elseif (qtil\ArrayUtil::isIterable($views)) { $views = new qtil\Collection($views); } else { $views = new qtil\Collection(); } $this->views = $views; }
/** * Recursively searches array * @param array $array * @param callable $fn * @param array $args * @return array */ protected function recurse(array $array, callable $fn, array $args) { foreach ($array as $key => $value) { if (\qtil\ArrayUtil::isIterable($value)) { $array[$key] = $this->recurse($value, $fn, $args); } elseif (!$this->search($fn, array_merge([$value, $key], $args))) { unset($array[$key]); } } return $array; }
/** * Default mapping constructor * @param array $mapping * @param \Closure $namingCallback */ function __construct() { $args = func_get_args(); $data = []; if (func_num_args()) { foreach ($args as $a) { if (qtil\ArrayUtil::isIterable($a)) { $data = $a; } elseif (is_callable($a)) { $this->setNamingCallback($a); } } } parent::__construct($data); }
/** * Statement execution * @param callable $statement * @return \qinq\Query\Statement|\qinq\Collection|null */ protected function statement(qinq\Query\Statement $statement) { $result = null; $l = call_user_func_array($statement, func_get_args()); if ($l instanceof Statement) { $result = $l; } elseif (qtil\ArrayUtil::isIterable($l)) { if ($statement->getMutable() === false) { return new qinq\Collection($l); } else { $this->collection->from($l); } } elseif (!is_null($l)) { $result = $l; } return $result; }
/** * starts join * @return \qinq\Object\Query\Join */ public function execute() { $collection = $this->getCollection(); $fn = $this->getCallback(); $arr = $collection->toArray(); $args = $this->getArguments(); if (empty($fn) && count($args) === 1) { $this->group = [new qinq\Collection($arr), new qinq\Collection($args[0])]; } elseif (!empty($fn)) { $arr1 = array_filter($arr, $fn); $arr2 = array_diff($arr, $arr1); $this->group = [new qinq\Collection($arr), new qinq\Collection($arr2)]; } if (qtil\ArrayUtil::isIterable($this->group) && qtil\ArrayUtil::isMultiObject($this->group)) { return $this; } }
/** * Where statement * Modifies ypath to limit yml query results * @param string $attributeOperator */ function execute($attributeOperator = '|') { $query = $this->getQuery(); $args = $this->getArguments(); if (!empty($args)) { $name = ''; if (isset($args[0])) { $name = $args[0]; } $value = null; if (isset($args[1])) { $value = $args[1]; } $operator = 'or'; if (isset($args[2])) { $operator = trim($args[2]); } if (!qtil\ArrayUtil::isIterable($value)) { $value = [$value]; } $nvalue = ''; $c = 0; foreach ($value as $v) { if ($c > 0) { $nvalue .= ' ' . $operator . ' '; } $nvalue .= $name . '=' . '"' . $v . '"'; $c++; } $value = $nvalue; if (strpos($query['ypath'], '[') !== false) { $newPath = ' ' . $attributeOperator . ' ' . $name; } else { $newPath = ''; } if (!is_null($value)) { $newPath .= '[' . $value . ']'; } } if (isset($newPath)) { $query['ypath'] = $query['ypath'] . $newPath; } }
/** * Performs xpath limiter procedure * @param \SimpleXMLElement|array $input * @return mixed */ function execute($input) { $xpath = $this->xpath; if ($input instanceof \SimpleXMLElement && isset($input->{$xpath})) { return $input->{$xpath}; } if (is_object($input) && method_exists($input, 'xpath')) { $namespaces = $this->query->getNamespaces(); foreach ($namespaces as $prefix => $ns) { $input->registerXPathNamespace($prefix, $ns); } return $input->xpath($xpath); } elseif (qtil\ArrayUtil::isIterable($input)) { $results = []; foreach ($input as $i) { if (is_object($i) && method_exists($i, 'xpath')) { $results[] = $this->execute($i); } } return $results; } }
/** * Merges array into local array * @param array $data * @return Collection * @throws \InvalidArgumentException */ public function merge($data) { if (!ArrayUtil::isIterable($data)) { throw new \InvalidArgumentException(); } foreach ($data as $key => $val) { $this->insert($key, $val); } return $this; }