Example #1
0
 /**
  * Resolve the file system path of a template
  * 
  * @param Page $page
  * @param string $class
  * @param string $path
  * @param array $inParams
  * @param boolean $showMissingTemplate
  * 
  * @return string
  */
 public static function resolveTemplatePath($page, $class, $path, &$inParams, $showMissingTemplate = true)
 {
     // if starts with a slash, then its a full path from the contextRoot
     // that means there is no wayt to do a file system full path...  thats probably ok
     if (preg_match("/^\\//", $path)) {
         $result = Application::getInstance()->getActiveModule()->resolveResourcePath($path, $page->getRequest()->getAttribute("contextPath"));
         if ($result) {
             return $result;
         } else {
             $inParams['templatePath'] = $path;
             $a = array();
             return Container::resolveTemplatePath($page, $class, "missing_template.php", $a);
         }
     }
     /* First search for overridden namespace paths in the root directory of the namespace */
     $override_path = str_replace("\\", DIRECTORY_SEPARATOR, $class) . DIRECTORY_SEPARATOR . $path;
     $reflector = new \ReflectionClass(get_class(Application::getInstance()));
     $start_path = str_replace(str_replace("\\", DIRECTORY_SEPARATOR, $reflector->getName()) . ".php", '', $reflector->getFileName());
     $override_path = $start_path . $override_path;
     if (file_exists($override_path)) {
         return $override_path;
     }
     $iter = new SearchPathIterator($class);
     while ($iter->hasNext()) {
         $testPath = $iter->next() . DIRECTORY_SEPARATOR . $path;
         if (file_exists($testPath)) {
             return $testPath;
         }
     }
     // if didn't find it and we aren't the Page class, then allow the page to be involved
     if ($class != get_class($page)) {
         return self::resolveTemplatePath($page, get_class($page), $path, $inParams, $showMissingTemplate);
     } else {
         if ($showMissingTemplate) {
             $inParams['templatePath'] = $path;
             return Container::resolveTemplatePath($page, $class, "missing_template.php", $a);
         } else {
             return null;
         }
     }
 }