示例#1
0
 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']);
 }
示例#2
0
 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);
 }
示例#3
0
 /**
  * @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;
 }