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; }
/** * 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); } }