12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?php
- /**
- * Pimf
- *
- * @copyright Copyright (c) Gjero Krsteski (http://krsteski.de)
- * @license http://krsteski.de/new-bsd-license New BSD License
- */
- namespace Pimf;
- /**
- * @package Pimf
- * @author Gjero Krsteski <[email protected]>
- */
- class Param
- {
- /**
- * @var \ArrayObject|null
- */
- protected $data = null;
- /**
- * @param array $data
- */
- public function __construct(array $data = array())
- {
- $this->data = new \ArrayObject($data, \ArrayObject::STD_PROP_LIST + \ArrayObject::ARRAY_AS_PROPS);
- }
- /**
- * @return array
- */
- public function getAll()
- {
- return (array)$this->data->getArrayCopy();
- }
- /**
- * @param string $index
- * @param null|string $defaultValue
- * @param bool $filtered If you trust foreign input introduced to your PHP code - set to FALSE!
- *
- * @return string
- */
- public function get($index, $defaultValue = null, $filtered = true)
- {
- if ($this->data->offsetExists($index)) {
- if ($filtered === true) {
- // pretty high-level filtering here...
- return self::filter($this->data->offsetGet($index));
- }
- return $this->data->offsetGet($index);
- }
- return $defaultValue;
- }
- /**
- * Never ever (ever) trust foreign input introduced to your PHP code!
- *
- * @param array|string $rawData
- *
- * @return array|bool|string
- */
- public static function filter($rawData)
- {
- return is_array($rawData)
- ? array_map(
- function ($value) {
- return \Pimf\Util\String\Clean::xss($value);
- }, $rawData
- )
- : \Pimf\Util\String\Clean::xss($rawData);
- }
- }
|