/**
  * @param \Cake\Network\Response $response The response.
  * @return \Cake\Network\Response
  */
 protected function build($response)
 {
     $cakeRequest = Request::createFromGlobals();
     $builder = new ViewBuilder();
     $templateName = $this->config('templateFileName');
     $templatePath = $this->config('templatePath');
     $view = $builder->className($this->config('className'))->templatePath(Inflector::camelize($templatePath))->layout($this->config('templateLayout'))->build([], $cakeRequest);
     $view->_ext = $this->config('templateExtension');
     $bodyString = $view->render($templateName);
     $response = $response->withHeader('Retry-After', (string) HOUR)->withHeader('Content-Type', $this->config('contentType'))->withStatus($this->config('statusCode'));
     $body = $response->getBody();
     $body->write($bodyString);
     return $response;
 }
Пример #2
0
 /**
  * testCreateFromArray()
  *
  * @return void
  */
 public function testCreateFromArray()
 {
     $builder = new ViewBuilder();
     $builder->template('default')->layout('test')->helpers(['Html'])->className('JsonView');
     $result = json_encode($builder);
     $builder = new ViewBuilder();
     $builder->createFromArray(json_decode($result, true));
     $this->assertEquals('default', $builder->template());
     $this->assertEquals('test', $builder->layout());
     $this->assertEquals(['Html'], $builder->helpers());
     $this->assertEquals('JsonView', $builder->className());
 }