Created
December 19, 2016 15:14
-
-
Save JanSuchanek/54bc86f76855bc873746d52147589d09 to your computer and use it in GitHub Desktop.
Run some app from terminal (Open Cart, Wp etc.)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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