Overview

Namespaces

  • Deimos
    • Request
      • Adapter
  • PHP

Classes

  • Deimos\Request\Request

Interfaces

  • Throwable

Traits

  • Deimos\Request\Adapter\Data
  • Deimos\Request\Adapter\Other
  • Deimos\Request\Adapter\Query
  • Deimos\Request\Adapter\Request
  • Deimos\Request\Adapter\Router
  • Deimos\Request\Adapter\Server
  • Deimos\Request\AdapterExtension
  • Deimos\Request\DefaultAdapter
  • Deimos\Request\RequestExtension

Exceptions

  • BadFunctionCallException
  • Exception
  • InvalidArgumentException
  • LogicException
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
 1: <?php
 2: 
 3: namespace Deimos\Request;
 4: 
 5: trait AdapterExtension
 6: {
 7: 
 8:     use DefaultAdapter;
 9: 
10:     private $allowMethods = [
11:         'attribute' => true,
12:         'get'       => true,
13:         'query'     => true,
14:         'post'      => true,
15:         'data'      => true,
16:         'put'       => true,
17:         'patch'     => true,
18:         'delete'    => true,
19:     ];
20: 
21:     /**
22:      * @var array
23:      */
24:     private $filters = [
25:         'int'   => FILTER_VALIDATE_INT,
26:         'float' => FILTER_VALIDATE_FLOAT,
27:         'bool'  => FILTER_VALIDATE_BOOLEAN,
28:         'email' => FILTER_VALIDATE_EMAIL,
29:         'ip'    => FILTER_VALIDATE_IP,
30:         'url'   => FILTER_VALIDATE_URL,
31:     ];
32: 
33:     /**
34:      * @var array
35:      */
36:     private $defaults = [
37:         'int'   => 0,
38:         'float' => .0,
39:         'bool'  => false,
40:         'email' => '',
41:         'ip'    => '',
42:         'url'   => '',
43:     ];
44: 
45:     /**
46:      * @param $name
47:      * @param $arguments
48:      *
49:      * @return mixed
50:      *
51:      * @throws \BadFunctionCallException
52:      */
53:     public function __call($name, $arguments)
54:     {
55:         $parameters = preg_replace('~([A-Z])~', '_$1', $name, 1);
56: 
57:         $parameters = $this->normalizeLow($parameters);
58:         list ($call, $filter) = explode('_', $parameters);
59: 
60:         if (empty($this->allowMethods[$call]))
61:         {
62:             throw new \BadFunctionCallException('Not found' . $name);
63:         }
64: 
65:         if ($filter === 'unsafe')
66:         {
67:             $arguments[1] = isset($arguments[1]) ? $arguments[1] : null;
68:             $arguments[2] = false;
69: 
70:             return call_user_func_array([$this, $call], $arguments);
71:         }
72: 
73:         return $this->filterVariable(
74:             call_user_func_array([$this, $call], $arguments),
75:             $this->filters[$filter],
76:             $this->defaults[$filter]
77:         );
78:     }
79: 
80: }
API documentation generated by ApiGen