File: /var/www/farm.kosmicfarms/public/index.php
<?php
declare(strict_types=1);
use Phalcon\Mvc\Dispatcher;
use Phalcon\Events\Event;
use Phalcon\Events\Manager as EventsManager;
use Phalcon\Debug;
use Phalcon\Di\FactoryDefault;
use Phalcon\Assets\Manager as AssetsManager;
use Phalcon\Http\Cookie;
use Phalcon\Mvc\View;
error_reporting(E_ALL);
define('BASE_PATH', dirname(__DIR__));
define('APP_PATH', BASE_PATH . '/app');
try {
/**
* The FactoryDefault Dependency Injector automatically registers
* the services that provide a full stack framework.
*/
$di = new FactoryDefault();
$debug = new Debug();
$debug->listen();
/**
* Read services
*/
include APP_PATH . '/config/services.php';
/**
* Handle routes
*/
include APP_PATH . '/config/router.php';
/**
* Get config service for use in inline setup below
*/
$config = $di->getConfig();
/**
* Include Autoloader
*/
include APP_PATH . '/config/loader.php';
// Register the helper service
$di->setShared('myHelpers', function () {
return new MyHelpers();
});
$di->setShared('assets', function () {
$assetsManager = new AssetsManager();
// Add global CSS resources
$assetsManager->collection('nucleo')
->addCss('assets/css/nucleo-icons.css')
->addCss('assets/css/nucleo-svg.css')
->addCss('assets/css/sweetalert2.min.css');
$assetsManager->collection('pagestyle')
->addCss('assets/css/material-dashboard.css?v=3.2.0', true, false, ['id' => 'pagestyle']);
$assetsManager->collection('footer')
->addJs("assets/js/core/jquery-4.0.0.min.js")
->addJs("assets/js/core/popper.min.js")
->addJs("assets/js/core/bootstrap.min.js")
->addJs("assets/js/plugins/perfect-scrollbar.min.js")
->addJs("assets/js/plugins/smooth-scrollbar.min.js")
->addJs("assets/js/plugins/sweetalert2.all.min");
return $assetsManager;
});
$di->set('dispatcher', function () {
$eventsManager = new EventsManager();
$eventsManager->attach(
'dispatch:beforeException',
function (Event $event, $dispatcher, Exception $exception) {
if ($exception instanceof \Phalcon\Mvc\Dispatcher\Exception) {
// Redirect to Error Controller
$dispatcher->forward([
'controller' => 'dashboard',
'action' => 'index'
]);
return false; // Prevent default exception handling
}
}
);
$eventsManager->attach('dispatch:beforeExecuteRoute', new RememberPlugin());
// Attach the SecurityPlugin to 'dispatch' events
$eventsManager->attach('dispatch:beforeExecuteRoute', new SecurityPlugin());
// Attach the SecurityPlugin to 'dispatch' events
$dispatcher = new Dispatcher();
$dispatcher->setEventsManager($eventsManager);
return $dispatcher;
});
/**
* Handle the request
*/
$application = new \Phalcon\Mvc\Application($di);
echo $application->handle($_SERVER['REQUEST_URI'])->getContent();
} catch (\Exception $e) {
echo $e->getMessage() . '<br>';
echo '<pre>' . $e->getTraceAsString() . '</pre>';
}