/** * Constructor. * * @param string $content Content. * @param int $status [optional] Response status code. Default: 404. * @param array $headers [optional] Headers array. */ public function __construct($content = '', $status = 404, $headers = array()) { if (!is_array($headers)) { throw new InvalidArgumentException('array', $headers, 3); } parent::__construct($content, $status, $headers); }
/** * Constructor. * * @param string $url URL to redirect to. * @param int $status [optional] Response status code. Default: 302. * @param array $headers [optional] Headers array. */ public function __construct($url = '', $status = 302, $headers = array()) { if (empty($url)) { throw new InvalidArgumentException('non-empty string', $url); } if (!is_array($headers)) { throw new InvalidArgumentException('array', $headers, 3); } parent::__construct('', $status, array('Location' => $url)); $this->url = $url; }
/** * Sends content for the current web response. * * @return JsonResponse */ public function sendContent() { $this->content = $this->getContent(); return parent::sendContent(); }
/** * Renders the final response and sends it back to the client. * * @param Response $response HTTP Response to be sent. * @param Request $request The original HTTP request for context. */ public function sendResponse(Response $response, Request $request) { // prepare the response for sending (will tweak some headers based on the request) $response->prepare($request); // trigger WillSendResponse event for any last minute changes $this->container->get('event_manager')->trigger(new WillSendResponse($response, $request)); $timer = $this->container->get('splot.timer'); $time = $timer->getDuration(); $memory = $timer->getCurrentMemoryPeak(); $memoryString = StringUtils::bytesToString($memory); $this->logger->debug('Rendering response for {method} {uri} took {time} ms and used {memory} memory.', array('method' => $request->getMethod(), 'uri' => $request->getRequestUri(), 'memory' => $memoryString, 'time' => $time, '@stat' => 'splot.render', '@time' => $time, '@memory' => $memory)); // and finally send out the response $response->send(); }
/** * @expectedException \MD\Foundation\Exceptions\InvalidArgumentException * @covers ::alterPart */ public function testInvalidAlterPart() { $response = new Response('Lorem ipsum dolor sit amet, adipiscit elit!'); $response->alterPart('', 'Lipsum'); }