示例#1
0
 /**
  * View factory method
  *
  * @param $templateName Template name (e.g., 'index')
  * @param $viewType     View type (e.g., View::CLI)
  */
 public static function factory($templateName, $viewType = null, $path = null)
 {
     //PostEvent('View.getViewType', $viewType);
     // get caller
     if ($path === null) {
         $bt = @debug_backtrace();
         if ($bt === null || !isset($bt[0])) {
             throw new Exception("View factory cannot be invoked");
         }
         $path = dirname($bt[0]['file']);
     } else {
         $path = USER_PATH . DIRECTORY_SEPARATOR . $path;
     }
     // determine best view type
     if ($viewType === null) {
         if (Core_Common::isPhpCliMode()) {
             $viewType = self::CLI;
         } else {
             $viewType = self::STANDARD;
         }
     }
     // get template filename
     if ($viewType == self::CLI) {
         $templateFile = $path . '/templates/cli_' . $templateName . '.tpl';
         if (file_exists($templateFile)) {
             return new View($templateFile, array(), false);
         }
         $viewType = self::STANDARD;
     }
     if ($viewType == self::MOBILE) {
         $templateFile = $path . '/templates/mobile_' . $templateName . '.tpl';
         if (!file_exists($templateFile)) {
             $viewType = self::STANDARD;
         }
     }
     if ($viewType != self::MOBILE) {
         $templateFile = $path . '/templates/' . $templateName . '.tpl';
         if (!file_exists($templateFile)) {
             throw new Exception('Template not found: ' . $templateFile);
         }
     }
     return new Core_View($templateFile);
 }