Skip to content

Instantly share code, notes, and snippets.

@zavodnoyapl1992
Last active August 29, 2015 13:56
Show Gist options
  • Save zavodnoyapl1992/8930836 to your computer and use it in GitHub Desktop.
Save zavodnoyapl1992/8930836 to your computer and use it in GitHub Desktop.
mini-app for visual test
<?php
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/config/constant.php';
function requireAllConfigFilesFrom($dir)
{
foreach (new DirectoryIterator($dir) as $fileInfo) {
if ($fileInfo->isDot()) {
continue;
}
if ($fileInfo->isDir()) {
requireAllConfigFilesFrom($fileInfo->getFileName());
} else if ($fileInfo->getFileName() != '.gitignore') {
require $fileInfo->getPath() . '/' . $fileInfo->getFileName();
}
}
}
if (getenv('APPLICATION_ENV') == 'production') {
requireAllConfigFilesFrom(__DIR__ . '/config/production/');
} else {
requireAllConfigFilesFrom(__DIR__ . '/config/development/');
}
$controllerName = 'IndexController';
$action = 'indexAction';
$requestUri = trim(current(explode('?', $_SERVER['REQUEST_URI'])), ' /');
$requestUriParam = explode('/', $requestUri);
if ($requestUriParam[0] == 'client') {
$fileTypeElement = explode('.', $requestUri);
$fileType = mb_strtolower($fileTypeElement[count($fileTypeElement) - 1]);
include_once __DIR__ . '/../' .$requestUri;
switch ($fileType) {
case 'css':
header('Content-type: text/css');
break;
case 'js':
header('Content-type: text/javascript');
break;
case 'jpg':
case 'png':
case 'gif':
case 'jpeg':
header('Content-type: image/' . $fileType);
break;
}
return;
}
if (!empty($requestUriParam[0])) {
$controllerName = implode('',array_map('ucfirst', explode('_',$requestUriParam[0]))) . 'Controller';
}
if (!empty($requestUriParam[1])) {
$action = implode('',array_map('ucfirst', explode('_',$requestUriParam[1]))) . 'Action';
}
if (!is_file(CONTROLLERS_PATH . $controllerName . '.php')) {
$controllerName = 'ErrorController';
$action = 'NotFoundAction';
}
$controller = '\Controller\\' . $controllerName;
$object = new $controller();
if (!method_exists($object, $action) && method_exists($object, 'indexAction')) {
$action = 'indexAction';
} elseif (!method_exists($object, $action)) {
$object = new Controller\ErrorController();
$action = 'NotFoundAction';
}
while (count($requestUriParam) < 5) {
$requestUriParam[] = '';
}
list(,,$param1, $param2, $param3) = $requestUriParam;
echo $object->$action($param1, $param2, $param3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment