diff --git a/app/common/controller/home.php b/app/common/controller/home.php new file mode 100644 index 0000000..b18887a --- /dev/null +++ b/app/common/controller/home.php @@ -0,0 +1,33 @@ +document->setTitle("Hello World! %s"); + + $this->load->model('common/teste'); + + var_dump(get_class_methods($this->model_common_teste)); + + var_dump($this->model_common_teste->oi()); + + $this->load->helper('common/Data'); + + $help = new TestOfHelp; + + var_dump($help->helpme()); + + $this->data['variable'] = "Hello World!"; + + $this->out(); + } +} \ No newline at end of file diff --git a/app/common/helper/Data.php b/app/common/helper/Data.php new file mode 100644 index 0000000..92e54d1 --- /dev/null +++ b/app/common/helper/Data.php @@ -0,0 +1,13 @@ +file = DIR_APP_MODULAR . str_replace('../', '', $pathNew) . 'controller/' . str_replace('../', '', $part) . '.php'; + + $this->class = 'Controller' . preg_replace('/[^a-zA-Z0-9]/', '', $path); + + array_shift($parts); + + break; + } elseif (is_file(DIR_APPLICATION . 'controller/' . str_replace('../', '', $path) . '.php')) { $this->file = DIR_APPLICATION . 'controller/' . str_replace('../', '', $path) . '.php'; $this->class = 'Controller' . preg_replace('/[^a-zA-Z0-9]/', '', $path); @@ -43,6 +67,7 @@ final class Action { } else { $this->method = 'index'; } + } public function getFile() { diff --git a/system/engine/autoload.php b/system/engine/autoload.php index 2deed63..2b456ca 100644 --- a/system/engine/autoload.php +++ b/system/engine/autoload.php @@ -1,13 +1,51 @@ DIR_CACHE."twig/", 'debug' => (defined('DEBUG')) ? DEBUG : false ); - $TwigLoaderFilesystem = constant('TwigLoaderFilesystem'); - $Twig_Environment = constant('TwigEnvironment'); + $TwigLoaderFilesystem = constant('\TwigLoaderFilesystem'); + $Twig_Environment = constant('\TwigEnvironment'); $Twig_SimpleFilter = constant('TwigSimpleFilter'); $Twig_Extension_Debug = constant('TwigExtensionDebug'); @@ -121,7 +129,7 @@ abstract class Controller { $twig->addExtension(new $Twig_Extension_Debug()); } - $twig->addExtension(new transExtension()); + $twig->addExtension(new \transExtension()); $twig->addFilter(new $Twig_SimpleFilter('translate', function ($str) { // do something different from the built-in date filter @@ -142,36 +150,18 @@ abstract class Controller { $this->output = $template->render($this->data); break; - case 'dwoo': - require_once(DIR_SYSTEM."templateEngines/Dwoo/autoload.php"); - - @trigger_error(sprintf("Dwoo template engine is deprecated since Phacil 1.5.0 and will be removed in further versions. Migration to Smarty (most similarity) or other template engine is recommended."), E_USER_DEPRECATED); - - $dwoo = new Dwoo\Core(); - - // Configure directories - $dwoo->setCompileDir(DIR_CACHE.'dwoo/compiled/dir/'); // Folder to store compiled templates - $dwoo->setCacheDir(DIR_CACHE.'dwoo/cache/');// Folder to store cached templates - $dwoo->setCacheTime(3600); //Cache Time - $dwoo->setTemplateDir(DIR_TEMPLATE); // Folder containing template files - - $dwoo->getLoader()->addDirectory(DIR_SYSTEM."templateEngines/Dwoo/extension/"); - - $this->output = $dwoo->get($this->template, $this->data); - - break; case 'mustache': require_once(DIR_SYSTEM."templateEngines/Mustache/autoload.php"); - Mustache_Autoloader::register(); + \Mustache_Autoloader::register(); - $mustache = new Mustache_Engine(array( + $mustache = new \Mustache_Engine(array( //'template_class_prefix' => '__MyTemplates_', 'cache' => DIR_CACHE.'mustache', 'cache_file_mode' => 0666, // Please, configure your umask instead of doing this :) //'cache_lambda_templates' => true, - 'loader' => new Mustache_Loader_FilesystemLoader(DIR_TEMPLATE), + 'loader' => new \Mustache_Loader_FilesystemLoader(DIR_TEMPLATE), //'partials_loader' => new Mustache_Loader_FilesystemLoader(dirname(__FILE__).'/views/partials'), 'helpers' => array('translate' => function($text) { if (class_exists('Translate')) { @@ -197,7 +187,7 @@ abstract class Controller { case 'smarty': require_once(DIR_SYSTEM."templateEngines/smarty/autoload.php"); - $smarty = new Smarty(); + $smarty = new \Smarty(); $smarty->setTemplateDir(DIR_TEMPLATE); $smarty->setCompileDir(DIR_CACHE."Smarty/compile/"); @@ -208,7 +198,7 @@ abstract class Controller { $smarty->assign($this->data); - $smarty->caching = Smarty::CACHING_LIFETIME_CURRENT; + $smarty->caching = \Smarty::CACHING_LIFETIME_CURRENT; //** un-comment the following line to show the debug console $smarty->debugging = (defined('DEBUG')) ? DEBUG : false; @@ -247,4 +237,5 @@ abstract class Controller { return $this->response->setOutput($this->render()); } -} \ No newline at end of file +} + diff --git a/system/engine/document.php b/system/engine/document.php index a74eb36..c45c272 100644 --- a/system/engine/document.php +++ b/system/engine/document.php @@ -1,4 +1,13 @@ \ No newline at end of file diff --git a/system/engine/front.php b/system/engine/front.php index a807618..435fff7 100644 --- a/system/engine/front.php +++ b/system/engine/front.php @@ -1,4 +1,13 @@ \ No newline at end of file diff --git a/system/engine/legacy.php b/system/engine/legacy.php new file mode 100644 index 0000000..974bb03 --- /dev/null +++ b/system/engine/legacy.php @@ -0,0 +1,13 @@ +registry->set('model_' . str_replace('/', '_', $model), new $class($this->registry)); } else { - trigger_error('Error: Could not load model ' . $model . '!'); + + $file = DIR_APPLICATION . 'model/' . $model . '.php'; + $class = 'Model' . preg_replace('/[^a-zA-Z0-9]/', '', $model); + + if (file_exists($file)) { + include_once($file); + + $this->registry->set('model_' . str_replace('/', '_', $model), new $class($this->registry)); + } else { + trigger_error('Error: Could not load model ' . $model . '!'); + exit(); + } + } + + } + + public function helper(string $helper) { + + $parts = explode('/', str_replace('../', '', (string)$helper)); + + $lastPart = array_pop($parts); + + $path = str_replace('../', '', implode("/", $parts) ); + + $file = DIR_APP_MODULAR.$path."/helper/". $lastPart.".php"; + + if(file_exists($file)){ + include_once($file); + /* $class = 'Helper' . preg_replace('/[^a-zA-Z0-9]/', '', $model); + + $this->registry->set('model_' . str_replace('/', '_', $model), new $class($this->registry)); */ + } else { + trigger_error('Error: Could not load Helper ' . $helper . '!'); exit(); } + } public function control($model) { //temp alias, consider change to loader controller function diff --git a/system/engine/log.php b/system/engine/log.php index d0a91dc..fb2cd9a 100644 --- a/system/engine/log.php +++ b/system/engine/log.php @@ -1,4 +1,13 @@ registry->set($key, $value); } } -?> \ No newline at end of file diff --git a/system/engine/registry.php b/system/engine/registry.php index 101c77a..6b4b887 100644 --- a/system/engine/registry.php +++ b/system/engine/registry.php @@ -1,4 +1,13 @@ translation($body)); } else { echo $body; diff --git a/system/templateEngines/Twig/Extension/ExacTITranslate1x.php b/system/templateEngines/Twig/Extension/ExacTITranslate1x.php index 54867a3..441ae3f 100644 --- a/system/templateEngines/Twig/Extension/ExacTITranslate1x.php +++ b/system/templateEngines/Twig/Extension/ExacTITranslate1x.php @@ -9,6 +9,8 @@ define('TWIGtagIni', 't'); define('TWIGtagClose', 'endt'); +//use Phacil\Framework; + class transTokenParser extends \Twig_TokenParser { @@ -177,10 +179,10 @@ function traduzir() { $body = array_shift($params); if (class_exists('Translate')) { - $trans = new Translate(); + $trans = new Phacil\Framework\Translate(); echo ($trans->translation($body)); } else { echo $body; } -} \ No newline at end of file +} diff --git a/system/templateEngines/Twig/autoload.php b/system/templateEngines/Twig/autoload.php index afb7ebe..4788cdf 100644 --- a/system/templateEngines/Twig/autoload.php +++ b/system/templateEngines/Twig/autoload.php @@ -1,29 +1,31 @@ ') == false) { - define('TwigFolderLoad', 'Twig1x'); - define('TwigLoaderFilesystem', 'Twig_Loader_Filesystem'); - define('TwigEnvironment', 'Twig_Environment'); - define('TwigSimpleFilter', 'Twig_SimpleFilter'); - define('TwigExtensionDebug', 'Twig_Extension_Debug'); +namespace { + if (version_compare(phpversion(), '7.0.0', '>') == false) { + define('TwigFolderLoad', 'Twig1x'); + define('TwigLoaderFilesystem', 'Twig_Loader_Filesystem'); + define('TwigEnvironment', 'Twig_Environment'); + define('TwigSimpleFilter', 'Twig_SimpleFilter'); + define('TwigExtensionDebug', 'Twig_Extension_Debug'); -} else { - define('TwigLoaderFilesystem', '\Twig\Loader\FilesystemLoader'); - define('TwigEnvironment', '\Twig\Environment'); - define('TwigSimpleFilter', '\Twig\TwigFilter'); - define('TwigExtensionDebug', '\Twig\Extension\DebugExtension'); - - if (version_compare(phpversion(), '7.2.0', '>') == false) { - define('TwigFolderLoad', 'Twig2x'); } else { - define('TwigFolderLoad', 'Twig3x'); + define('TwigLoaderFilesystem', '\Twig\Loader\FilesystemLoader'); + define('TwigEnvironment', '\Twig\Environment'); + define('TwigSimpleFilter', '\Twig\TwigFilter'); + define('TwigExtensionDebug', '\Twig\Extension\DebugExtension'); + + if (version_compare(phpversion(), '7.2.0', '>') == false) { + define('TwigFolderLoad', 'Twig2x'); + } else { + define('TwigFolderLoad', 'Twig3x'); + } } -} -include_once TwigFolderLoad."/autoload.php"; + include_once TwigFolderLoad."/autoload.php"; -if(TwigFolderLoad == 'Twig1x') { - if (file_exists(__DIR__ . "/Extension/ExacTITranslate1x.php")) include __DIR__ . "/Extension/ExacTITranslate1x.php"; -} else { - if (file_exists(__DIR__ . "/Extension/ExacTITranslate.php")) include __DIR__ . "/Extension/ExacTITranslate.php"; + if(TwigFolderLoad == 'Twig1x') { + if (file_exists(__DIR__ . "/Extension/ExacTITranslate1x.php")) include __DIR__ . "/Extension/ExacTITranslate1x.php"; + } else { + if (file_exists(__DIR__ . "/Extension/ExacTITranslate.php")) include __DIR__ . "/Extension/ExacTITranslate.php"; + } } \ No newline at end of file diff --git a/system/templateEngines/smarty/autoload.php b/system/templateEngines/smarty/autoload.php index e9ab0d4..3ea23a7 100644 --- a/system/templateEngines/smarty/autoload.php +++ b/system/templateEngines/smarty/autoload.php @@ -3,8 +3,8 @@ include __DIR__."/Smarty.class.php"; function translate($params = '', $content = '', $smarty = '', &$repeat = '', $template = '') { - if (class_exists('Translate')) { - $trans = new Translate(); + if (class_exists('\Phacil\Framework\Translate')) { + $trans = new \Phacil\Framework\Translate(); return ($trans->translation($content)); } else { return $content; diff --git a/system/translate/autoload.php b/system/translate/autoload.php index 153d96b..99cf64e 100644 --- a/system/translate/autoload.php +++ b/system/translate/autoload.php @@ -1,4 +1,12 @@ '(\\d{1,})',