public function init() { RenderingEngines::registerEngine('php', 'CLMVC\\Controllers\\Render\\Engines\\PhpRenderingEngine'); (new WpActionOverrides())->init(); $this->setupConstants(); $this->setupContainer(); $this->setupWpContainer(); if (is_admin()) { Filter::register('after_plugin_row', [$this, 'loadCloudlessFirst'], 10); } Filter::register('status_header', [$this, 'addHeader']); }
/** * Renders a controller and its action. * * @param string $controller * @param string $action * * @throws RenderException */ public function render($controller, $action) { if (!$this->canRender()) { return; } $view_path = $this->views->findView($controller, $action, $this->getTemplate()); if ($view_path) { Hook::run('rendering-render', [$controller, strtolower($action), $this->controller]); $tags = Filter::run('view-tags', array(array(), $this->controller)); $engine = RenderingEngines::getEngine($this->getTemplate(), $this->controller->getViewPath()); $view_content = $engine->render($view_path, array_merge($this->getBag(), $tags, ['bag' => $this->getBag() + $tags])); $layout_path = $this->views->findLayout($this->getTemplate()); if ($layout_path) { $engine = RenderingEngines::getEngine($this->getTemplate(), $view_path); $view_content = $engine->render($layout_path, array_merge($this->getBag(), $tags, ['bag' => $this->getBag() + $tags], Filter::run("{$this->controllerName}-{$action}-blocks", array(array('view' => $view_content))))); } $this->disableRendering(); RenderedContent::set($view_content); return; } $view_content = "Could not find view for {$controller}, {$action} in: " . $view_path; trigger_error($view_content, E_USER_WARNING); }
<?php use CLMVC\Controllers\BaseController; use CLMVC\Controllers\Render\RenderingEngines; use CLMVC\Events\Filter; use CLMVC\Events\Hook; if (!defined('CLMVC_CACHE_PATH')) { define('CLMVC_CACHE_PATH', ABSPATH . '/cache/'); } $container = CLMVC\Core\Container::instance(); $container->add('CLMVC\\Interfaces\\IScriptInclude', new CLMVC\ViewEngines\Standard\CLMVCScriptIncludes()); $container->add('CLMVC\\Interfaces\\IStyleInclude', new CLMVC\ViewEngines\Standard\CLMVCStyleIncludes()); $container->add('CLMVC\\Interfaces\\IOptions', 'CLMVC\\ViewEngines\\Standard\\BIOptions', 'class'); $container->add('CLMVC\\Interfaces\\IOption', 'CLMVC\\ViewEngines\\Standard\\BIOption', 'class'); RenderingEngines::registerEngine('php', 'CLMVC\\Controllers\\Render\\Engines\\PhpRenderingEngine'); Filter::register('view-tags', 'clmvc_setup_default_tags'); /** * @param array $tags * @param BaseController $controller * * @return array */ function clmvc_setup_default_tags($tags, $controller) { $bag = $controller->getBag(); $tags['title'] = Filter::run('title', array($bag['title'])); $tags['stylesheets'] = implode("\n", Filter::run('stylesheets-frontend', array(array()))); $tags['javascript_footer'] = implode("\n", Filter::run('javascripts-footer-frontend', array(array()))); $tags['javascript_head'] = implode("\n", Filter::run('javascripts-head-frontend', array(array()))); return $tags; }