#1 | Phalcon\Dispatcher->dispatch()
/var/www/vhosts/guncelsorular.com/httpdocs/app/Bootstrap.php (426) <?php
namespace App;
use Application\Cache\Manager as CacheManager;
use Application\Mvc\Helper\CmsCache;
use Konsol\Model\Options;
class Bootstrap{
public function run(){
try {
$this->initDefined();
$di = new \Phalcon\DI\FactoryDefault();
$loader = new \Phalcon\Loader();
// Config
$config = require_once PATHS['APPS'] . '/config/application.php';
$config = new \Phalcon\Config($config);
$loader->registerDirs([PATHS['APPS'] . "/plugins/"]);
$loader->registerNamespaces($config->loader->namespaces->toArray());
$loader->registerFiles([PATHS['APPS'] . '/../vendor/autoload.php']);
$loader->register();
$di->set('config', $config);
// URL
$url = new \Phalcon\Mvc\Url();
$url->setBasePath($config->base_path);
$url->setBaseUri($config->base_path);
$di->set('url', $url);
// Database
$di->set('db', new \Phalcon\Db\Adapter\Pdo\Mysql([
"host" => $config->database->host,
"username" => $config->database->username,
"password" => $config->database->password,
"dbname" => $config->database->dbname,
"charset" => $config->database->charset,
"port" => $config->database->port,
]));
//SET MODULES
$this->getModules($di);
// Loader
$loader->registerDirs([PATHS['APPS'] . "/plugins/"]);
$loader->registerNamespaces($config->loader->namespaces->toArray());
$loader->registerFiles([PATHS['APPS'] . '/../vendor/autoload.php']);
$loader->register();
// View
$this->initView($di,$config);
// Cache
$this->initCache($di);
// Application
$application = new \Phalcon\Mvc\Application();
$application->registerModules($config->modules->toArray());
// Events Manager, Dispatcher
$this->initEventManager($di);
$di->set('session', function () use ($di) {
$session = new \Phalcon\Session\Adapter\Files();
session_name(HOST_HASH);
$session->start();
return $session;
});
$di->set('cookie', function () {
$cookies = new \Phalcon\Http\Response\Cookies();
$cookies->useEncryption(true);
return $cookies;
});
$di->set('crypt', function () {
$crypt = new \Phalcon\Crypt();
$crypt->setCipher('aes-256-ctr');
$crypt->setKey("T4\xb1\x8d\xa9\x98\x05\\\x8c\xbe\x1d\x07&[\x99\x18\xa4~Lc1\xbeW\xb3");
return $crypt;
});
$di->set('localization', new \YobisiKonsol\Plugin\Localization());
$di->set('helper', new \Application\Mvc\Helper());
$di->set('auth', new \Konsol\Model\Auth());
$di->set('acl', new \YobisiKonsol\Plugin\Acl());
// JS Assets
$this->initAssetsManager($di);
// Toast helper
$di->set('toast', new \Application\Mvc\Helper\Toast());
// Flash helper
$di->set('flash', new \Phalcon\Flash\Session());
// Routing
$this->initRouting($application, $di);
$application->setDI($di);
// Main dispatching process
$response = $this->dispatch($di);
$response->send();
} catch (\Exception $e) {
return $this->initCatch($di, $e,[
"code" => "bootstrap_initCatch",
"message" => "Uygulama çalıştırılırken hata oluştu"
]);
}
}
private function initRouting($application, $di){
foreach ($application->getModules() as $module) {
try {
$initClassName = str_replace('\Module', '\Init', $module['className']);
if (class_exists($initClassName)) {
new $initClassName();
}
}catch (\Throwable $exception){
$this->initCatch($di,$exception,[
"code" => "init_routing",
"message" => sprintf('%s modülünün Init.php dosyasında hata !',$module['className']),
"error_code" => $exception->getCode(),
"error_message" => $exception->getMessage(),
"file" => $exception->getFile(),
"line" => $exception->getLine()
]);
}
}
$router = new \Application\Mvc\Router\DefaultRouter();
$router->setDi($di);
foreach ($application->getModules() as $module) {
try {
$routesClassName = str_replace('\Module', '\Routes', $module['className']);
if (class_exists($routesClassName)) {
$routesClass = new $routesClassName();
$router = $routesClass->init($router);
}
}catch (\Throwable $exception){
$this->initCatch($di,$exception,[
"code" => "init_routing",
"message" => sprintf('%s modülünün Routes.php dosyasında hata !',$module['className']),
"error_code" => $exception->getCode(),
"error_message" => $exception->getMessage(),
"file" => $exception->getFile(),
"line" => $exception->getLine()
]);
}
}
$di->set('router', $router);
}
private function initAssetsManager($di){
$assetsManager = new \Application\Assets\Manager();
$di->set('assets', $assetsManager);
}
private function initEventManager($di)
{
$eventsManager = new \Phalcon\Events\Manager();
$dispatcher = new \Phalcon\Mvc\Dispatcher();
$eventsManager->attach("dispatch", function ($event, $dispatcher, $exception) use ($di) {
if ($event->getType() == 'beforeException') {
switch ($exception->getCode()) {
case \Phalcon\Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
case \Phalcon\Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
return $this->initCatch($di, $exception,[
"code" => "dispatch:beforeException",
"message" => "Sayfa çalıştırılırken beklenmedik hata oluştu"
]);
}
}//error pages redirect
});
/*
* Plugins
*/
$events = [];
$plugins = glob(PATHS['APPS'] .'plugins/*.php');
foreach ($plugins as $plugin_path):
$plugin_name = rtrim(basename($plugin_path), ".php");
$namespace = "YobisiKonsol\Plugin\\" . $plugin_name;
$variables = get_class_vars($namespace);
if(!$event_type = $variables['event_type']) continue;
$events[$event_type][] = $namespace;//plugin
endforeach;
foreach ($events as $event_type => $namespaces):
$eventsManager->attach($event_type, function ($event, $dispatcher) use ($di, $namespaces) {
foreach ($namespaces as $namespace):
$item = new $namespace();
if(method_exists($item,"execute")) $item->execute();
endforeach;
});
endforeach;
// Profiler
//$is_profiler = Options::findFirstByKey('profiler');
$is_profiler = false;
if ($is_profiler) {
$profiler = new \Phalcon\Db\Profiler();
$di->set('profiler', $profiler);
$eventsManager->attach('db', function ($event, $db) use ($profiler) {
if ($event->getType() == 'beforeQuery') {
$profiler->startProfile($db->getSQLStatement());
}
if ($event->getType() == 'afterQuery') {
$profiler->stopProfile();
}
});
$di->get('view')->setVar('profiler',$di->get('profiler'));
}
$db = $di->get('db');
$db->setEventsManager($eventsManager);
$dispatcher->setEventsManager($eventsManager);
$di->set('dispatcher', $dispatcher);
}
private function initView($di,$config = [])
{
$view = new \Phalcon\Mvc\View();
define('MAIN_VIEW_PATH', PATHS['MODULES'] . "Konsol/Views/");
$view->setViewsDir(MAIN_VIEW_PATH);
$view->setMainView(MAIN_VIEW_PATH . '/konsol');
$view->setLayoutsDir(MAIN_VIEW_PATH . '/layouts/');
$view->setLayout('/konsol');
$view->setPartialsDir(MAIN_VIEW_PATH . '/partials/');
// Volt
$volt = new \Application\Mvc\View\Engine\Volt($view, $di);
$volt->setOptions([
'compiledPath' => PATHS['APPS'] . '/../data/cache/volt/',
'compileAlways' => (DEBUG_MODE) ? true : false
]);
$volt->initCompiler();
$phtml = new \Phalcon\Mvc\View\Engine\Php($view, $di);
$viewEngines = [
".volt" => $volt,
".phtml" => $phtml,
];
$view->registerEngines($viewEngines);
$ajax = $di->get('request')->getQuery('_ajax');
if ($ajax) $view->setRenderLevel(\Phalcon\Mvc\View::LEVEL_LAYOUT);
$view->setVar('config',$config);
$di->set('view', $view);
return $view;
}
private function initCache($di)
{
$config = $di->get('config');
$cacheFrontend = new \Phalcon\Cache\Frontend\Data([
"lifetime" => 60,
"prefix" => HOST_HASH,
]);
$cache = null;
switch ($config->cache) {
case 'memcache':
$cache = new \Phalcon\Cache\Backend\Memcache(
$cacheFrontend, [
"host" => $config->memcache->host,
"port" => $config->memcache->port,
]);
break;
case 'memcached':
$cache = new \Phalcon\Cache\Backend\Libmemcached(
$cacheFrontend, [
"host" => $config->memcached->host,
"port" => $config->memcached->port,
]);
break;
case 'redis':
//$company_index = $di->get('session')->get('company_id','0');
$company_index = 0;
$cache = new \Phalcon\Cache\Backend\Redis(
$cacheFrontend, [
"host" => $config->redis->host,
"port" => $config->redis->port,
"auth" => $config->redis->auth,
"statsKey" => $config->redis->statsKey,
"persistent" => $config->redis->persistent,
"index" => $company_index
]);
break;
default:
$cache = new \Phalcon\Cache\Backend\File($cacheFrontend, [
"cacheDir" => PATHS['APPS'] . "/../data/cache/backend/",
'lifetime' => 172800
]);
}
\Application\Widget\Proxy::$cache = $cache; // Modules Widget System
$modelsMetadata = new \Phalcon\Mvc\Model\Metadata\Memory();
$di->set('cache', $cache, true);
$di->set('modelsCache', $cache, true);
$di->set('modelsMetadata', $modelsMetadata);
$di->set('cacheManager', new CacheManager());
}
private function dispatch($di){
$router = $di->get('router');
$router->handle();
$view = $di->get('view');
$dispatcher = $di->get('dispatcher');
$response = $di->get('response');
$dispatcher->setModuleName($router->getModuleName());
$dispatcher->setControllerName($router->getControllerName());
$dispatcher->setActionName($router->getActionName());
$dispatcher->setParams($router->getParams());
$moduleName = \Application\Utils\ModuleName::camelize($router->getModuleName());
$ModuleClassName = $moduleName . '\Module';
if (class_exists($ModuleClassName)) {
$module = new $ModuleClassName();
$module->registerAutoloaders();
$module->registerServices($di);
}
$view->start();
try {
$dispatcher->dispatch();
} catch (\Phalcon\Exception $error) {
return $this->initCatch($di, $error,[
"code" => "dispatch:catch",
"message" => "Uygulama çalıştırılırken beklenmedik hata oluştu"
]);
}
$view->render(
$dispatcher->getControllerName(),
$dispatcher->getActionName(),
$dispatcher->getParams()
);
$view->finish();
// AJAX
$request = $di['request'];
$_ajax = $request->getQuery('_ajax');
if ($_ajax) {
$view->setLayout('ajax');
$contents = $view->getContent();
$return = new \stdClass();
$return->status = true;
$return->title = $di->get('helper')->title()->get();
$return->html = $contents;
$headers = $response->getHeaders()->toArray();
if (isset($headers[404]) || isset($headers[503])) {
$return->status = false;
}
$response->setContentType('application/json', 'UTF-8');
$response->setContent(json_encode($return));
} else {
$response->setContent($view->getContent());
}
return $response;
}
private function getModules($di){
try {
$config = $di->get('config');
$db = $di->get('db');
$cache = new \Application\Mvc\Helper\CmsCache();
if (APPLICATION_ENV == "development") $db->query("SET @@GLOBAL.sql_mode=''");//fix group_by error
$user_modules = $cache::getInstance()->get('modules');
if (!$user_modules):
//GET_MODULES
$statement = $db->prepare('SELECT * FROM modules WHERE status = ? order by priority ASC');
$statement->execute(array("active"));
$user_modules = $statement->fetchAll(\Phalcon\Db::FETCH_ASSOC);
$cache::getInstance()->save('modules', $user_modules);
endif;
//SET_MODULES
require_once PATHS['APPS'] . '/modules/Application/Loader/Modules.php';
$modules = new \Application\Loader\Modules();
$modules_config = $modules->modulesConfig($user_modules);
foreach ($modules_config['loader']['namespaces'] as $key => $module)
$config->loader->namespaces[$key] = $module;
foreach ($modules_config['modules'] as $key => $module)
$config->modules[$key] = $module;
return $config;
}catch (\Throwable $e){
$params = [
"code" => "bootstrap_modules_catch",
"message" => $e->getMessage(),
"file" => $e->getFile(),
"line" => $e->getLine(),
];
return $di->get('response')->redirect('public/error.php?' . http_build_query($params))->send();
}
}
private function initDefined(){
/*
* geliştirici modunu açar
*/
$root_dir = rtrim(__DIR__,'app');
define('PATHS',[
"ROOT" => $root_dir,
"APPS" => $root_dir . 'app/',
"MODULES" => $root_dir . "app/modules/",
"PLUGINS" => $root_dir . "app/plugins/",
"DATA" => $root_dir . "data/",
"CACHE" => $root_dir . "data/cache/",
"PUBLIC" => $root_dir . 'public/',
"MEDIA" => $root_dir . "public/media/",
"ASSETS" => $root_dir . "public/assets/",
]);
}
private function initCatch($di, $exception = null,$params = []){
$debug = new \Phalcon\Debug();
$debug->listen()->onUncaughtException($exception);
return true;
if (DEBUG_MODE):
if($exception):
try {
$debug = new \Phalcon\Debug();
$debug->listen()->onUncaughtException($exception);
return true;
}catch (\Throwable $e){
}
endif;
endif;
return $di->get('response')->redirect('public/error.php?' . http_build_query($params))->send();
}
}
|
#2 | App\Bootstrap->dispatch(Object(Phalcon\Di\FactoryDefault))
/var/www/vhosts/guncelsorular.com/httpdocs/app/Bootstrap.php (132) <?php
namespace App;
use Application\Cache\Manager as CacheManager;
use Application\Mvc\Helper\CmsCache;
use Konsol\Model\Options;
class Bootstrap{
public function run(){
try {
$this->initDefined();
$di = new \Phalcon\DI\FactoryDefault();
$loader = new \Phalcon\Loader();
// Config
$config = require_once PATHS['APPS'] . '/config/application.php';
$config = new \Phalcon\Config($config);
$loader->registerDirs([PATHS['APPS'] . "/plugins/"]);
$loader->registerNamespaces($config->loader->namespaces->toArray());
$loader->registerFiles([PATHS['APPS'] . '/../vendor/autoload.php']);
$loader->register();
$di->set('config', $config);
// URL
$url = new \Phalcon\Mvc\Url();
$url->setBasePath($config->base_path);
$url->setBaseUri($config->base_path);
$di->set('url', $url);
// Database
$di->set('db', new \Phalcon\Db\Adapter\Pdo\Mysql([
"host" => $config->database->host,
"username" => $config->database->username,
"password" => $config->database->password,
"dbname" => $config->database->dbname,
"charset" => $config->database->charset,
"port" => $config->database->port,
]));
//SET MODULES
$this->getModules($di);
// Loader
$loader->registerDirs([PATHS['APPS'] . "/plugins/"]);
$loader->registerNamespaces($config->loader->namespaces->toArray());
$loader->registerFiles([PATHS['APPS'] . '/../vendor/autoload.php']);
$loader->register();
// View
$this->initView($di,$config);
// Cache
$this->initCache($di);
// Application
$application = new \Phalcon\Mvc\Application();
$application->registerModules($config->modules->toArray());
// Events Manager, Dispatcher
$this->initEventManager($di);
$di->set('session', function () use ($di) {
$session = new \Phalcon\Session\Adapter\Files();
session_name(HOST_HASH);
$session->start();
return $session;
});
$di->set('cookie', function () {
$cookies = new \Phalcon\Http\Response\Cookies();
$cookies->useEncryption(true);
return $cookies;
});
$di->set('crypt', function () {
$crypt = new \Phalcon\Crypt();
$crypt->setCipher('aes-256-ctr');
$crypt->setKey("T4\xb1\x8d\xa9\x98\x05\\\x8c\xbe\x1d\x07&[\x99\x18\xa4~Lc1\xbeW\xb3");
return $crypt;
});
$di->set('localization', new \YobisiKonsol\Plugin\Localization());
$di->set('helper', new \Application\Mvc\Helper());
$di->set('auth', new \Konsol\Model\Auth());
$di->set('acl', new \YobisiKonsol\Plugin\Acl());
// JS Assets
$this->initAssetsManager($di);
// Toast helper
$di->set('toast', new \Application\Mvc\Helper\Toast());
// Flash helper
$di->set('flash', new \Phalcon\Flash\Session());
// Routing
$this->initRouting($application, $di);
$application->setDI($di);
// Main dispatching process
$response = $this->dispatch($di);
$response->send();
} catch (\Exception $e) {
return $this->initCatch($di, $e,[
"code" => "bootstrap_initCatch",
"message" => "Uygulama çalıştırılırken hata oluştu"
]);
}
}
private function initRouting($application, $di){
foreach ($application->getModules() as $module) {
try {
$initClassName = str_replace('\Module', '\Init', $module['className']);
if (class_exists($initClassName)) {
new $initClassName();
}
}catch (\Throwable $exception){
$this->initCatch($di,$exception,[
"code" => "init_routing",
"message" => sprintf('%s modülünün Init.php dosyasında hata !',$module['className']),
"error_code" => $exception->getCode(),
"error_message" => $exception->getMessage(),
"file" => $exception->getFile(),
"line" => $exception->getLine()
]);
}
}
$router = new \Application\Mvc\Router\DefaultRouter();
$router->setDi($di);
foreach ($application->getModules() as $module) {
try {
$routesClassName = str_replace('\Module', '\Routes', $module['className']);
if (class_exists($routesClassName)) {
$routesClass = new $routesClassName();
$router = $routesClass->init($router);
}
}catch (\Throwable $exception){
$this->initCatch($di,$exception,[
"code" => "init_routing",
"message" => sprintf('%s modülünün Routes.php dosyasında hata !',$module['className']),
"error_code" => $exception->getCode(),
"error_message" => $exception->getMessage(),
"file" => $exception->getFile(),
"line" => $exception->getLine()
]);
}
}
$di->set('router', $router);
}
private function initAssetsManager($di){
$assetsManager = new \Application\Assets\Manager();
$di->set('assets', $assetsManager);
}
private function initEventManager($di)
{
$eventsManager = new \Phalcon\Events\Manager();
$dispatcher = new \Phalcon\Mvc\Dispatcher();
$eventsManager->attach("dispatch", function ($event, $dispatcher, $exception) use ($di) {
if ($event->getType() == 'beforeException') {
switch ($exception->getCode()) {
case \Phalcon\Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
case \Phalcon\Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
return $this->initCatch($di, $exception,[
"code" => "dispatch:beforeException",
"message" => "Sayfa çalıştırılırken beklenmedik hata oluştu"
]);
}
}//error pages redirect
});
/*
* Plugins
*/
$events = [];
$plugins = glob(PATHS['APPS'] .'plugins/*.php');
foreach ($plugins as $plugin_path):
$plugin_name = rtrim(basename($plugin_path), ".php");
$namespace = "YobisiKonsol\Plugin\\" . $plugin_name;
$variables = get_class_vars($namespace);
if(!$event_type = $variables['event_type']) continue;
$events[$event_type][] = $namespace;//plugin
endforeach;
foreach ($events as $event_type => $namespaces):
$eventsManager->attach($event_type, function ($event, $dispatcher) use ($di, $namespaces) {
foreach ($namespaces as $namespace):
$item = new $namespace();
if(method_exists($item,"execute")) $item->execute();
endforeach;
});
endforeach;
// Profiler
//$is_profiler = Options::findFirstByKey('profiler');
$is_profiler = false;
if ($is_profiler) {
$profiler = new \Phalcon\Db\Profiler();
$di->set('profiler', $profiler);
$eventsManager->attach('db', function ($event, $db) use ($profiler) {
if ($event->getType() == 'beforeQuery') {
$profiler->startProfile($db->getSQLStatement());
}
if ($event->getType() == 'afterQuery') {
$profiler->stopProfile();
}
});
$di->get('view')->setVar('profiler',$di->get('profiler'));
}
$db = $di->get('db');
$db->setEventsManager($eventsManager);
$dispatcher->setEventsManager($eventsManager);
$di->set('dispatcher', $dispatcher);
}
private function initView($di,$config = [])
{
$view = new \Phalcon\Mvc\View();
define('MAIN_VIEW_PATH', PATHS['MODULES'] . "Konsol/Views/");
$view->setViewsDir(MAIN_VIEW_PATH);
$view->setMainView(MAIN_VIEW_PATH . '/konsol');
$view->setLayoutsDir(MAIN_VIEW_PATH . '/layouts/');
$view->setLayout('/konsol');
$view->setPartialsDir(MAIN_VIEW_PATH . '/partials/');
// Volt
$volt = new \Application\Mvc\View\Engine\Volt($view, $di);
$volt->setOptions([
'compiledPath' => PATHS['APPS'] . '/../data/cache/volt/',
'compileAlways' => (DEBUG_MODE) ? true : false
]);
$volt->initCompiler();
$phtml = new \Phalcon\Mvc\View\Engine\Php($view, $di);
$viewEngines = [
".volt" => $volt,
".phtml" => $phtml,
];
$view->registerEngines($viewEngines);
$ajax = $di->get('request')->getQuery('_ajax');
if ($ajax) $view->setRenderLevel(\Phalcon\Mvc\View::LEVEL_LAYOUT);
$view->setVar('config',$config);
$di->set('view', $view);
return $view;
}
private function initCache($di)
{
$config = $di->get('config');
$cacheFrontend = new \Phalcon\Cache\Frontend\Data([
"lifetime" => 60,
"prefix" => HOST_HASH,
]);
$cache = null;
switch ($config->cache) {
case 'memcache':
$cache = new \Phalcon\Cache\Backend\Memcache(
$cacheFrontend, [
"host" => $config->memcache->host,
"port" => $config->memcache->port,
]);
break;
case 'memcached':
$cache = new \Phalcon\Cache\Backend\Libmemcached(
$cacheFrontend, [
"host" => $config->memcached->host,
"port" => $config->memcached->port,
]);
break;
case 'redis':
//$company_index = $di->get('session')->get('company_id','0');
$company_index = 0;
$cache = new \Phalcon\Cache\Backend\Redis(
$cacheFrontend, [
"host" => $config->redis->host,
"port" => $config->redis->port,
"auth" => $config->redis->auth,
"statsKey" => $config->redis->statsKey,
"persistent" => $config->redis->persistent,
"index" => $company_index
]);
break;
default:
$cache = new \Phalcon\Cache\Backend\File($cacheFrontend, [
"cacheDir" => PATHS['APPS'] . "/../data/cache/backend/",
'lifetime' => 172800
]);
}
\Application\Widget\Proxy::$cache = $cache; // Modules Widget System
$modelsMetadata = new \Phalcon\Mvc\Model\Metadata\Memory();
$di->set('cache', $cache, true);
$di->set('modelsCache', $cache, true);
$di->set('modelsMetadata', $modelsMetadata);
$di->set('cacheManager', new CacheManager());
}
private function dispatch($di){
$router = $di->get('router');
$router->handle();
$view = $di->get('view');
$dispatcher = $di->get('dispatcher');
$response = $di->get('response');
$dispatcher->setModuleName($router->getModuleName());
$dispatcher->setControllerName($router->getControllerName());
$dispatcher->setActionName($router->getActionName());
$dispatcher->setParams($router->getParams());
$moduleName = \Application\Utils\ModuleName::camelize($router->getModuleName());
$ModuleClassName = $moduleName . '\Module';
if (class_exists($ModuleClassName)) {
$module = new $ModuleClassName();
$module->registerAutoloaders();
$module->registerServices($di);
}
$view->start();
try {
$dispatcher->dispatch();
} catch (\Phalcon\Exception $error) {
return $this->initCatch($di, $error,[
"code" => "dispatch:catch",
"message" => "Uygulama çalıştırılırken beklenmedik hata oluştu"
]);
}
$view->render(
$dispatcher->getControllerName(),
$dispatcher->getActionName(),
$dispatcher->getParams()
);
$view->finish();
// AJAX
$request = $di['request'];
$_ajax = $request->getQuery('_ajax');
if ($_ajax) {
$view->setLayout('ajax');
$contents = $view->getContent();
$return = new \stdClass();
$return->status = true;
$return->title = $di->get('helper')->title()->get();
$return->html = $contents;
$headers = $response->getHeaders()->toArray();
if (isset($headers[404]) || isset($headers[503])) {
$return->status = false;
}
$response->setContentType('application/json', 'UTF-8');
$response->setContent(json_encode($return));
} else {
$response->setContent($view->getContent());
}
return $response;
}
private function getModules($di){
try {
$config = $di->get('config');
$db = $di->get('db');
$cache = new \Application\Mvc\Helper\CmsCache();
if (APPLICATION_ENV == "development") $db->query("SET @@GLOBAL.sql_mode=''");//fix group_by error
$user_modules = $cache::getInstance()->get('modules');
if (!$user_modules):
//GET_MODULES
$statement = $db->prepare('SELECT * FROM modules WHERE status = ? order by priority ASC');
$statement->execute(array("active"));
$user_modules = $statement->fetchAll(\Phalcon\Db::FETCH_ASSOC);
$cache::getInstance()->save('modules', $user_modules);
endif;
//SET_MODULES
require_once PATHS['APPS'] . '/modules/Application/Loader/Modules.php';
$modules = new \Application\Loader\Modules();
$modules_config = $modules->modulesConfig($user_modules);
foreach ($modules_config['loader']['namespaces'] as $key => $module)
$config->loader->namespaces[$key] = $module;
foreach ($modules_config['modules'] as $key => $module)
$config->modules[$key] = $module;
return $config;
}catch (\Throwable $e){
$params = [
"code" => "bootstrap_modules_catch",
"message" => $e->getMessage(),
"file" => $e->getFile(),
"line" => $e->getLine(),
];
return $di->get('response')->redirect('public/error.php?' . http_build_query($params))->send();
}
}
private function initDefined(){
/*
* geliştirici modunu açar
*/
$root_dir = rtrim(__DIR__,'app');
define('PATHS',[
"ROOT" => $root_dir,
"APPS" => $root_dir . 'app/',
"MODULES" => $root_dir . "app/modules/",
"PLUGINS" => $root_dir . "app/plugins/",
"DATA" => $root_dir . "data/",
"CACHE" => $root_dir . "data/cache/",
"PUBLIC" => $root_dir . 'public/',
"MEDIA" => $root_dir . "public/media/",
"ASSETS" => $root_dir . "public/assets/",
]);
}
private function initCatch($di, $exception = null,$params = []){
$debug = new \Phalcon\Debug();
$debug->listen()->onUncaughtException($exception);
return true;
if (DEBUG_MODE):
if($exception):
try {
$debug = new \Phalcon\Debug();
$debug->listen()->onUncaughtException($exception);
return true;
}catch (\Throwable $e){
}
endif;
endif;
return $di->get('response')->redirect('public/error.php?' . http_build_query($params))->send();
}
}
|