/** * Constructor * * @param array $config The available configuration options are the following. Further * options are inherited from the parent classes. * - `'ignorePath'` _string_ : Part of the base path to ignore. * - `'basePath'` _string_ : The base path. * - `'path'` _string_ : The url path. * - `'body'` _resource_: Body stream of message (defaults: php://input). * - `'data'` _array_ : Form data (defaults: `[]`). * - `'params'` _array_ : Custom routing params (defaults: `[]`). * - `'env'` _array_ : Environment variables (defaults: `[]`). * - `'locale'` _string_ : An optional locale string (defaults: `''`). * - `'classes'` _array_ : Classes dependencies. * - `'detectors'` _array_ : Request detector definition. */ public function __construct($config = []) { $defaults = ['body' => '', 'data' => [], 'params' => [], 'env' => [], 'locale' => null, 'classes' => ['environment' => 'Lead\\Env\\Env', 'auth' => 'Lead\\Net\\Http\\Auth'], 'detectors' => ['mobile' => ['http:user-agent' => ['iPhone', 'MIDP', 'AvantGo', 'BlackBerry', 'J2ME', 'Opera Mini', 'DoCoMo', 'NetFront', 'Nokia', 'PalmOS', 'PalmSource', 'portalmmm', 'Plucker', 'ReqwirelessWeb', 'iPod', 'SonyEricsson', 'Symbian', 'UP\\.Browser', 'Windows CE', 'Xiino', 'Android']], 'ajax' => ['http:x-requested-with' => 'XMLHttpRequest'], 'flash' => ['http:user-agent' => 'Shockwave Flash'], 'ssl' => ['http:ssl' => true], 'get' => ['http:method' => 'GET'], 'post' => ['http:method' => 'POST'], 'put' => ['http:method' => 'PUT'], 'patch' => ['http:method' => 'PATCH'], 'delete' => ['http:method' => 'DELETE'], 'head' => ['http:method' => 'HEAD'], 'options' => ['http:method' => 'OPTIONS']]]; $config = Set::merge($defaults, $config); if (!is_object($config['env'])) { $environment = $config['classes']['environment']; $config['env'] = new $environment($config['env']); } $config += $this->_defaults($config); $this->env = $config['env']; $this->_data = $config['data']; $this->_params = $config['params']; unset($config['data']); parent::__construct($config); $this->_detectors = $config['detectors']; $this->ignorePath($config['ignorePath']); $this->basePath($config['basePath']); $this->locale($config['locale']); if (isset($this->_data['_method'])) { $this->env['REQUEST_METHOD'] = strtoupper($this->_data['_method']); $this->method($this->env['REQUEST_METHOD']); unset($this->_data['_method']); } }