/**
  * Returns array of loaded legacy templates
  *
  * @param \Closure $legacyKernel
  *
  * @return array
  */
 public static function getLegacyTemplatesList(\Closure $legacyKernel)
 {
     $templateList = array('compact' => array(), 'full' => array());
     // Only retrieve legacy templates list if the kernel has been booted at least once.
     if (!LegacyKernel::hasInstance()) {
         return $templateList;
     }
     try {
         $templateStats = $legacyKernel()->runCallback(function () {
             return eZTemplate::templatesUsageStatistics();
         }, false, false);
     } catch (RuntimeException $e) {
         // Ignore the exception thrown by legacy kernel as this would break debug toolbar (and thus debug info display).
         // Furthermore, some legacy kernel handlers don't support runCallback (e.g. ezpKernelTreeMenu)
         $templateStats = array();
     }
     foreach ($templateStats as $tplInfo) {
         $requestedTpl = $tplInfo["requested-template-name"];
         $actualTpl = $tplInfo["actual-template-name"];
         $fullPath = $tplInfo["template-filename"];
         $templateList["full"][$actualTpl] = array("loaded" => $requestedTpl, "fullPath" => $fullPath);
         if (!isset($templateList["compact"][$actualTpl])) {
             $templateList["compact"][$actualTpl] = 1;
         } else {
             $templateList["compact"][$actualTpl]++;
         }
     }
     return $templateList;
 }
 /**
  * Returns array of loaded legacy templates
  *
  * @param \Closure $legacyKernel
  *
  * @return array
  */
 public static function getLegacyTemplatesList(\Closure $legacyKernel)
 {
     $templateList = array('compact' => array(), 'full' => array());
     // Only retrieve legacy templates list if the kernel has been booted at least once.
     if (!LegacyKernel::hasInstance()) {
         return $templateList;
     }
     $formTokenWasEnabled = false;
     try {
         // Deactivate ezxFormToken to avoid double checks on it.
         // Checking on ezxFormToken existence since might not be loadable if eZ is not yet installed
         // (ezp_extension.php not yet generated in legacy).
         if (class_exists('ezxFormToken') && ($formTokenWasEnabled = ezxFormToken::isEnabled())) {
             ezxFormToken::setIsEnabled(false);
         }
         $templateStats = $legacyKernel()->runCallback(function () {
             return eZTemplate::templatesUsageStatistics();
         });
     } catch (RuntimeException $e) {
         // Ignore the exception thrown by legacy kernel as this would break debug toolbar (and thus debug info display).
         // Furthermore, some legacy kernel handlers don't support runCallback (e.g. ezpKernelTreeMenu)
         $templateStats = array();
         if ($formTokenWasEnabled) {
             ezxFormToken::setIsEnabled(true);
         }
     }
     foreach ($templateStats as $tplInfo) {
         $requestedTpl = $tplInfo["requested-template-name"];
         $actualTpl = $tplInfo["actual-template-name"];
         $fullPath = $tplInfo["template-filename"];
         $templateList["full"][$actualTpl] = array("loaded" => $requestedTpl, "fullPath" => $fullPath);
         if (!isset($templateList["compact"][$actualTpl])) {
             $templateList["compact"][$actualTpl] = 1;
         } else {
             $templateList["compact"][$actualTpl]++;
         }
     }
     // Re-activate ezxFormToken if it was before, as we might be inside an inline sub-request.
     // See https://jira.ez.no/browse/EZP-22643
     if ($formTokenWasEnabled) {
         ezxFormToken::setIsEnabled(true);
     }
     return $templateList;
 }
Example #3
0
 /**
  * Builds up the legacy kernel and encapsulates it inside a closure, allowing lazy loading.
  *
  * @param \ezpKernelHandler|\Closure A kernel handler instance or a closure returning a kernel handler instance
  *
  * @return \Closure
  */
 public function buildLegacyKernel($legacyKernelHandler)
 {
     $legacyRootDir = $this->legacyRootDir;
     $webrootDir = $this->webrootDir;
     $eventDispatcher = $this->eventDispatcher;
     $logger = $this->logger;
     $that = $this;
     return function () use($legacyKernelHandler, $legacyRootDir, $webrootDir, $eventDispatcher, $logger, $that) {
         if (LegacyKernel::hasInstance()) {
             return LegacyKernel::instance();
         }
         if ($legacyKernelHandler instanceof \Closure) {
             $legacyKernelHandler = $legacyKernelHandler();
         }
         $legacyKernel = new LegacyKernel($legacyKernelHandler, $legacyRootDir, $webrootDir, $logger);
         if ($that->getBuildEventsEnabled()) {
             $eventDispatcher->dispatch(LegacyEvents::POST_BUILD_LEGACY_KERNEL, new PostBuildKernelEvent($legacyKernel, $legacyKernelHandler));
         }
         return $legacyKernel;
     };
 }
Example #4
0
 /**
  * Resets the legacy kernel instances from the container.
  */
 public function resetKernel()
 {
     // Reset the kernel only if it has been initialized.
     if (LegacyKernel::hasInstance()) {
         /** @var \Closure $kernelClosure */
         $kernelClosure = $this->container->get('ezpublish_legacy.kernel');
         $this->eventDispatcher->dispatch(LegacyEvents::PRE_RESET_LEGACY_KERNEL, new PreResetLegacyKernelEvent($kernelClosure()));
     }
     LegacyKernel::resetInstance();
     $this->webHandler = null;
     $this->cliHandler = null;
     $this->restHandler = null;
     $this->container->set('ezpublish_legacy.kernel.lazy', null);
     $this->container->set('ezpublish_legacy.kernel_handler.web', null);
     $this->container->set('ezpublish_legacy.kernel_handler.cli', null);
     $this->container->set('ezpublish_legacy.kernel_handler.rest', null);
 }