function _controllerApi($controllerClass, Di $di) { $controller = $di($controllerClass); $this->controller = $controller; $method = isset($this->request['method']) ? $this->request['method'] : '__invoke'; $params = isset($this->request['params']) ? $this->request['params'] : []; if (is_object($params)) { $params = $params->getArray(); } if ($method != '__invoke' && substr($method, 0, 1) == '_') { throw new \RuntimeException("Underscore prefixed method \"{$method}\" is not allowed to public api access"); } if (method_exists($controller, $method)) { if (!(new \ReflectionMethod($controller, $method))->isPublic()) { throw new \RuntimeException("The called method is not public"); } return $di->method($controller, $method, (array) $params); } }
static function getInstance() { if (!isset(self::$instance)) { if (class_exists('RedCat\\Strategy\\Di')) { self::$instance = \RedCat\Strategy\Di::getInstance()->get(__CLASS__); } else { self::$instance = new self(); } } return self::$instance; }
function load() { $this->remapAttr('domains'); $this->attr('domains', eval('return ' . $this->domains . ';')); if ($this->attr('no-cache')) { $href = "<?php echo \\RedCat\\Strategy\\Di::getInstance()->get('RedCat\\Route\\Url')->getCanonical(" . var_export($this->attr('domains'), true) . ',' . ($this->attr('http-substitution') ? 'true' : 'false') . ',' . ($this->attr('static') ? 'true' : 'false') . ');?>'; } else { $url = Di::getInstance()->get('RedCat\\Route\\Url'); $canonical = $url->getCanonical($this->attr('domains'), !!$this->attr('http-substitution'), $this->attr('static')); $canonical2 = $url->getCanonical($this->attr('domains'), '%s', $this->attr('static')); if ($this->attr('http-substitution')) { $href = '<?php echo http_response_code()===200?' . var_export($canonical, true) . ':sprintf(' . var_export($canonical2, true) . ',http_response_code());?>'; } else { $href = $canonical; } } $this->write('<link rel="canonical" href="' . $href . '">'); }
function __invoke(Di $di) { return function () use($di) { return $di->closureInvoke($this->closure, func_get_args(), $this->rules); }; }