mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-06-19 17:51:26 +00:00
67 lines
1.6 KiB
PHP
67 lines
1.6 KiB
PHP
<?php
|
|
namespace Pecee\Http\Input;
|
|
|
|
class InputCollection implements \IteratorAggregate {
|
|
|
|
protected $data = array();
|
|
|
|
/**
|
|
* Search for input element matching index.
|
|
* Useful for searching for finding items where $index doesn't contain form name.
|
|
*
|
|
* @param string $index
|
|
* @return mixed
|
|
*/
|
|
public function findFirst($index) {
|
|
if(count($this->data)) {
|
|
|
|
if(isset($this->data[$index])) {
|
|
return $this->data[$index];
|
|
}
|
|
|
|
foreach($this->data as $key => $value) {
|
|
if(strtolower($index) === strtolower($key)) {
|
|
return $value;
|
|
}
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* @param $index
|
|
* @throws \InvalidArgumentException
|
|
* @return InputItem
|
|
*/
|
|
public function __get($index) {
|
|
$item = $this->findFirst($index);
|
|
// Ensure that item are always available
|
|
if($item === null) {
|
|
$this->data[$index] = new InputItem($index, null);
|
|
return $this->data[$index];
|
|
}
|
|
|
|
return $item;
|
|
}
|
|
|
|
public function __set($index, $value) {
|
|
$this->data[$index] = $value;
|
|
}
|
|
|
|
public function getData() {
|
|
return $this->data;
|
|
}
|
|
|
|
/**
|
|
* Retrieve an external iterator
|
|
* @link http://php.net/manual/en/iteratoraggregate.getiterator.php
|
|
* @return \Traversable An instance of an object implementing <b>Iterator</b> or
|
|
* <b>Traversable</b>
|
|
* @since 5.0.0
|
|
*/
|
|
public function getIterator() {
|
|
return new \ArrayIterator($this->data);
|
|
}
|
|
|
|
} |