get() public method

Gets a filter.
public get ( string $name, array $options = [] ) : Pagekit\Filter\FilterInterface
$name string
$options array
return Pagekit\Filter\FilterInterface The filter
コード例 #1
0
 /**
  * {@inheritdoc}
  */
 public function get($index)
 {
     if (!isset($this->params[$index])) {
         return null;
     }
     /**
      * @var string $name
      * @var string $type
      * @var array  $options
      */
     extract($this->params[$index]);
     foreach (['query', 'request'] as $bag) {
         $value = $this->request->{$bag}->get($name);
         if ($value !== null) {
             if ($type == 'array') {
                 $value = (array) $value;
             } elseif (strpos($type, '[]') !== false) {
                 $value = (array) $value;
                 $filter = $this->filterManager->get(str_replace('[]', '', $type), $options);
                 array_walk($value, function (&$val) use($filter, $name) {
                     if (is_array($val)) {
                         throw new \RuntimeException(sprintf("Query parameter cannot be a nested array.", $name));
                     }
                     $val = $filter->filter($val);
                 });
             } elseif ($type) {
                 $value = $this->filterManager->get($type, $options)->filter($value);
             }
             break;
         }
     }
     return $value;
 }