Skip to content

Instantly share code, notes, and snippets.

@JanSuchanek
Created December 19, 2016 15:14
Show Gist options
  • Save JanSuchanek/54bc86f76855bc873746d52147589d09 to your computer and use it in GitHub Desktop.
Save JanSuchanek/54bc86f76855bc873746d52147589d09 to your computer and use it in GitHub Desktop.
Run some app from terminal (Open Cart, Wp etc.)
<?php
class ServerRequest
{
private $request;
public function __construct($server)
{
$this->request = $server;
}
public function getContentType()
{
$types = [
"js" => "application/javascript",
"css" => "text/css",
"png" => "image/png",
"jpg" => "image/jpg",
];
foreach($types as $key => $type)
{
if(strpos($this->request["REQUEST_URI"], ".".$key) !== false){
return $type;
}
}
}
public function getUri()
{
return $this->request["REQUEST_URI"];
}
}
$serverRequest = new ServerRequest($_SERVER);
if(!$contentType = $serverRequest->getContentType()){
$contentType = "text/html";
}
$uri = $serverRequest->getUri();
header('Content-Type: '.$contentType);
if($uri != "/" && is_file(__DIR__.$uri)){
$fileName = __DIR__.$uri;
} else {
$fileName = __DIR__."/index.php";
}
include_once($fileName);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment