/var/www/html/site/controllers/DefaultController.php
public static function ResolveSlug($req, $res, $extras = array()) {
$slug = $req->controller;
$record = \R::findOne('slugs','deleted = 0 and slug = ? limit 1', array($slug));
if (!isset($record->id)) {
//return $res->redirect('404');
http_response_code(404);
$language = $req->language;
$meta = array();
$meta = \Models\Meta::get('404',$language,false);
if (!isset($meta->id)) {
\Lib\I18n::setup($language);
$titulo = \Lib\I18n::get('pagina-nao-encontrada',"Página não encontrada");
$Meta2 = \Models\Meta::get('home',$req->language,true);
$meta->title = $titulo.' - '.$Meta2->title;
}
$extras['meta'] = $meta;
$defaultArgs = array(
'req' => $req,
'res' => $res
);
$args = $defaultArgs + $extras;
return $res->render('404/index.twig',$args);
}
$table = $record->table;
$modulo = \R::findOne('modulo', 'deleted = 0 and ativo = 1 and folder = ? limit 1', array($table));
if (!preg_match('/^(?<controller>.+)Controller\:\:(?<method>.+)Action$/', $modulo->site_controller, $matches)) {
//var_dump($modulo->site_controller);exit;
return $res->redirect('404');
/var/www/html/site/controllers/DefaultController.php
public static function ResolveSlug($req, $res, $extras = array()) {
$slug = $req->controller;
$record = \R::findOne('slugs','deleted = 0 and slug = ? limit 1', array($slug));
if (!isset($record->id)) {
//return $res->redirect('404');
http_response_code(404);
$language = $req->language;
$meta = array();
$meta = \Models\Meta::get('404',$language,false);
if (!isset($meta->id)) {
\Lib\I18n::setup($language);
$titulo = \Lib\I18n::get('pagina-nao-encontrada',"Página não encontrada");
$Meta2 = \Models\Meta::get('home',$req->language,true);
$meta->title = $titulo.' - '.$Meta2->title;
}
$extras['meta'] = $meta;
$defaultArgs = array(
'req' => $req,
'res' => $res
);
$args = $defaultArgs + $extras;
return $res->render('404/index.twig',$args);
}
$table = $record->table;
$modulo = \R::findOne('modulo', 'deleted = 0 and ativo = 1 and folder = ? limit 1', array($table));
if (!preg_match('/^(?<controller>.+)Controller\:\:(?<method>.+)Action$/', $modulo->site_controller, $matches)) {
//var_dump($modulo->site_controller);exit;
return $res->redirect('404');
/var/www/html/site/controllers/DefaultController.php
<?php
namespace Controller;
use Lib\Config;
use Lib\View;
class DefaultController {
public static function IndexAction($req,$res, $extraArgs = array()) {
$tpl = $req->controller.'/'.$req->method.'.twig';
$view_dir = dirname(__DIR__).'/views';
if (!file_exists($view_dir.'/'.$tpl)) {
$tpl = 'home/index.twig';
//$res->redirect('404');
return static::ResolveSlug($req, $res, $extraArgs);
}
$defaultArgs = array(
'req' => $req,
'res' => $res
);
$args = $defaultArgs + $extraArgs;
$res->render($tpl,$args);
}
public static function Pascal2KebabCase($input) {
//return strtolower(preg_replace('/(?<!^)[A-Z]/', '_$0', $input));
return strtolower(preg_replace('/(?<!^)[A-Z]/', '-$0', $input));
}
public static function ResolveSlug($req, $res, $extras = array()) {
$slug = $req->controller;
$record = \R::findOne('slugs','deleted = 0 and slug = ? limit 1', array($slug));
/var/www/html/lib/Router.php
if ($cacheTime !== 0 && !isset($req->get->noCache) && in_array($req->type, array('GET'))) {
//CacheManager::setup($cache['config']);
//$cache = phpFastCache();
$cache_key = sha1($req->base_url.$req->controller.'/'.$req->method.'/'.join('/',$req->params).'?'.http_build_query((array)$req->get));
if (\Lib\Cache::exists($cache_key)) {
$cached = \Lib\Cache::get($cache_key,function() {});
}
//$cached = $cache->get($cache_key);
}
if (!$cached) {
$res->header('X-Cache','miss');
Hooks::call('before-action',array(&$req,&$res));
call_user_func_array(array($classname,$method), array($req,&$res));
Hooks::call('after-action',array(&$req,&$res));
if ($cacheTime !== 0 && !isset($req->get->noCache) && in_array($req->type, array('GET'))) {
\Lib\Cache::set($cache_key, $res->export());
/*
$res->on('background',function($cache,$cache_key,$res,$cacheTime){
$cache->set($cache_key,$res->export(),$cacheTime);
},array($cache,$cache_key,$res,$cacheTime));
*/
}
} else {
$res->import($cached);
$res->header('X-Cache','hit');
}
}
$req->end_time = microtime(true);
/var/www/html/lib/Router.php
if ($cacheTime !== 0 && !isset($req->get->noCache) && in_array($req->type, array('GET'))) {
//CacheManager::setup($cache['config']);
//$cache = phpFastCache();
$cache_key = sha1($req->base_url.$req->controller.'/'.$req->method.'/'.join('/',$req->params).'?'.http_build_query((array)$req->get));
if (\Lib\Cache::exists($cache_key)) {
$cached = \Lib\Cache::get($cache_key,function() {});
}
//$cached = $cache->get($cache_key);
}
if (!$cached) {
$res->header('X-Cache','miss');
Hooks::call('before-action',array(&$req,&$res));
call_user_func_array(array($classname,$method), array($req,&$res));
Hooks::call('after-action',array(&$req,&$res));
if ($cacheTime !== 0 && !isset($req->get->noCache) && in_array($req->type, array('GET'))) {
\Lib\Cache::set($cache_key, $res->export());
/*
$res->on('background',function($cache,$cache_key,$res,$cacheTime){
$cache->set($cache_key,$res->export(),$cacheTime);
},array($cache,$cache_key,$res,$cacheTime));
*/
}
} else {
$res->import($cached);
$res->header('X-Cache','hit');
}
}
$req->end_time = microtime(true);
/var/www/html/index.php
$regex = '#^http[s]?:\/\/(www\.)?(' . join("|", $hosts) . ')(\/' . preg_quote($request_uri) . ')?(\/)?(index\.php)?(\/)?#';
//trigger_error($regex);
$de = preg_replace('#^http[s]?:\/\/(www\.)?(' . join("|", $hosts) . ')(\/' . preg_quote($request_uri) . ')?(\/)?(index\.php)?(\/)?#', '', $de);
$para = preg_replace('#^http[s]?:\/\/(www\.)?(' . join("|", $hosts) . ')?(\/)?(index\.php)?(\/)?#', '', $para);
if ($request_uri == $de) {
$base_url = \Lib\Request::getBaseUrl();
$url = $base_url . $para;
//Header( “HTTP/1.1 301 Moved Permanently” );
header("Location: {$url}");
exit;
}
}
}
Router::init();