[TASK] PSR-2

This commit is contained in:
Kanti 2014-12-17 11:31:43 +01:00
commit 5f6bf63760
2 changed files with 327 additions and 327 deletions

View file

@ -18,7 +18,7 @@ function site_url()
error(500, '[site.url] is not set'); error(500, '[site.url] is not set');
// Forcing the forward slash // Forcing the forward slash
return rtrim(config('site.url'),'/').'/'; return rtrim(config('site.url'), '/') . '/';
} }
function site_path() function site_path()
@ -29,7 +29,7 @@ function site_path()
error(500, '[site.url] is not set'); error(500, '[site.url] is not set');
if (!$_path) if (!$_path)
$_path = rtrim(parse_url(config('site.url'), PHP_URL_PATH),'/'); $_path = rtrim(parse_url(config('site.url'), PHP_URL_PATH), '/');
return $_path; return $_path;
} }
@ -158,7 +158,7 @@ function warn($name = null, $message = null)
return count(array_keys($warnings)); return count(array_keys($warnings));
if (!$message) if (!$message)
return isset($warnings[$name]) ? $warnings[$name] : null ; return isset($warnings[$name]) ? $warnings[$name] : null;
$warnings[$name] = $message; $warnings[$name] = $message;
} }
@ -178,10 +178,10 @@ function from($source, $name)
if (is_array($name)) { if (is_array($name)) {
$data = array(); $data = array();
foreach ($name as $k) foreach ($name as $k)
$data[$k] = isset($source[$k]) ? $source[$k] : null ; $data[$k] = isset($source[$k]) ? $source[$k] : null;
return $data; return $data;
} }
return isset($source[$name]) ? $source[$name] : null ; return isset($source[$name]) ? $source[$name] : null;
} }
function stash($name, $value = null) function stash($name, $value = null)
@ -251,7 +251,7 @@ function redirect(/* $code_or_path, $path_or_cond, $cond */)
if (!$cond) if (!$cond)
return; return;
header('Location: '.$path, true, $code); header('Location: ' . $path, true, $code);
exit; exit;
} }
@ -265,7 +265,7 @@ function partial($view, $locals = null)
error(500, "[views.root] is not set"); error(500, "[views.root] is not set");
$path = basename($view); $path = basename($view);
$view = preg_replace('/'.$path.'$/', "_{$path}", $view); $view = preg_replace('/' . $path . '$/', "_{$path}", $view);
$view = "{$view_root}/{$view}.html.php"; $view = "{$view_root}/{$view}.html.php";
if (file_exists($view)) { if (file_exists($view)) {
@ -287,11 +287,11 @@ function content($value = null)
function render($view, $locals = null, $layout = null) function render($view, $locals = null, $layout = null)
{ {
$login = login(); $login = login();
if(!$login) { if (!$login) {
$c = str_replace('/', '#', str_replace('?', '~', $_SERVER['REQUEST_URI'])); $c = str_replace('/', '#', str_replace('?', '~', $_SERVER['REQUEST_URI']));
$dir = 'cache/page'; $dir = 'cache/page';
$cachefile = $dir. '/' . $c . '.cache'; $cachefile = $dir . '/' . $c . '.cache';
if(is_dir($dir) === false) { if (is_dir($dir) === false) {
mkdir($dir, 0777, true); mkdir($dir, 0777, true);
} }
} }
@ -321,7 +321,7 @@ function render($view, $locals = null, $layout = null)
ob_start(); ob_start();
require $layout; require $layout;
if(!$login) { if (!$login) {
if (!file_exists($cachefile)) { if (!file_exists($cachefile)) {
file_put_contents($cachefile, ob_get_contents()); file_put_contents($cachefile, ob_get_contents());
} }
@ -362,7 +362,7 @@ function condition()
if (is_callable($cb_map[$name])) if (is_callable($cb_map[$name]))
return call_user_func_array($cb_map[$name], $argv); return call_user_func_array($cb_map[$name], $argv);
error(500, 'condition ['.$name.'] is undefined'); error(500, 'condition [' . $name . '] is undefined');
} }
function middleware($cb_or_path = null) function middleware($cb_or_path = null)
@ -403,9 +403,9 @@ function route_to_regex($route)
{ {
$route = preg_replace_callback('@:[\w]+@i', function ($matches) { $route = preg_replace_callback('@:[\w]+@i', function ($matches) {
$token = str_replace(':', '', $matches[0]); $token = str_replace(':', '', $matches[0]);
return '(?P<'.$token.'>[a-z0-9_\0-\.]+)'; return '(?P<' . $token . '>[a-z0-9_\0-\.]+)';
}, $route); }, $route);
return '@^'.rtrim($route, '/').'$@i'; return '@^' . rtrim($route, '/') . '$@i';
} }
function route($method, $pattern, $callback = null) function route($method, $pattern, $callback = null)
@ -520,7 +520,7 @@ function dispatch()
$path = urldecode($_SERVER['REQUEST_URI']); $path = urldecode($_SERVER['REQUEST_URI']);
if (config('site.url') !== null) if (config('site.url') !== null)
$path = preg_replace('@^'.preg_quote(site_path()).'@', '', $path); $path = preg_replace('@^' . preg_quote(site_path()) . '@', '', $path);
$parts = preg_split('/\?/', $path, -1, PREG_SPLIT_NO_EMPTY); $parts = preg_split('/\?/', $path, -1, PREG_SPLIT_NO_EMPTY);

View file

@ -2,20 +2,22 @@
$updater = new Kanti\HubUpdater("danpros/htmly"); $updater = new Kanti\HubUpdater("danpros/htmly");
$info = $updater->getCurrentInfo(); $info = $updater->getCurrentInfo();
$versionNumber = substr($info['tag_name'],1); $versionNumber = substr($info['tag_name'], 1);
function isGraterThan($string){ function isGraterThan($string)
{
global $versionNumber; global $versionNumber;
return (version_compare($versionNumber,$string) > 0); return (version_compare($versionNumber, $string) > 0);
} }
// http://stackoverflow.com/questions/3338123/how-do-i-recursively-delete-a-directory-and-its-entire-contents-files-sub-dir // http://stackoverflow.com/questions/3338123/how-do-i-recursively-delete-a-directory-and-its-entire-contents-files-sub-dir
function rrmdir($dir) { function rrmdir($dir)
{
if (is_dir($dir)) { if (is_dir($dir)) {
$objects = scandir($dir); $objects = scandir($dir);
foreach ($objects as $object) { foreach ($objects as $object) {
if ($object != "." && $object != "..") { if ($object != "." && $object != "..") {
if (filetype($dir."/".$object) == "dir") rrmdir($dir."/".$object); else unlink($dir."/".$object); if (filetype($dir . "/" . $object) == "dir") rrmdir($dir . "/" . $object); else unlink($dir . "/" . $object);
} }
} }
reset($objects); reset($objects);
@ -24,13 +26,11 @@ function rrmdir($dir) {
} }
//run upgrade specific stuff //run upgrade specific stuff
if(isGraterThan("2.3")) {// 2.4, 2.5, ... if (isGraterThan("2.3")) {// 2.4, 2.5, ...
if(file_exists("vendor/")){ if (file_exists("vendor/")) {
rrmdir("vendor/"); rrmdir("vendor/");
} }
} }
if(isGraterThan("2.3")) { file_put_contents("index.php", file_get_contents("system/upgrade/index.php"));
file_put_contents("index.php",file_get_contents("system/upgrade/index.php")); rrmdir("system/upgrade/");
rrmdir("system/upgrade/");
}