Phalcon Framework 2.0.13

Phalcon\Cache\Exception: Cache file /var/www/html/ciss/cis.edu.vn/public/../app/../data/cache/backend/efa504d1f1d200a5bc89f783104caa559782c61ce89c could not be written

/var/www/html/ciss/cis.edu.vn/app/modules/Publication/Model/Publication.php (38)
#0Phalcon\Cache\Backend\File->save(efa504d1f1d200a5bc89f783104caa559782c61ce89c, Object(Phalcon\Mvc\Model\Resultset\Simple), 60)
#1Phalcon\Mvc\Model\Query->execute()
#2Phalcon\Mvc\Model::findFirst(Array([0] => slug = 'university-college-fair-2019', [cache] => Array([key] => efa504d1f1d200a5bc89f783104caa559782c61ce89c, [lifetime] => 60)))
/var/www/html/ciss/cis.edu.vn/app/modules/Publication/Model/Publication.php (38)
<?php
 
namespace Publication\Model;
 
use Application\Localization\Transliterator;
use Application\Mvc\Model\Model;
use Carbon\Carbon;
use Phalcon\Mvc\Model\Behavior\Timestampable;
use Phalcon\Mvc\Model\Validator\Uniqueness;
 
class Publication extends Model
{
    protected $id;
    protected $type_id;
    protected $slug;
    protected $created_at;
    protected $updated_at;
    protected $date;
    protected $cover_photo; // translate
    protected $preview_src; // translate
    protected $preview_inner; // translate
 
    protected $title;
    protected $short_description;
    protected $text;
    protected $meta_title;
    protected $meta_description;
    protected $meta_keywords;
 
    protected $translateModel = 'Publication\Model\Translate\PublicationTranslate';
 
    public static function findCachedBySlug($slug)
    {
        $publication = static::findFirst(["slug = '$slug'",
            'cache' => [
                'key' => static::cacheSlugKey($slug),
                'lifetime' => 60],
        ]);
 
        return $publication;
    } // translate
 
    public static function cacheSlugKey($slug)
    {
        $key = HOST_HASH . md5('Publication\Model\Publication; slug = ' . $slug);
 
        return $key;
    }
 
    public function getSource()
    {
        return "publication";
    }
 
    public function initialize()
    {
        $this->addBehavior(
            new Timestampable(
                [
                    'beforeValidationOnCreate' => [
                        'field' => ['created_at', 'updated_at'],
                        'generator' => function () {
                            return Carbon::now()->timestamp;
                        },
                    ],
                    'beforeUpdate' => [
                        'field' => 'updated_at',
                        'generator' => function () {
                            return Carbon::now()->timestamp;
                        },
                    ],
                ]
            )
        );
 
        $this->hasMany('id', $this->translateModel, 'foreign_id', ['alias' => 'translates']); // translate
 
        $this->belongsTo('type_id', 'Publication\Model\Type', 'id', [
            'alias' => 'type',
        ]);
    }
 
    public function afterUpdate()
    {
        parent::afterUpdate();
 
        $cache = $this->getDi()->get('cache');
 
        $cache->delete(static::cacheSlugKey($this->getSlug()));
    }
 
    public function getSlug()
    {
        return $this->slug;
    }
 
    public function setSlug($slug)
    {
        $this->slug = $slug;
    }
 
    public function beforeSave()
    {
 
        if (LANG == "vi") {
            $date = str_replace('/', '-', $this->date);
            $this->setDate(strtotime($date));
        } else {
            $this->setDate(strtotime($this->date));
        }
 
    }
 
    public function validation()
    {
        $this->validate(new Uniqueness(
            [
                "field" => "slug",
                "message" => "A page with a transliteration = '" . $this->slug . "' Already exists",
            ]
        ));
 
        return $this->validationHasFailed() != true;
    }
 
    public function afterValidation()
    {
        if (!$this->date) {
            $this->date = date("Y-m-d H:i:s");
        }
    }
 
    public function updateFields($data)
    {
        if (!$this->getSlug()) {
            $this->setSlug(Transliterator::slugify($data['title']));
        }
        if (!$this->getMetaTitle()) {
            $this->setMetaTitle($data['title']);
        }
        if (!$this->getMetaKeywords()) {
            $this->setMeta_keywords($data['meta_keywords']);
        }
        if (!$this->getMetaDescription()) {
            $this->setMeta_description($data['meta_description']);
        }
        $this->setPreviewInner(isset($data['preview_inner']) ? 1 : 0);
    }
 
    public function getMetaTitle()
    {
        return $this->getMLVariable('meta_title');
    }
 
    public function setMetaTitle($meta_title)
    {
        $this->setMLVariable('meta_title', $meta_title);
    }
 
    public function getCreatedAt()
    {
        return $this->created_at;
    }
 
    public function setCreatedAt($created_at)
    {
        $this->created_at = $created_at;
    }
 
    public function getMetaDescription()
    {
        return $this->getMLVariable('meta_description');
    }
 
    public function setMeta_description($meta_description)
    {
        $this->setMLVariable('meta_description', $meta_description);
    }
 
    public function getMetaKeywords()
    {
        return $this->getMLVariable('meta_keywords');
    }
 
    public function setMeta_keywords($meta_keywords)
    {
        $this->setMLVariable('meta_keywords', $meta_keywords);
    }
 
    /**
     * @return mixed
     */
    public function getMetaImage()
    {
        $image = $this->getDI()->get('helper')->image([
            'id' => $this->getId(),
            'type' => $this->getImgFolder("cover_photo"),
            'width' => 722,
            'height' => 361,
            'strategy' => 'a',
            'stretch' => 'false',
            'widthHeight' => 'false',
            'hash' => true,
        ]);
        if ($image->isExists()) {
            return $imgPath = "/" . $image->cachedRelPath();
        }
 
        return '';
    }
 
    public function getId()
    {
        return $this->id;
    }
 
    public function setId($id)
    {
        $this->id = $id;
    }
 
    public function getText()
    {
        return $this->getMLVariable('text');
    }
 
    public function setText($text)
    {
        $this->setMLVariable('text', $text);
    }
 
    /**
     * @return mixed
     */
    public function getShortDescription()
    {
        return $this->getMLVariable('short_description');
    }
 
    /**
     * @param mixed $short_description
     */
    public function setShortDescription($short_description)
    {
        $this->setMLVariable('short_description', $short_description);
    }
 
    public function getTitle()
    {
        return $this->getMLVariable('title');
    }
 
    public function setTitle($title)
    {
        $this->setMLVariable('title', $title);
    }
 
    public function getUpdatedAt()
    {
        return $this->updated_at;
    }
 
    public function setUpdatedAt($updated_at)
    {
        $this->updated_at = $updated_at;
    }
 
    public function getDate($format = null)
    {
        if ($format) {
            $format = $this->getDi()->get('helper')->getDateFormat();
            if ($this->date) {
                return date($format, $this->date);
            }
        }
 
        return $this->date;
    }
 
    public function setDate($date)
    {
        $this->date = $date;
    }
 
    public function getTypeId()
    {
        return $this->type_id;
    }
 
    public function setTypeId($type_id)
    {
        $this->type_id = $type_id;
    }
 
    public function getTypeTitle()
    {
        if ($this->type_id) {
            $types = Type::cachedListArray(['key' => 'id']);
            if (array_key_exists($this->type_id, $types)) {
                return $types[$this->type_id];
            }
        }
    }
 
    public function getTypeSlug()
    {
        if ($this->type_id) {
            $types = Type::cachedListArray(['key' => 'id', 'value' => 'slug']);
            if (array_key_exists($this->type_id, $types)) {
                return $types[$this->type_id];
            }
        }
    }
 
    /**
     * @return mixed
     */
    public function getCoverPhoto()
    {
        return $this->getMLVariable('cover_photo');
    }
 
    /**
     * @param mixed $cover_photo
     */
    public function setCover_Photo($cover_photo)
    {
        $this->setMLVariable('cover_photo', $cover_photo);
    }
 
    public function getPreviewInner()
    {
        return $this->getMLVariable('preview_inner');
    }
 
    public function setPreviewInner($preview_inner)
    {
        $this->setMLVariable('preview_inner', $preview_inner);
    }
 
    /**
     * @return mixed
     */
    public function getThumbnailPhoto()
    {
        return $this->getPreviewSrc();
    }
 
    public function getPreviewSrc()
    {
        return $this->getMLVariable('preview_src');
    }
 
    public function setPreview_Src($preview_src)
    {
        $this->setMLVariable('preview_src', $preview_src);
    }
 
}
#3Publication\Model\Publication::findCachedBySlug(university-college-fair-2019)
/var/www/html/ciss/cis.edu.vn/app/modules/Publication/Controller/IndexController.php (79)
<?php
 
namespace Publication\Controller;
 
use Application\Mvc\Controller;
use Page\Model\Page;
use Phalcon\Exception;
use Publication\Model\Publication;
use Publication\Model\Type;
 
class IndexController extends Controller
{
 
  public function indexAction ()
  {
    $this->view->bodyClass = 'page publications';
 
    $type = $this->dispatcher->getParam('type', 'string');
 
    $page = Page::findCachedBySlug($type);
 
    if (!$page) {
      throw new Exception("Page '$type.html' not found");
    }
    $this->view->page = $page;
 
    $this->helper->activeMenu()->setActive($page->getSlug());
 
    $typeModel = \Publication\Model\Type::findFirstById($page->getModuleCategory());
    if (!$typeModel) {
      throw new Exception("Publication hasn't type = '$page->getModuleCategory()'");
    }
 
    $typeLimit = ($typeModel->getLimit()) ? $typeModel->getLimit() : $this->registry['cms']['PAGE_LIMIT'];
    $limit = $this->request->getQuery('limit', 'string', $typeLimit);
    if ($limit != 'all') {
      $paginatorLimit = (int)$limit;
    } else {
      $paginatorLimit = 9999;
    }
    $page_num = $this->request->getQuery('page', 'int', 1);
 
    $publications = Publication::find(array(
      "type_id = {$typeModel->getId()}",
      "order" => "date DESC",
    ));
 
    $paginator = new \Phalcon\Paginator\Adapter\Model(array(
      "data" => $publications,
      "limit" => $paginatorLimit,
      "page" => $page_num
    ));
 
    $this->view->paginate = $paginator->getPaginate();
 
    $this->helper->title()->append($typeModel->getHead_title());
    $this->view->title = $typeModel->getTitle();
    $this->view->format = $typeModel->getFormat();
    $this->view->type = $page->getModuleCategory();
 
    $this->helper->activeMenu()->setActive($page->getId() . $type);
    $this->setPageMeta($page);
  }
 
  public function publicationAction ()
  {
    $this->view->bodyClass = 'page publications publication';
 
    $slug = $this->dispatcher->getParam('slug', 'string');
    $module_category = $this->dispatcher->getParam('type', 'string');
 
    $page_slug = $module_category;
    $page = Page::findCachedBySlug($page_slug);
    if (!$page) {
      throw new Exception("Page '$slug.html' not found");
    }
    $this->view->page = $page;
 
    $publication = Publication::findCachedBySlug($slug);
    if (!$publication) {
      throw new Exception("Publication '$slug.html' not found");
    }
 
    $this->helper->title()->append($publication->getMetaTitle());
    $this->view->publication = $publication;
    $this->helper->activeMenu()->setActive($page->getId() . $page_slug);
    $this->setPageMeta($publication);
  }
}
#4Publication\Controller\IndexController->publicationAction(upcoming-events, university-college-fair-2019)
#5Phalcon\Dispatcher->dispatch()
/var/www/html/ciss/cis.edu.vn/app/Bootstrap.php (357)
<?php
 
namespace YonaCMS;
 
/**
 * Bootstrap
 *
 * @copyright Copyright (c) 2011 - 2014 Aleksandr Torosh (http://wezoom.com.ua)
 * @author    Aleksandr Torosh <webtorua@gmail.com>
 */
class Bootstrap
{
 
  public function run()
  {
    $di = new \Phalcon\DI\FactoryDefault();
 
    // Config
    require_once APPLICATION_PATH . '/modules/Cms/Config.php';
    $config = \Cms\Config::get();
    $di->set('config', $config);
 
    // Registry
    $registry = new \Phalcon\Registry();
    $di->set('registry', $registry);
 
    // Loader
    $loader = new \Phalcon\Loader();
    $loader->registerNamespaces($config->loader->namespaces->toArray());
    $loader->registerDirs([APPLICATION_PATH . "/plugins/"]);
    $loader->register();
    require_once APPLICATION_PATH . '/../vendor/autoload.php';
 
    // Database
    $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,
    ]);
    $di->set('db', $db);
 
    // View
    $this->initView($di);
 
    // URL
    $url = new \Phalcon\Mvc\Url();
    $url->setBasePath($config->base_path);
    $url->setBaseUri($config->base_path);
    $di->set('url', $url);
 
    // Cache
    $this->initCache($di);
 
    // CMS
    $cmsModel = new \Cms\Model\Configuration();
    $registry->cms = $cmsModel->getConfig(); // Отправляем в Registry
 
    // Application
    $application = new \Phalcon\Mvc\Application();
    $application->registerModules($config->modules->toArray());
 
    // Events Manager, Dispatcher
    $this->initEventManager($di);
 
    // Session
    $session = new \Phalcon\Session\Adapter\Files();
    $session->start();
    $di->set('session', $session);
 
    $acl = new \Application\Acl\DefaultAcl();
    $di->set('acl', $acl);
 
    // JS Assets
    $this->initAssetsManager($di);
 
    // Flash helper
    $flash = new \Phalcon\Flash\Session([
      'error'   => 'alert alert-danger',
      'success' => 'alert alert-success',
      'notice'  => 'alert alert-info',
      'warning' => 'alert alert-warning',
    ]);
    $di->set('flash', $flash);
 
    $di->set('helper', new \Application\Mvc\Helper());
 
 
    /**
     * Custom DI
     */
    $di->set('email', function () {
      return new \Application\Mvc\EmailHelper();
    });
 
    // Routing
    $this->initRouting($application, $di);
 
    $application->setDI($di);
 
    // Main dispatching process
    $this->dispatch($di);
 
  }
 
  private function initView($di)
  {
    $view = new \Phalcon\Mvc\View();
 
    $theme = $di->get('config')['theme'];
    if ($theme) {
      $themePath = __DIR__ . '/themes/' . $di->get('config')['theme'] . '/';
      if (file_exists($themePath)) {
        define('MAIN_VIEW_PATH', '../../../themes/' . $theme . '/');
      }
    } else {
      define('MAIN_VIEW_PATH', '../../../views/');
    }
 
    $view->setMainView(MAIN_VIEW_PATH . 'main');
    $view->setLayoutsDir(MAIN_VIEW_PATH . '/layouts/');
    $view->setLayout('main');
    $view->setPartialsDir(MAIN_VIEW_PATH . '/partials/');
 
    // Volt
    $volt = new \Application\Mvc\View\Engine\Volt($view, $di);
    $volt->setOptions(['compiledPath' => APPLICATION_PATH . '/../data/cache/volt/']);
    $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);
    }
 
    $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 'file':
        $cache = new \Phalcon\Cache\Backend\File($cacheFrontend, [
          "cacheDir" => APPLICATION_PATH . "/../data/cache/backend/",
        ]);
        break;
      case 'memcache':
        $cache = new \Phalcon\Cache\Backend\Memcache(
          $cacheFrontend, [
          "host" => $config->memcache->host,
          "port" => $config->memcache->port,
        ]);
        break;
    }
    $di->set('cache', $cache, true);
    $di->set('modelsCache', $cache, true);
 
    \Application\Widget\Proxy::$cache = $cache; // Modules Widget System
 
    $modelsMetadata = new \Phalcon\Mvc\Model\Metadata\Memory();
    $di->set('modelsMetadata', $modelsMetadata);
  }
 
  private function initEventManager($di)
  {
    $eventsManager = new \Phalcon\Events\Manager();
    $dispatcher = new \Phalcon\Mvc\Dispatcher();
 
    $eventsManager->attach("dispatch:beforeDispatchLoop", function ($event, $dispatcher) use ($di) {
      new \YonaCMS\Plugin\CheckPoint($di->get('request'));
      new \YonaCMS\Plugin\Localization($dispatcher);
      new \YonaCMS\Plugin\AdminLocalization($di->get('config'));
      new \YonaCMS\Plugin\Acl($di->get('acl'), $dispatcher, $di->get('view'));
      new \YonaCMS\Plugin\MobileDetect($di->get('session'), $di->get('view'), $di->get('request'));
    });
 
    $eventsManager->attach("dispatch:afterDispatchLoop", function ($event, $dispatcher) use ($di) {
      new \Seo\Plugin\SeoManager($dispatcher, $di->get('request'), $di->get('router'), $di->get('view'));
      new \YonaCMS\Plugin\Title($di);
    });
 
    // Profiler
    $registry = $di->get('registry');
    if ($registry->cms['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();
        }
      });
    }
 
    $db = $di->get('db');
    $db->setEventsManager($eventsManager);
 
    $dispatcher->setEventsManager($eventsManager);
    $di->set('dispatcher', $dispatcher);
  }
 
  private function initAssetsManager($di)
  {
    $config = $di->get('config');
    $isProductionEnv = (APPLICATION_ENV == "production") || (APPLICATION_ENV == "stagging");
    $locator = $isProductionEnv ? ROOT . '/' : '/';
    $jsMin = $isProductionEnv ? new \Phalcon\Assets\Filters\Jsmin() : new \Phalcon\Assets\Filters\None();
    $cssMin = $isProductionEnv ? new \Phalcon\Assets\Filters\Cssmin() : new \Phalcon\Assets\Filters\None();
 
    $assetsManager = new \Application\Assets\Manager();
    if ($isProductionEnv) {
      $js_collection = $assetsManager->collection('js')
        ->setLocal(true)
        ->addFilter($jsMin)
        ->setTargetPath(ROOT . '/assets/main.js')
        ->setTargetUri('assets/main.js')
        ->join($isProductionEnv);
    } else {
      $js_collection = $assetsManager->collection('js')->setLocal(true);
    }
    if ($config->assets->js) {
      foreach ($config->assets->js as $js) {
        $js_collection->addJs($locator . $js);
      }
    }
 
    if ($isProductionEnv) {
      $css_collection = $assetsManager->collection('css')
        ->setLocal(true)
        ->addFilter($cssMin)
        ->setTargetPath(ROOT . '/assets/main.min.css')
        ->setTargetUri('/assets/main.min.css')
        ->join($isProductionEnv);
    } else {
      $css_collection = $assetsManager->collection('css')->setLocal(true);
    }
    if ($config->assets->css) {
      foreach ($config->assets->css as $css) {
        $css_collection->addCss($locator . $css);
      }
    }
 
    // Admin JS Assets
    $assetsManager->collection('modules-admin-js')
      ->setLocal(true)
      ->addFilter(new \Phalcon\Assets\Filters\Jsmin())
      ->setTargetPath(ROOT . '/assets/modules-admin.js')
      ->setTargetUri('assets/modules-admin.js')
      ->join(true);
 
    // Admin LESS Assets
    $assetsManager->collection('modules-admin-less')
      ->setLocal(true)
      ->addFilter(new \Application\Assets\Filter\Less())
      ->setTargetPath(ROOT . '/assets/modules-admin.less')
      ->setTargetUri('assets/modules-admin.less')
      ->join(true)
      ->addCss(APPLICATION_PATH . '/modules/Admin/assets/admin.less');
 
    $di->set('assets', $assetsManager);
    $admin_js_collection = $assetsManager->collection('admin_js')->join($isProductionEnv);
    if ($config->assets->admin_js) {
      foreach ($config->assets->admin_js as $js) {
        $admin_js_collection->addJs('/' . $js);
      }
    }
 
    $admin_css_collection = $assetsManager->collection('admin_css')->setLocal(true);
    if ($config->assets->admin_css) {
      foreach ($config->assets->admin_css as $css) {
        $admin_css_collection->addCss('/' . $css);
      }
    }
  }
 
  private function initRouting($application, $di)
  {
    $router = new \Application\Mvc\Router\DefaultRouter();
    $router->setDi($di);
    foreach ($application->getModules() as $module) {
      $routesClassName = str_replace('Module', 'Routes', $module['className']);
      if (class_exists($routesClassName)) {
        $routesClass = new $routesClassName();
        $router = $routesClass->init($router);
      }
      $initClassName = str_replace('Module', 'Init', $module['className']);
      if (class_exists($initClassName)) {
        new $initClassName();
      }
    }
    $di->set('router', $router);
  }
 
  private function dispatch($di)
  {
    $router = $di['router'];
 
    $router->handle();
 
    $view = $di['view'];
 
    $dispatcher = $di['dispatcher'];
 
    $response = $di['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);
 
      $theme = $di->get('config')['theme'];
      if ($theme) {
        $themePath = '/themes/' . $di->get('config')['theme'] . '/' . $moduleName . '/';
        if (file_exists($themePath)) {
          $view->setViewsDir(__DIR__ . $themePath);
        }
      }
    }
 
    $view->start();
 
    $registry = $di['registry'];
    if ($registry->cms['DEBUG_MODE']) {
      $debug = new \Phalcon\Debug();
      $debug->listen();
 
      $dispatcher->dispatch();
    } else {
      try {
        $dispatcher->dispatch();
      } catch (\Phalcon\Exception $e) {
        // Errors catching
 
        $view->setViewsDir(__DIR__ . '/modules/Index/views/');
        $view->setPartialsDir('');
        $view->e = $e;
 
        if ($e instanceof \Phalcon\Mvc\Dispatcher\Exception) {
          $response->setHeader(404, 'Not Found');
          $view->partial('error/error404');
        } else {
          $response->setHeader(503, 'Service Unavailable');
          $view->partial('error/error503');
        }
        $response->sendHeaders();
        echo $response->getContent();
 
        return;
 
      }
    }
 
    $view->render(
      $dispatcher->getControllerName(),
      $dispatcher->getActionName(),
      $dispatcher->getParams()
    );
 
    $view->finish();
 
    $response = $di['response'];
 
    // AJAX
    $request = $di['request'];
    $_ajax = $request->getQuery('_ajax');
    if ($_ajax) {
      $contents = $view->getContent();
 
      $return = new \stdClass();
      $return->html = $contents;
      $return->title = $di->get('helper')->title()->get();
      $return->success = true;
 
      if ($view->bodyClass) {
        $return->bodyClass = $view->bodyClass;
      }
 
      $headers = $response->getHeaders()->toArray();
      if (isset($headers[404]) || isset($headers[503])) {
        $return->success = false;
      }
      $response->setContentType('application/json', 'UTF-8');
      $response->setContent(json_encode($return));
    } else {
      $response->setContent($view->getContent());
    }
 
    $response->sendHeaders();
 
    echo $response->getContent();
  }
 
}
#6YonaCMS\Bootstrap->dispatch(Object(Phalcon\Di\FactoryDefault))
/var/www/html/ciss/cis.edu.vn/app/Bootstrap.php (103)
<?php
 
namespace YonaCMS;
 
/**
 * Bootstrap
 *
 * @copyright Copyright (c) 2011 - 2014 Aleksandr Torosh (http://wezoom.com.ua)
 * @author    Aleksandr Torosh <webtorua@gmail.com>
 */
class Bootstrap
{
 
  public function run()
  {
    $di = new \Phalcon\DI\FactoryDefault();
 
    // Config
    require_once APPLICATION_PATH . '/modules/Cms/Config.php';
    $config = \Cms\Config::get();
    $di->set('config', $config);
 
    // Registry
    $registry = new \Phalcon\Registry();
    $di->set('registry', $registry);
 
    // Loader
    $loader = new \Phalcon\Loader();
    $loader->registerNamespaces($config->loader->namespaces->toArray());
    $loader->registerDirs([APPLICATION_PATH . "/plugins/"]);
    $loader->register();
    require_once APPLICATION_PATH . '/../vendor/autoload.php';
 
    // Database
    $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,
    ]);
    $di->set('db', $db);
 
    // View
    $this->initView($di);
 
    // URL
    $url = new \Phalcon\Mvc\Url();
    $url->setBasePath($config->base_path);
    $url->setBaseUri($config->base_path);
    $di->set('url', $url);
 
    // Cache
    $this->initCache($di);
 
    // CMS
    $cmsModel = new \Cms\Model\Configuration();
    $registry->cms = $cmsModel->getConfig(); // Отправляем в Registry
 
    // Application
    $application = new \Phalcon\Mvc\Application();
    $application->registerModules($config->modules->toArray());
 
    // Events Manager, Dispatcher
    $this->initEventManager($di);
 
    // Session
    $session = new \Phalcon\Session\Adapter\Files();
    $session->start();
    $di->set('session', $session);
 
    $acl = new \Application\Acl\DefaultAcl();
    $di->set('acl', $acl);
 
    // JS Assets
    $this->initAssetsManager($di);
 
    // Flash helper
    $flash = new \Phalcon\Flash\Session([
      'error'   => 'alert alert-danger',
      'success' => 'alert alert-success',
      'notice'  => 'alert alert-info',
      'warning' => 'alert alert-warning',
    ]);
    $di->set('flash', $flash);
 
    $di->set('helper', new \Application\Mvc\Helper());
 
 
    /**
     * Custom DI
     */
    $di->set('email', function () {
      return new \Application\Mvc\EmailHelper();
    });
 
    // Routing
    $this->initRouting($application, $di);
 
    $application->setDI($di);
 
    // Main dispatching process
    $this->dispatch($di);
 
  }
 
  private function initView($di)
  {
    $view = new \Phalcon\Mvc\View();
 
    $theme = $di->get('config')['theme'];
    if ($theme) {
      $themePath = __DIR__ . '/themes/' . $di->get('config')['theme'] . '/';
      if (file_exists($themePath)) {
        define('MAIN_VIEW_PATH', '../../../themes/' . $theme . '/');
      }
    } else {
      define('MAIN_VIEW_PATH', '../../../views/');
    }
 
    $view->setMainView(MAIN_VIEW_PATH . 'main');
    $view->setLayoutsDir(MAIN_VIEW_PATH . '/layouts/');
    $view->setLayout('main');
    $view->setPartialsDir(MAIN_VIEW_PATH . '/partials/');
 
    // Volt
    $volt = new \Application\Mvc\View\Engine\Volt($view, $di);
    $volt->setOptions(['compiledPath' => APPLICATION_PATH . '/../data/cache/volt/']);
    $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);
    }
 
    $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 'file':
        $cache = new \Phalcon\Cache\Backend\File($cacheFrontend, [
          "cacheDir" => APPLICATION_PATH . "/../data/cache/backend/",
        ]);
        break;
      case 'memcache':
        $cache = new \Phalcon\Cache\Backend\Memcache(
          $cacheFrontend, [
          "host" => $config->memcache->host,
          "port" => $config->memcache->port,
        ]);
        break;
    }
    $di->set('cache', $cache, true);
    $di->set('modelsCache', $cache, true);
 
    \Application\Widget\Proxy::$cache = $cache; // Modules Widget System
 
    $modelsMetadata = new \Phalcon\Mvc\Model\Metadata\Memory();
    $di->set('modelsMetadata', $modelsMetadata);
  }
 
  private function initEventManager($di)
  {
    $eventsManager = new \Phalcon\Events\Manager();
    $dispatcher = new \Phalcon\Mvc\Dispatcher();
 
    $eventsManager->attach("dispatch:beforeDispatchLoop", function ($event, $dispatcher) use ($di) {
      new \YonaCMS\Plugin\CheckPoint($di->get('request'));
      new \YonaCMS\Plugin\Localization($dispatcher);
      new \YonaCMS\Plugin\AdminLocalization($di->get('config'));
      new \YonaCMS\Plugin\Acl($di->get('acl'), $dispatcher, $di->get('view'));
      new \YonaCMS\Plugin\MobileDetect($di->get('session'), $di->get('view'), $di->get('request'));
    });
 
    $eventsManager->attach("dispatch:afterDispatchLoop", function ($event, $dispatcher) use ($di) {
      new \Seo\Plugin\SeoManager($dispatcher, $di->get('request'), $di->get('router'), $di->get('view'));
      new \YonaCMS\Plugin\Title($di);
    });
 
    // Profiler
    $registry = $di->get('registry');
    if ($registry->cms['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();
        }
      });
    }
 
    $db = $di->get('db');
    $db->setEventsManager($eventsManager);
 
    $dispatcher->setEventsManager($eventsManager);
    $di->set('dispatcher', $dispatcher);
  }
 
  private function initAssetsManager($di)
  {
    $config = $di->get('config');
    $isProductionEnv = (APPLICATION_ENV == "production") || (APPLICATION_ENV == "stagging");
    $locator = $isProductionEnv ? ROOT . '/' : '/';
    $jsMin = $isProductionEnv ? new \Phalcon\Assets\Filters\Jsmin() : new \Phalcon\Assets\Filters\None();
    $cssMin = $isProductionEnv ? new \Phalcon\Assets\Filters\Cssmin() : new \Phalcon\Assets\Filters\None();
 
    $assetsManager = new \Application\Assets\Manager();
    if ($isProductionEnv) {
      $js_collection = $assetsManager->collection('js')
        ->setLocal(true)
        ->addFilter($jsMin)
        ->setTargetPath(ROOT . '/assets/main.js')
        ->setTargetUri('assets/main.js')
        ->join($isProductionEnv);
    } else {
      $js_collection = $assetsManager->collection('js')->setLocal(true);
    }
    if ($config->assets->js) {
      foreach ($config->assets->js as $js) {
        $js_collection->addJs($locator . $js);
      }
    }
 
    if ($isProductionEnv) {
      $css_collection = $assetsManager->collection('css')
        ->setLocal(true)
        ->addFilter($cssMin)
        ->setTargetPath(ROOT . '/assets/main.min.css')
        ->setTargetUri('/assets/main.min.css')
        ->join($isProductionEnv);
    } else {
      $css_collection = $assetsManager->collection('css')->setLocal(true);
    }
    if ($config->assets->css) {
      foreach ($config->assets->css as $css) {
        $css_collection->addCss($locator . $css);
      }
    }
 
    // Admin JS Assets
    $assetsManager->collection('modules-admin-js')
      ->setLocal(true)
      ->addFilter(new \Phalcon\Assets\Filters\Jsmin())
      ->setTargetPath(ROOT . '/assets/modules-admin.js')
      ->setTargetUri('assets/modules-admin.js')
      ->join(true);
 
    // Admin LESS Assets
    $assetsManager->collection('modules-admin-less')
      ->setLocal(true)
      ->addFilter(new \Application\Assets\Filter\Less())
      ->setTargetPath(ROOT . '/assets/modules-admin.less')
      ->setTargetUri('assets/modules-admin.less')
      ->join(true)
      ->addCss(APPLICATION_PATH . '/modules/Admin/assets/admin.less');
 
    $di->set('assets', $assetsManager);
    $admin_js_collection = $assetsManager->collection('admin_js')->join($isProductionEnv);
    if ($config->assets->admin_js) {
      foreach ($config->assets->admin_js as $js) {
        $admin_js_collection->addJs('/' . $js);
      }
    }
 
    $admin_css_collection = $assetsManager->collection('admin_css')->setLocal(true);
    if ($config->assets->admin_css) {
      foreach ($config->assets->admin_css as $css) {
        $admin_css_collection->addCss('/' . $css);
      }
    }
  }
 
  private function initRouting($application, $di)
  {
    $router = new \Application\Mvc\Router\DefaultRouter();
    $router->setDi($di);
    foreach ($application->getModules() as $module) {
      $routesClassName = str_replace('Module', 'Routes', $module['className']);
      if (class_exists($routesClassName)) {
        $routesClass = new $routesClassName();
        $router = $routesClass->init($router);
      }
      $initClassName = str_replace('Module', 'Init', $module['className']);
      if (class_exists($initClassName)) {
        new $initClassName();
      }
    }
    $di->set('router', $router);
  }
 
  private function dispatch($di)
  {
    $router = $di['router'];
 
    $router->handle();
 
    $view = $di['view'];
 
    $dispatcher = $di['dispatcher'];
 
    $response = $di['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);
 
      $theme = $di->get('config')['theme'];
      if ($theme) {
        $themePath = '/themes/' . $di->get('config')['theme'] . '/' . $moduleName . '/';
        if (file_exists($themePath)) {
          $view->setViewsDir(__DIR__ . $themePath);
        }
      }
    }
 
    $view->start();
 
    $registry = $di['registry'];
    if ($registry->cms['DEBUG_MODE']) {
      $debug = new \Phalcon\Debug();
      $debug->listen();
 
      $dispatcher->dispatch();
    } else {
      try {
        $dispatcher->dispatch();
      } catch (\Phalcon\Exception $e) {
        // Errors catching
 
        $view->setViewsDir(__DIR__ . '/modules/Index/views/');
        $view->setPartialsDir('');
        $view->e = $e;
 
        if ($e instanceof \Phalcon\Mvc\Dispatcher\Exception) {
          $response->setHeader(404, 'Not Found');
          $view->partial('error/error404');
        } else {
          $response->setHeader(503, 'Service Unavailable');
          $view->partial('error/error503');
        }
        $response->sendHeaders();
        echo $response->getContent();
 
        return;
 
      }
    }
 
    $view->render(
      $dispatcher->getControllerName(),
      $dispatcher->getActionName(),
      $dispatcher->getParams()
    );
 
    $view->finish();
 
    $response = $di['response'];
 
    // AJAX
    $request = $di['request'];
    $_ajax = $request->getQuery('_ajax');
    if ($_ajax) {
      $contents = $view->getContent();
 
      $return = new \stdClass();
      $return->html = $contents;
      $return->title = $di->get('helper')->title()->get();
      $return->success = true;
 
      if ($view->bodyClass) {
        $return->bodyClass = $view->bodyClass;
      }
 
      $headers = $response->getHeaders()->toArray();
      if (isset($headers[404]) || isset($headers[503])) {
        $return->success = false;
      }
      $response->setContentType('application/json', 'UTF-8');
      $response->setContent(json_encode($return));
    } else {
      $response->setContent($view->getContent());
    }
 
    $response->sendHeaders();
 
    echo $response->getContent();
  }
 
}
#7YonaCMS\Bootstrap->run()
/var/www/html/ciss/cis.edu.vn/public/index.php (22)
<?php
chdir(dirname(__DIR__));
 
define('ROOT', __DIR__);
define('HOST_HASH', substr(md5($_SERVER['HTTP_HOST']), 0, 12));
 
defined('APPLICATION_ENV') || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
 
define('APPLICATION_PATH', __DIR__ . '/../app');
 
if (APPLICATION_ENV === 'development' || APPLICATION_ENV === 'staging') {
  //@TODO: fixed me by update docker to allow config php.ini
  error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT);
 
  ini_set('display_errors', 1);
  ini_set('display_startup_errors', 1);
  ini_set('log_errors', 0);
}
 
require_once APPLICATION_PATH . '/Bootstrap.php';
$bootstrap = new YonaCMS\Bootstrap();
$bootstrap->run();
KeyValue
_url/news/upcoming-events/university-college-fair-2019.html
KeyValue
REDIRECT_APPLICATION_ENVproduction
REDIRECT_downgrade-1_0
REDIRECT_STATUS200
APPLICATION_ENVproduction
downgrade-1_0
HTTP_USER_AGENTCCBot/2.0 (https://commoncrawl.org/faq/)
HTTP_ACCEPTtext/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
HTTP_ACCEPT_LANGUAGEen-US,en;q=0.5
HTTP_IF_MODIFIED_SINCEFri, 22 Nov 2019 17:25:22 PST
HTTP_ACCEPT_ENCODINGbr,gzip
HTTP_HOSTcis.edu.vn
HTTP_CONNECTIONKeep-Alive
PATH/sbin:/usr/sbin:/bin:/usr/bin
SERVER_SIGNATURE<address>Apache/2.2.15 (CentOS) Server at cis.edu.vn Port 80</address>\n
SERVER_SOFTWAREApache/2.2.15 (CentOS)
SERVER_NAMEcis.edu.vn
SERVER_ADDR172.16.254.4
SERVER_PORT80
REMOTE_ADDR3.83.32.171
DOCUMENT_ROOT/var/www/html/ciss/cis.edu.vn/public
SERVER_ADMINdinhhoaibao@gmail.com
SCRIPT_FILENAME/var/www/html/ciss/cis.edu.vn/public/index.php
REMOTE_PORT45518
REDIRECT_QUERY_STRING_url=/news/upcoming-events/university-college-fair-2019.html
REDIRECT_URL/news/upcoming-events/university-college-fair-2019.html
GATEWAY_INTERFACECGI/1.1
SERVER_PROTOCOLHTTP/1.1
REQUEST_METHODGET
QUERY_STRING_url=/news/upcoming-events/university-college-fair-2019.html
REQUEST_URI/news/upcoming-events/university-college-fair-2019.html
SCRIPT_NAME/index.php
PHP_SELF/index.php
REQUEST_TIME_FLOAT1579797964.642
REQUEST_TIME1579797964
#Path
0/var/www/html/ciss/cis.edu.vn/public/index.php
1/var/www/html/ciss/cis.edu.vn/app/Bootstrap.php
2/var/www/html/ciss/cis.edu.vn/app/modules/Cms/Config.php
3/var/www/html/ciss/cis.edu.vn/app/config/environment/production.php
4/var/www/html/ciss/cis.edu.vn/app/config/global.php
5/var/www/html/ciss/cis.edu.vn/app/config/modules.php
6/var/www/html/ciss/cis.edu.vn/app/modules/Application/Loader/Modules.php
7/var/www/html/ciss/cis.edu.vn/vendor/autoload.php
8/var/www/html/ciss/cis.edu.vn/vendor/composer/autoload_real.php
9/var/www/html/ciss/cis.edu.vn/vendor/composer/ClassLoader.php
10/var/www/html/ciss/cis.edu.vn/vendor/composer/autoload_static.php
11/var/www/html/ciss/cis.edu.vn/vendor/symfony/polyfill-mbstring/bootstrap.php
12/var/www/html/ciss/cis.edu.vn/vendor/donatj/phpuseragentparser/Source/UserAgentParser.php
13/var/www/html/ciss/cis.edu.vn/app/modules/Application/Mvc/View/Engine/Volt.php
14/var/www/html/ciss/cis.edu.vn/app/modules/Application/Widget/Proxy.php
15/var/www/html/ciss/cis.edu.vn/app/modules/Cms/Model/Configuration.php
16/var/www/html/ciss/cis.edu.vn/app/modules/Application/Acl/DefaultAcl.php
17/var/www/html/ciss/cis.edu.vn/app/config/acl.php
18/var/www/html/ciss/cis.edu.vn/app/modules/Application/Assets/Manager.php
19/var/www/html/ciss/cis.edu.vn/app/modules/Application/Assets/Filter/Less.php
20/var/www/html/ciss/cis.edu.vn/app/modules/Application/Mvc/Helper.php
21/var/www/html/ciss/cis.edu.vn/app/modules/Menu/Helper/Menu.php
22/var/www/html/ciss/cis.edu.vn/app/modules/Application/Mvc/Router/DefaultRouter.php
23/var/www/html/ciss/cis.edu.vn/app/modules/Index/Routes.php
24/var/www/html/ciss/cis.edu.vn/app/modules/Application/Mvc/Helper/CmsCache.php
25/var/www/html/ciss/cis.edu.vn/app/modules/Admin/Routes.php
26/var/www/html/ciss/cis.edu.vn/app/modules/Staff/Routes.php
27/var/www/html/ciss/cis.edu.vn/app/modules/Staff/Model/Type.php
28/var/www/html/ciss/cis.edu.vn/app/modules/Application/Mvc/Model/Model.php
29/var/www/html/ciss/cis.edu.vn/app/modules/Widget/Routes.php
30/var/www/html/ciss/cis.edu.vn/app/modules/Page/Routes.php
31/var/www/html/ciss/cis.edu.vn/app/modules/Page/Model/Page.php
32/var/www/html/ciss/cis.edu.vn/app/modules/Publication/Routes.php
33/var/www/html/ciss/cis.edu.vn/app/modules/Publication/Model/Type.php
34/var/www/html/ciss/cis.edu.vn/app/modules/Slider/Routes.php
35/var/www/html/ciss/cis.edu.vn/app/modules/Seo/Routes.php
36/var/www/html/ciss/cis.edu.vn/app/modules/Menu/Routes.php
37/var/www/html/ciss/cis.edu.vn/app/modules/Menu/Model/Type.php
38/var/www/html/ciss/cis.edu.vn/app/modules/Tree/Routes.php
39/var/www/html/ciss/cis.edu.vn/app/modules/Tree/Init.php
40/var/www/html/ciss/cis.edu.vn/app/modules/Tree/Mvc/Helper.php
41/var/www/html/ciss/cis.edu.vn/app/modules/Sitemap/Routes.php
42/var/www/html/ciss/cis.edu.vn/app/modules/Popup/Routes.php
43/var/www/html/ciss/cis.edu.vn/app/modules/Subscribe/Routes.php
44/var/www/html/ciss/cis.edu.vn/app/modules/Application/Utils/ModuleName.php
45/var/www/html/ciss/cis.edu.vn/app/modules/Publication/Module.php
46/var/www/html/ciss/cis.edu.vn/app/plugins/CheckPoint.php
47/var/www/html/ciss/cis.edu.vn/app/plugins/Localization.php
48/var/www/html/ciss/cis.edu.vn/app/modules/Cms/Model/Translate.php
49/var/www/html/ciss/cis.edu.vn/app/plugins/AdminLocalization.php
50/var/www/html/ciss/cis.edu.vn/data/translations/admin/en.php
51/var/www/html/ciss/cis.edu.vn/app/plugins/Acl.php
52/var/www/html/ciss/cis.edu.vn/app/plugins/MobileDetect.php
53/var/www/html/ciss/cis.edu.vn/vendor/mobiledetect/mobiledetectlib/Mobile_Detect.php
54/var/www/html/ciss/cis.edu.vn/app/modules/Publication/Controller/IndexController.php
55/var/www/html/ciss/cis.edu.vn/app/modules/Application/Mvc/Controller.php
56/var/www/html/ciss/cis.edu.vn/app/modules/Page/Model/Translate/PageTranslate.php
57/var/www/html/ciss/cis.edu.vn/app/modules/Application/Mvc/Model/Translate.php
58/var/www/html/ciss/cis.edu.vn/app/modules/Publication/Model/Publication.php
Memory
Usage1835008