/** * Attempts to find a controller class for the given view template path. * * @param string $viewName A view template absolute file path. * @return null|string null if no controller was found. */ function findControllerForView($viewName) { /** @var DocumentContext $this */ $path = $this->viewService->resolveTemplatePath($viewName, $base); // inspect ($viewName, $base, $path); if (isset($this->controllers[$path])) { return $this->controllers[$path]; } foreach ($this->controllerNamespaces as $nsPath => $ns) { // inspect ($nsPath, $ns); if (str_beginsWith($path, $nsPath)) { $remaining = substr($path, strlen($nsPath) + 1); $a = PS($remaining)->split('/'); $file = $a->pop(); $nsPrefix = $a->map('ucfirst', false)->join('\\')->S; $class = ($p = strpos($file, '.')) !== false ? ucfirst(substr($file, 0, $p)) : ucfirst($file); $FQN = PA([$ns, $nsPrefix, $class])->prune()->join('\\')->S; // inspect ("CLASS $FQN"); if (class_exists($FQN)) { return $FQN; } } } // inspect ("CLASS NOT FOUND FOR VIEW $viewName"); return null; }
private function loadMacroFile($filename) { return $this->viewService->loadFromFile($filename)->getCompiled(); }