/** * @param $namespace * @param IOptions $iOptions */ public function __construct($namespace, IOptions $iOptions = null) { $this->namespace = $namespace; if ($iOptions) { $this->ioptions = $iOptions; } else { $this->ioptions = Container::instance()->make('CLMVC\\Interfaces\\IOptions', array($namespace)); } $this->init(); }
/** * Inject a style handler for includes. * * @param IIncludes $iStyleInclude */ public function __construct(IIncludes $iStyleInclude = null) { if ($iStyleInclude) { $this->styleInclude = $iStyleInclude; } else { $this->styleInclude = Container::instance()->fetch('CLMVC\\Interfaces\\IStyleInclude'); } $this->styleInclude->init(); Hook::register('stylesheets-register', array($this, 'registerIncludes')); }
/** * Overrides global $post and $wp_query with the rendered content from CloudLess. * Its done if is_main_query and CloudLess detected a correct and matching route. */ public function override() { global $wp_query; if ($wp_query->is_main_query() && !$this->routes->isRouted() || !$wp_query->is_main_query() && !$this->routes->isRouted() || !$wp_query->is_main_query() && $this->routes->isRouted()) { return; } $bag = Container::instance()->fetch('Bag'); $args = ['post_content' => RenderedContent::get(), 'post_title' => $bag->title, 'is_page' => true, 'guid' => $this->routes->getCurrentRoute()->getRoutePath()]; $dummy = new DummyPost($args); $dummy->overrideWpQuery(); remove_filter('the_content', 'wpautop'); unset($dummy); }
/** * Takes request uri and routes to controller. * @return bool * @throws \Exception */ public function routing() { $routes = array_merge($this->priorityRoutes, $this->routes); $uri = $_SERVER['REQUEST_URI']; $method = Communication::getMethod(); /** * @var Route $route */ foreach ($routes as $route) { $matches = $route->match($uri, $method); if ($matches) { $params = $route->params($uri, $method); $array = $route->getCallback(); $controller = str_replace('/', '\\', $array[0]); /** * @var BaseController */ $ctrl = Container::instance()->make($controller); $ctrl->init(); $action = $array[1]; if ($action == ':action') { $action = str_replace(':action', $matches['action'], $action); } try { $ctrl->executeAction($action, $params); $this->routed = true; $this->current_route = $route; } catch (\Exception $ex) { if (defined('WP_DEBUG') && WP_DEBUG) { throw $ex; } $this->routed = false; } return $this->routed; } } $this->routed = false; return $this->routed; }
/** * Checks if page is being viewed by a tablet. * @return bool */ function clmvc_is_tablet() { $mobile_detect = \CLMVC\Core\Container::instance()->fetchOrMake(\CLMVC\Helpers\MobileDetect::class); return $mobile_detect->isTablet(); }
/** * Sets initial variables etc. */ public function __construct() { $this->renderer = new Rendering($this); $this->bag = Container::instance()->fetch('Bag'); }
<?php use CLMVC\Core\Container; use CLMVC\ViewEngines\WordPress\WpEngine; use CLMVC\ViewEngines\WordPress\WpRendering; define('CLOUDLESS_APP_DIR', WP_PLUGIN_DIR); Container::instance()->fetchOrMake(WpEngine::class)->init(); Container::instance()->fetchOrMake(WpRendering::class)->init(); /** * @param string $app * @param string $url * * @return string */ if (!function_exists('clmvc_app_url')) { /** * @return string */ function clmvc_app_url($app, $url) { return plugins_url($app . '/' . $url); } }
public function setupWpContainer() { global $wpdb; $container = Container::instance(); $container->add('wpdb', $wpdb); }
public function testNoParamsConstructorWithInherit() { $c = new Container(); $sub = $c->make(SubClass::class); self::assertEquals('someparam', $sub->getSomeParam()); }
/** * @var \WP_Query $wp_query */ public function overrideWpQuery($wp_query) { /** * @var Routes $routes */ $container = Container::instance(); $routes = $container->fetch('Routes'); if (!$routes->isRouted()) { $wp_query->set('pagename', $_SERVER['REQUEST_URI']); $wp_query->is_page = false; $wp_query->is_home = false; $wp_query->is_archive = false; $wp_query->current_post = -1; $wp_query->post_count = 0; $wp_query->found_posts = 0; $wp_query->is_404 = false; } }