/** * Class constructor * * @param Application $app Application object * * @since 1.0 */ public function __construct(Application $app) { $this->app = $app; $this->db = $this->app->getContainer()->get('db'); $this->helper = new Helper(); $this->packages = $this->helper->parseComposer(); }
/** * Execute the command * * @return void * * @since 1.0 */ public function execute() { // Check if caching is enabled $twigCache = $this->app->get('template.cache', false); if ($twigCache === false) { $this->app->out('Twig caching is disabled.'); return; } // Display status $this->app->out('Resetting Twig Cache.'); // First remove the existing cache files if (is_dir(JPATH_ROOT . '/' . $twigCache)) { foreach (Folder::folders(JPATH_ROOT . '/' . $twigCache) as $folder) { Folder::delete(JPATH_ROOT . '/' . $twigCache . '/' . $folder); } } // Now get a list of all the templates $files = Folder::files(JPATH_TEMPLATES, '.twig', true, true); // Load each template now /** @var \Joomla\Renderer\TwigRenderer $twigRenderer */ $twigRenderer = $this->app->getContainer()->get('renderer'); $engine = $twigRenderer->getRenderer(); $errorFiles = []; foreach ($files as $file) { $template = str_replace(JPATH_TEMPLATES . '/', '', $file); try { $engine->loadTemplate($template); } catch (\Twig_Error $e) { $errorFiles[] = $file; } } if (count($errorFiles)) { $msg = 'The following Twig resources failed to cache: ' . implode(', ', $errorFiles); } else { $msg = 'The cached Twig resources were successfully created.'; } $this->app->out($msg); }
/** * Class constructor * * @param Application $app Application object * * @since 1.0 */ public function __construct(Application $app) { $this->app = $app; $this->config = $this->app->getContainer()->get('config'); $this->db = $this->app->getContainer()->get('db'); }