protected function respondWithArray(array $array, array $headers = []) { $mimeTypeRaw = Input::server('HTTP_ACCEPT', '*/*'); // If its empty or has */* then default to JSON if ($mimeTypeRaw === '*/*') { $mimeType = 'application/json'; } else { // You'll probably want to do something intelligent with charset if provided // This chapter just assumes UTF8 everything everywhere $mimeParts = (array) explode(',', $mimeTypeRaw); $mimeType = strtolower($mimeParts[0]); } switch ($mimeType) { case 'application/json': $contentType = 'application/json'; $content = json_encode($array); break; case 'application/x-yaml': $contentType = 'application/x-yaml'; $dumper = new YamlDumper(); $content = $dumper->dump($array, 2); break; default: $contentType = 'application/json'; $content = json_encode(['error' => ['code' => static::CODE_INVALID_MIME_TYPE, 'http_code' => 415, 'message' => sprintf('Content of type %s is not supported.', $mimeType)]]); } $response = Response::make($content, $this->statusCode, $headers); $response->header('Content-Type', $contentType); return $response; }
/** * Define the routes for the application. * * @param \Illuminate\Routing\Router $router * @return void */ public function map(Router $router) { #if (!$this->app->routesAreCached()) { // Handle legacy routes $router->get('blog/wp-content/uploads/{img_ref_path}', function ($img_ref_path) { return file_get_contents(img_path($img_ref_path)); }); $router->group(['namespace' => $this->namespace], function ($router) { if (in_array(Input::server('HTTP_HOST'), ['www.joejiko.com', 'local.joejiko.com'])) { require_once __DIR__ . '/../Http/routes.php'; } }); #} }