/** * * @param <type> $table * @param ArrayIterator $params * @return ArrayObject */ public function search($table, ArrayIterator $params) { $this->searchParams = $params; $this->join(); if ($table == "analysis") { $this->statements->remove("type_event"); } $statement = "SELECT this_.* " . $this->selectAttributes() . " FROM {$table} this_ "; $statement .= $this->join(); $i = 0; $this->searchParams->rewind(); if ($this->searchParams->count() > 0 && !$this->searchParams->offsetExists('true')) { $statement .= " WHERE "; } while ($this->searchParams->valid()) { if ($this->statements->containsKey($this->searchParams->key())) { if ($i++ > 0) { $statement .= " AND "; } $clause = $this->statements->get($this->searchParams->key()); $statement .= str_replace(":" . $this->searchParams->key(), "'" . $this->searchParams->current() . "'", $clause['where']); } $this->searchParams->next(); } return $this->getObject($statement . " ORDER BY this_.date DESC, this_.id DESC"); }
/** * @coversNothing */ public function test_constructor_iterator_immutability() { $value = new \ArrayIterator([1, 2, 3, 4, 5]); $value->next(); $prevKey = $value->key(); new testSubject($value); self::assertSame($prevKey, $value->key()); }
public function addToQuote() { $iterator = new \ArrayIterator($this->_data['fixture']['addresses']); while ($iterator->valid()) { if ($iterator->key() == 'billing_and_shipping') { $this->_setBillingAndShipping(); } else { $this->_setBillingOrShipping($iterator->key()); } $iterator->next(); } }
/** * {@inheritdoc} */ public function seek($offset) { $newIterator = new \ArrayIterator($this->baseArray); while ($newIterator->key() != $offset && $newIterator->valid()) { $newIterator->next(); } if (!$newIterator->valid()) { throw new BadOffsetException("OffsetProvider is not valid", 550); } if ($newIterator->key() != $offset) { throw new \Exception("Something went wrong", 550); } $this->arrayIterator = $newIterator; }
/** * Return the pathname for the current resource. * * @return string The path to the temporary resource or null if no resource exists. */ public function key() { if (!$this->valid()) { return null; } return $this->iterator->key(); }
public function processStatesItr(ArrayIterator $statesItr) { // ArrayIterator for ($statesItr; $statesItr->valid(); $statesItr->next()) { echo $statesItr->key() . ' : ' . $statesItr->current() . PHP_EOL; } }
/** * Update = $sql = "UPDATE tabla SET campo1 = ?, campo2 = ?, campo3 = ? * WHERE idcampo = ?" * $stm->bindValue(4, idValor); */ public function update($table, $data, $where, $id) { $result = null; $iterator = new ArrayIterator($data); $sql = "UPDATE {$table} SET "; while ($iterator->valid()) { $sql .= $iterator->key() . " = ?, "; $iterator->next(); } //Se elimina los dos ultimos caracteres (la coma y el espacio) $sql = substr($sql, 0, -2); $sql .= " WHERE {$where} = ?"; $stm = $this->_getDbh()->prepare($sql); $i = 1; foreach ($iterator as $param) { $stm->bindValue($i, $param); $i++; } /** * Se asigna el bindValue para el parametro $id, como no esta contemplado en los ciclos del $data, * se asigna en la posicion ($iterator->count()+1) y se le asigna el tipo de dato: PDO::PARAM_INT */ $stm->bindValue($iterator->count() + 1, $id, PDO::PARAM_INT); $result = $stm->execute(); return $result; }
/** * è‡ªåŠ¨åŠ è½½ * * @param $className */ function zroneClassLoader($className) { $path = array(str_replace("\\", "/", dirname(__FILE__) . DIRECTORY_SEPARATOR . "Vendor/"), str_replace("\\", "/", dirname(__FILE__) . DIRECTORY_SEPARATOR . "FrameWork/"), str_replace("\\", "/", dirname(__FILE__) . DIRECTORY_SEPARATOR . "Application/")); if (isset($path) && is_array($path)) { $Iterator = new ArrayIterator($path); $Iterator->rewind(); $pathString = ""; while ($Iterator->valid()) { $pathString .= $Iterator->current() . ";"; if ($Iterator->key() == count($path) - 1) { $pathString = rtrim($pathString, ";"); } $Iterator->next(); } set_include_path($pathString); spl_autoload_extensions(".php, .class.php"); spl_autoload($className); } else { try { throw new Exception("<code style='color: red; font-size: 22px; display: block; text-align: center; height: 40px; line-height: 40px;'>I'm sorry, my dear! The FrameWork is Wrong……😫</code>"); } catch (Exception $e) { echo $e->getMessage(); } } }
/** * @param \ArrayIterator $map */ public function __construct(\ArrayIterator $map) { $this->map = $map; parent::__construct($this->map, function ($element) use($map) { return array($map->key(), $element); }); }
/** * *@param $id_ciu * * **/ public function getById($id_jefe) { $this->conex = DataBase::getInstance(); //Consulta SQL $consulta = "SELECT * FROM FISC_JEFE_OFICINA WHERE \n\t\t\t\t\t\tID_JEFE=:id_jefe"; $stid = oci_parse($this->conex, $consulta); if (!$stid) { $e = oci_error($this->conex); trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR); } // Realizar la lógica de la consulta oci_bind_by_name($stid, ':id_jefe', $id_jefe); $r = oci_execute($stid); if (!$r) { $e = oci_error($stid); trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR); } $result = array(); // Obtener los resultados de la consulta while ($fila = oci_fetch_array($stid, OCI_ASSOC + OCI_RETURN_NULLS)) { $it = new ArrayIterator($fila); $alm = new Denuncia(); while ($it->valid()) { $alm->__SET(strtolower($it->key()), $it->current()); $it->next(); } $result[] = $alm; } //Libera los recursos oci_free_statement($stid); // Cierra la conexión Oracle oci_close($this->conex); //retorna el resultado de la consulta return $result; }
/** * Returns the identifier of the current cache entry pointed to by the cache * entry iterator. * * @return string * @api */ public function key() { if ($this->cacheEntriesIterator === null) { $this->rewind(); } return $this->cacheEntriesIterator->key(); }
/** * iterate the complete data collection and execute callback for each key => value pair passing the key * and the value to the callback function/method as first and second parameter. the callback must be * a valid callable that can be executed call_user_func_array * * @error 16307 * @param callable $callback expects the callback function/method * @return void */ public function each(callable $callback) { while ($this->iterator->valid()) { call_user_func_array($callback, array($this->iterator->key(), $this->iterator->current())); $this->iterator->next(); } }
public function getById($id) { $this->conex = DataBase::getInstance(); $stid = oci_parse($this->conex, "SELECT *\n\t\t\tFROM FISC_CIUDADANO WHERE ID_CIUDADANO=:id"); if (!$stid) { $e = oci_error($this->conex); trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR); } // Realizar la lógica de la consulta oci_bind_by_name($stid, ':id', $id); $r = oci_execute($stid); if (!$r) { $e = oci_error($stid); trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR); } // Obtener los resultados de la consulta $alm = new FiscCiudadano(); while ($fila = oci_fetch_array($stid, OCI_ASSOC + OCI_RETURN_NULLS)) { $it = new ArrayIterator($fila); while ($it->valid()) { $alm->__SET(strtolower($it->key()), $it->current()); $it->next(); } } //Libera los recursos oci_free_statement($stid); // Cierra la conexión Oracle oci_close($this->conex); //retorna el resultado de la consulta return $alm; }
/** * *@param $id_ciu * * **/ public function queryByIC($id_ciu) { $this->conex = DataBase::getInstance(); $stid = oci_parse($this->conex, "SELECT * FROM TBL_REPRESENTANTEEMPRESAS WHERE CLV_REPRESENTANTE=:id_ciu"); if (!$stid) { $e = oci_error($this->conex); trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR); } // Realizar la lógica de la consulta oci_bind_by_name($stid, ':id_ciu', $id_ciu); $r = oci_execute($stid); if (!$r) { $e = oci_error($stid); trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR); } $result = new RepresentanteEmpresa(); // Obtener los resultados de la consulta while ($fila = oci_fetch_array($stid, OCI_ASSOC + OCI_RETURN_NULLS)) { $it = new ArrayIterator($fila); while ($it->valid()) { $result->__SET(strtolower($it->key()), $it->current()); $it->next(); } } //Libera los recursos oci_free_statement($stid); // Cierra la conexión Oracle oci_close($this->conex); //retorna el resultado de la consulta return $result; }
/** * Gets item by it`s position * @param integer $position * @return mixed */ private function getByPosition($position) { $key = $this->_list->key(); $this->_list->seek($position); $item = $this->_list->current(); $this->_list->seek($key); return $item; }
public function test_iterator_immutability() { $test = new \ArrayIterator([1, 2, 3, 4, 5]); $test->next(); $prevKey = $test->key(); P\map(P\I, $test); $this->assertTrue($prevKey === $test->key(), 'The function must not alter the state of an iterator.'); }
public function testRewindRestartsIteratorToBeginning() { $iterator = new ArrayIterator(array('foo' => 'bar', 'oof' => 'rab')); $iterator->next(); $iterator->rewind(); $this->assertSame('foo', $iterator->key()); $this->assertSame('bar', $iterator->current()); }
/** * @param $offset * @param $value */ public function unshift($offset, \Barberry\PostedFile $value) { $currentKey = $this->key(); $this->specsIterator = new \ArrayIterator(array_merge(array($offset => $value), array_diff_key($this->specsIterator->getArrayCopy(), array($offset => false)))); while ($this->specsIterator->key() !== $currentKey) { $this->specsIterator->next(); } }
function omg() { $itr = new ArrayIterator($vals); $itr->seek($random); $city = $itr->current(); $country = $itr->key(); echo $country; return $city; }
function test($a) { $it = new ArrayIterator($a); while ($it->valid()) { var_dump($it->key()); var_dump($it->current()); $it->next(); } }
function dump($data, $depth = 0) { if (is_array($data)) { print_line('[', $depth); foreach ($data as $key => $value) { if (!is_int($key)) { print_line("{$key} =>", $depth + 1); } dump($value, $depth + 2); } print_line(']', $depth); return; } if (is_object($data)) { if (method_exists($data, '__toString')) { $class = get_class($data); print_line("[{$class}] {$data}", $depth); return; } $class = get_class($data); print_line("[{$class}] {", $depth); if ($data instanceof \IteratorAggregate) { $iterator = $data->getIterator(); } elseif ($data instanceof \Iterator) { $iterator = $data; } else { $iterator = new \ArrayIterator((array) $data); } for ($iterator->rewind(); $iterator->valid(); $iterator->next()) { if (!is_int($iterator->key())) { dump($iterator->key(), $depth + 1); } dump($iterator->current(), $depth + 2); } print_line('}', $depth); return; } if (is_string($data)) { print_line('"' . $data . '"', $depth); return; } print_line($data, $depth); }
/** * Exibe uma div normal do html, mas adiciona uma variavel de template "var" * e fecha a tag: * * Ex.: << div class="blue" var=$text >> * * Result: <div class="blue">Text Value</div> * * @param $params * @param $smarty * @return string */ function smarty_function_label($params, &$smarty) { $str = "<label "; $ai = new ArrayIterator($params); while ($ai->valid()) { $exibir = true; foreach (Samus::getLangs() as $lang) { if ($ai->key() == $lang || $ai->key() == "var") { $exibir = false; break; } } if ($exibir) { $str .= $ai->key() . "='" . str_replace("'", '"', $ai->current()) . "' "; } $ai->next(); } $str .= ">" . $params["var"] . $params[$_SESSION["lang"]] . "</label>"; return $str; }
function current() { $curfile = parent::current(); $curfile['attribs']['name'] = parent::key(); if ($base = self::$_parent->getBaseInstallDir($curfile['attribs']['name'])) { $curfile['attribs']['baseinstalldir'] = $base; } if (isset($curfile['attribs']['md5sum'])) { unset($curfile['attribs']['md5sum']); } return $curfile; }
/** * Iterate and output properties and attriibutes * @todo return a string instead of outputting directly * @todo use XSLT from XML output to decorate */ public function toHtml() { $iterator = new \ArrayIterator((array) $this); echo "<br/>"; while ($iterator->valid()) { $value = $iterator->current(); $key = $iterator->key(); echo \MIMAS\Service\Jorum\Formatters\Html::get($key, $value); $iterator->next(); } echo "<br/>"; }
protected function assertIteratesThrough($values, $iterator) { $valuesIterator = new ArrayIterator($values); $valuesIterator->rewind(); foreach ($iterator as $key => $row) { $this->assertTrue($valuesIterator->valid()); $this->assertEquals($valuesIterator->key(), $key); $this->assertEquals($valuesIterator->current(), $row); $valuesIterator->next(); } $this->assertFalse($valuesIterator->valid()); }
function testIteration() { $array = [0, 2, 4, 8]; $iterator = new ArrayIterator($array); $i = 0; $iterator->rewind(); while ($i < count($array)) { $this->assertTrue($iterator->valid()); $this->assertEquals($i, $iterator->key()); $this->assertEquals($array[$i], $iterator->current()); $iterator->next(); $i++; } }
/** * Data Hydrate * @param array $data * @return void */ protected function _hydrate(array $data = [], $separator = 'set') { $it = new \ArrayIterator($data); while ($it->valid()) { $key = $it->key(); $value = $it->current(); $method = $separator . ucfirst($key); if (method_exists($this, $method)) { $this->{$method}($value); } else { $this->{$key} = $value; } $it->next(); } }
/** * @param ArrayIterator $iterator * @param ArrayObject $collector * @param $prefix * @param $prefixedCategoryData * @param $prefixedPriceData */ protected function _advancedIndexCallback(ArrayIterator $iterator, ArrayObject $collector, $prefix, $prefixedCategoryData, $prefixedPriceData) { while ($iterator->valid()) { $productId = $iterator->key(); $productData = $iterator->current(); if (isset($prefixedCategoryData[$productId]) && isset($prefixedPriceData[$productId])) { $categoryData = Mage::helper('elasticsearch')->pregGrepReplaceArrayKeys("/{$prefix}/", '', $prefixedCategoryData[$productId]); $priceData = Mage::helper('elasticsearch')->pregGrepReplaceArrayKeys("/{$prefix}/", '', $prefixedPriceData[$productId]); $productData += $categoryData; $productData += $priceData; } else { $productData += array('categories' => array(), 'show_in_categories' => array(), 'visibility' => 0); } $collector[$productId] = $productData; $iterator->next(); } }
protected function assertIteratesThrough($values, $iterator) { $valuesIterator = new ArrayIterator($values); $valuesIterator->rewind(); foreach ($iterator as $key => $row) { foreach ($row as &$value) { if ($value instanceof DateTime) { $value = $value->format('Y-m-d H:i'); } } $this->assertTrue($valuesIterator->valid()); $this->assertEquals($valuesIterator->key(), $key); $this->assertEquals($valuesIterator->current(), $row); $valuesIterator->next(); } $this->assertFalse($valuesIterator->valid()); }
/** * Factory ItemCollection (Cria coleção de itens) * @param array $data Items * @return ItemCollection * @throws \InvalidArgumentException */ public static function factory(array $data = []) { $collectionItems = []; $itr = new \ArrayIterator($data); while ($itr->valid()) { $item = $itr->current(); if ($item instanceof ItemInterface) { $collectionItems[] = $item; } elseif (is_array($item)) { $collectionItems[] = new Item($item); } else { $exptMsg = sprintf('Invalid item on key: %s', $itr->key()); throw new \InvalidArgumentException($exptMsg); } $itr->next(); } return new self($collectionItems); }