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: use Deimos\Helper\Exceptions\ExceptionEmpty;
  6: 
  7: trait DefaultAdapter
  8: {
  9: 
 10:     /**
 11:      * @var \Deimos\Helper\Helper
 12:      */
 13:     protected $helper;
 14:     private   $input = 'php://input';
 15: 
 16:     /**
 17:      * @param string $type
 18:      *
 19:      * @return mixed
 20:      */
 21:     protected function inputArray($type)
 22:     {
 23:         return filter_input_array($type, FILTER_UNSAFE_RAW) ?: [];
 24:     }
 25: 
 26:     /**
 27:      * @return array
 28:      */
 29:     protected function getInput()
 30:     {
 31:         $contents = $this->getContents($this->input);
 32: 
 33:         return $this->parseStr($contents);
 34:     }
 35: 
 36:     /**
 37:      * @param string $data
 38:      *
 39:      * @return string
 40:      */
 41:     private function getContents($data)
 42:     {
 43:         return file_get_contents($data);
 44:     }
 45: 
 46:     /**
 47:      * @param string $data
 48:      *
 49:      * @return array
 50:      */
 51:     private function parseStr($data)
 52:     {
 53:         parse_str($data, $output);
 54: 
 55:         return $output;
 56:     }
 57: 
 58:     /**
 59:      * @param $string
 60:      *
 61:      * @return string
 62:      */
 63:     protected function normalizeUpp($string)
 64:     {
 65:         if(null === $string) {
 66: 
 67:             return null;
 68:         }
 69: 
 70:         return strtoupper($string);
 71:     }
 72: 
 73:     /**
 74:      * @param $string
 75:      *
 76:      * @return string
 77:      */
 78:     protected function normalizeLow($string)
 79:     {
 80:         if(null === $string) {
 81: 
 82:             return null;
 83:         }
 84: 
 85:         return strtolower($string);
 86:     }
 87: 
 88:     /**
 89:      * @param array  $storage
 90:      * @param string $path
 91:      * @param bool   $xss
 92:      *
 93:      * @return mixed
 94:      *
 95:      * @throws ExceptionEmpty
 96:      */
 97:     protected function arrRequired(array $storage, $path, $xss)
 98:     {
 99:         $data = $this->helper->arr()->getRequired($storage, $path);
100: 
101:         if ($xss)
102:         {
103:             $data = $this->xss($data);
104:         }
105: 
106:         return $data;
107:     }
108: 
109:     /**
110:      * @param $data
111:      *
112:      * @return mixed
113:      */
114:     protected function xss($data)
115:     {
116:         if (is_array($data))
117:         {
118:             return filter_var_array($data, FILTER_SANITIZE_STRING);
119:         }
120: 
121:         return filter_var($data, FILTER_SANITIZE_STRING);
122:     }
123: 
124:     /**
125:      * @param array  $storage
126:      * @param string $path
127:      * @param mixed  $default
128:      * @param bool   $xss
129:      *
130:      * @return mixed
131:      */
132:     protected function arrGetXss(array $storage, $path, $default, $xss)
133:     {
134:         $data = $this->arrGet($storage, $path, $default);
135: 
136:         if ($xss && !empty($data))
137:         {
138:             $data = $this->xss($data);
139:         }
140: 
141:         return $data;
142:     }
143: 
144:     /**
145:      * @param array  $storage
146:      * @param string $path
147:      * @param mixed  $default
148:      *
149:      * @return mixed
150:      */
151:     protected function arrGet(array $storage, $path, $default)
152:     {
153:         if ($path === null)
154:         {
155:             return $storage;
156:         }
157: 
158:         return $this->helper->arr()->get($storage, $path, $default);
159:     }
160: 
161:     /**
162:      * @param $data
163:      * @param $type
164:      * @param $default
165:      *
166:      * @return mixed
167:      */
168:     protected function filterVariable($data, $type, $default)
169:     {
170:         return filter_var($data, $type, array(
171:             'options' => array('default' => $default)
172:         ));
173:     }
174: 
175: }
API documentation generated by ApiGen