public static function parseNonPhtml(Response $response, $file) { if (!file_exists($file = file_exists($file = self::getPath() . $file) ? $file : (file_exists($file . '.html') ? $file . '.html' : (file_exists($file . '.xhtml') ? $file . '.xhtml' : (file_exists($file . '.php') ? $file . '.php' : $file))))) { if ($response->getStatusCode() == 200) { $response->setStatusCode(404); } $response->setContent($file = (string) new Phtml('/errors/' . $response->getStatusCode(), FALSE, 'default')); } else { if (strpos($file = realpath($file), realpath(Skin::getPath())) !== 0) { throw new \Exception('Unknown skin path: "' . $file . '".'); } $file = str_replace('sitemap.xml.php', 'sitemap.xml', $file); $repository = new PhpRepository(); $response->headers->set('Content-Type', $repository->findType(strtolower(substr(strrchr($file, '.'), 1)) ?: $file) ?: 'text/plain'); if (basename($file) == 'sitemap.xml') { $phtml = new Phtml(NULL); $file = $phtml->parsePhtml($file . '.php'); } else { $file = file_get_contents($file); } $response->setContent($file); } $response->headers->set('Cache-Control', 'max-age=604800'); $response->headers->set('Content-Length', strlen($file)); return $response; }
/** * Constructor * * @param OutputInterface $output Output * @param string $docroot Docroot * @param string $env Environment * @param bool $debug Debug * @param int $port Port */ public function __construct(OutputInterface $output, $docroot, $env, $debug, $port = null) { $repository = new PhpRepository(); if (!$port) { $port = 8000; } $this->output = $output; $this->env = $env; $this->debug = $debug; $this->port = $port; $this->loop = new StreamSelectLoop(); $socketServer = new ReactSocketServer($this->loop); $httpServer = new ReactHttpServer($socketServer); $httpServer->on("request", function ($request, $response) use($repository, $docroot, $output) { $path = $docroot . '/' . ltrim(rawurldecode($request->getPath()), '/'); if (is_dir($path)) { $path .= '/index.html'; } if (!file_exists($path)) { HttpServer::logRequest($output, 404, $request); $response->writeHead(404, ['Content-Type' => 'text/html']); return $response->end(implode('', ['<h1>404</h1>', '<h2>Not Found</h2>', '<p>', 'The embedded <a href="https://sculpin.io">Sculpin</a> web server could not find the requested resource.', '</p>'])); } $type = 'application/octet-stream'; if ('' !== ($extension = pathinfo($path, PATHINFO_EXTENSION))) { if ($guessedType = $repository->findType($extension)) { $type = $guessedType; } } HttpServer::logRequest($output, 200, $request); $response->writeHead(200, array("Content-Type" => $type)); $response->end(file_get_contents($path)); }); $socketServer->listen($port, '0.0.0.0'); }
/** * @param $file * @param $organization * @return Asset */ private function buildAsset($file, $organization, $type) { $ext = strtolower($file->getClientOriginalExtension()); $mime = $this->mimeDetect->findType($ext); $name = new Name($file->getClientOriginalName()); $guid = Guid::generate(); $asset = Asset::register($name, $guid, $mime, $organization); $asset->setTitle($name); if (isset($type)) { $asset->setType($type); } return $asset; }
private function getMimeTypeFile($path) { $mimetypeRepo = new PhpRepository(); return $mimetypeRepo->findType(pathinfo($path, PATHINFO_EXTENSION)) ?: $this->defatultMimeType; }
/** * findType - given a file extensions, return applicable mimetype * * @param string $extension file extension * * @return string|null applicable mimetype (string) or null if no match */ public static function findType($extension) { $mt = new PhpRepository(); return $mt->findType(strtolower($extension)); }
/** * Gets the Mime Type. * * @return string. Myme type. "application/octet-stream" by default. */ public function getMimeType() { $mimetypeRepo = new PhpRepository(); $path = $this->getPathFilename(); return $mimetypeRepo->findType(pathinfo($path, PATHINFO_EXTENSION)) ?: 'application/octet-stream'; }
/** * Return the mime type. * * @param $path * * @return mixed|null|string */ public function fileMimeType($path) { return $this->mimeDetect->findType(pathinfo($path, PATHINFO_EXTENSION)); }
/** * Get the mime type of a file. * * @param $path * * @return string */ public static function getMimetype($path) { $mimeDetect = new PhpRepository(); return $mimeDetect->findType(self::getExtension($path)); }
/** * @param string $filePath * * @return string */ public function getContentType($filePath) { $pathInfo = pathinfo($filePath); if (!isset($pathInfo['extension'])) { $extension = ''; } else { $extension = $pathInfo['extension']; } $repository = new PhpRepository(); $type = $repository->findType($extension); if ($type === null) { $type = 'text/plain'; } return $type; }