Exemplo n.º 1
0
 /**
  * Loads the template named by resource
  *
  * If no provider can load the resource, a PHPSTLNoSuchResource exception
  * is thrown
  *
  * @param resource string the resource to load
  * @return PHPSTLTemplate the loaded template
  */
 public function load($resource)
 {
     $r = PHPSTLTemplateProvider::provide($this->providers, $resource);
     if (isset($r)) {
         return $r;
     } else {
         throw new PHPSTLNoSuchResource($this, $resource);
     }
 }
 public function load($resource)
 {
     if (substr($resource, 0, strlen(self::$Prefix)) != self::$Prefix) {
         return PHPSTLTemplateProvider::DECLINE;
     }
     $path = substr($resource, strlen(self::$Prefix));
     if ($path === false) {
         $path = '';
     }
     if (isset($this->transform)) {
         list($path, $data) = (array) call_user_func($this->transform, $path);
         if (!isset($path)) {
             return PHPSTLTemplateProvider::FAIL;
         }
         assert(!isset($data) || is_array($data));
     }
     if (!isset($data)) {
         $data = array();
     }
     $gotit = new StopException('catch!');
     try {
         if ($path != '') {
             $r = PHPSTLTemplateProvider::provide($this->providers, $path);
             if (isset($r)) {
                 $gotit->template = $r;
                 throw $gotit;
             }
         }
         if ($path == '') {
             $path = $this->indexFile;
         } else {
             $path = "{$path}/{$this->indexFile}";
         }
         $r = PHPSTLTemplateProvider::provide($this->providers, $path);
         if (isset($r)) {
             $gotit->template = $r;
             throw $gotit;
         }
     } catch (StopException $e) {
         if ($e === $gotit) {
             $template = $e->template;
             $template->setArguments($data);
             $template->assign('pageUrl', $path);
             return $template;
         }
         throw $e;
     }
     return PHPSTLTemplateProvider::FAIL;
 }
 /**
  * Creats a new CMSNode template provider
  *
  * @param site Site
  * @param pstl PHPSTL
  */
 public function __construct(Site $site, PHPSTL $pstl)
 {
     parent::__construct($pstl);
     $this->site = $site;
 }