/** * @see \Fine47\MicroRouter\Responses\Http::serveImpl() */ protected function serveImpl() { // Create a temporary file to hold the output buffer. $tempPath = System::tempFile(); try { // Save output buffer as JSON. Assert::that(['condition' => false !== file_put_contents($tempPath, Json::encode($this->getBody())), 'message' => 'Unable to serve the response body', 'type' => Error::TYPE_RUNTIME, 'magic' => 0xeb73]); // Close the file handle and outputs its contents. Assert::that(['condition' => false !== readfile($tempPath, false), 'message' => 'Unable to serve the response body', 'type' => Error::TYPE_RUNTIME, 'magic' => 0xeb74]); } finally { // Deletes temporary file. @unlink($tempPath); } // Once the body is served, it cannot be re-served again. $this->shutdown(); }
/** * Retrieves the flash data as an encoded string. If there's no data in flash, * FALSE is returned. * * @return string|FALSE encoded flash data, FALSE if empty */ public function toString() { if (empty($this->newFlash)) { // No flash data. return false; } // Return encoded flash data. return Base64::encode(Json::encode($this->newFlash)); }
/** * @see \Fine47\MicroRouter\Responses\Http::serveImpl() */ protected function serveImpl() { echo Json::encode($this->body); }