public function testInputSetter() { $input = Input::create(); $input->set('foo.bar', 'baz'); $this->assertEquals('baz', $input->toArray()['foo']['bar']); $input->set('config.db.adapter', 'PDO'); $this->assertEquals('PDO', $input->toArray()['config']['db']['adapter']); }
public function parse($inputStr) { if (empty($inputStr)) { $dataArray = []; } else { $dataArray = json_decode($inputStr, true); $error = json_last_error(); if ($error != JSON_ERROR_NONE) { Exception\System\FunctionInvocation::create()->addFuncName('json_decode')->addFuncArgs([$inputStr, true])->_throw(); } } $this->data = Input::create('RESTfulData', $dataArray); }
/** * @return $this */ public static function createFromFile($filename) { $requestStr = FileHelper::create($filename)->getFileContent(); $request = static::createFromString($requestStr); if ($request->isPost()) { $postRawData = array(); foreach (explode('&', rawurldecode($request->getContent())) as $dataItem) { $keyValue = explode('=', $dataItem); $postRawData[$keyValue[0]] = $keyValue[1]; } $request->setPostInput(Input::createFromArray($postRawData)); } $cookieHeader = $request->getHeaders()->get('Cookie'); $cookies = $cookieHeader instanceof \Zend\Http\Header\Cookie ? $cookieHeader->getArrayCopy() : []; $request->setCookieInput(Input::createFromArray($cookies)); return $request; }