Пример #1
0
 /**
  * @param \Nette\Templating\Template|string|null $template full path to file and/or template instance and/or null
  * @param \Nette\Caching\IStorage|null $storage optional cache storage for template
  */
 public function __construct($template = null, \Nette\Caching\IStorage $storage = null)
 {
     if ($template === null) {
         $template = __DIR__ . '/bootstrap.latte';
     }
     if ($template instanceof \Nette\Templating\Template) {
         $this->template = $template;
     } elseif (is_string($template) && is_readable($template)) {
         $this->template = new \Nette\Templating\FileTemplate($template);
         $this->template->registerFilter(new \Nette\Latte\Engine());
     } elseif (is_string($template) && !is_readable($template)) {
         throw new \Nette\FileNotFoundException('File "' . $template . '" does not exists or is not readable by php.');
     } else {
         throw new \Nette\InvalidArgumentException('$template can be instance of Nette\\Templating\\Template, string path to file or null, ' . gettype($template) . ' given.');
     }
     if ($storage) {
         $this->template->setCacheStorage($storage);
     }
 }
Пример #2
0
 /**
  * @param string|Template $template Set either to constant, your instance of ITemplate and/or your path to your template file.
  * @param \Nette\Caching\IStorage $storage storage if available
  * @throws InvalidArgumentException Thrown when parameter combination does not match
  * @throws FileNotFoundException Thrown when path to the file is nonexistent or the file is not readable
  */
 public function __construct($template, \Nette\Caching\IStorage $storage = null)
 {
     $this->template = null;
     // If we're passed an ITemplate instance, use that
     if ($template instanceof ITemplate) {
         $this->template = $template;
     } elseif (is_string($template) && !file_exists($template) && file_exists(__DIR__ . '/' . $template)) {
         $template = __DIR__ . '/' . $template;
     }
     // CHeck & init
     if ($this->template === null && !file_exists($template)) {
         throw new InvalidArgumentException('$template has to be either path to template or instance of \\Nette\\Templating\\ITemplate');
     }
     if ($this->template === null) {
         $this->template = new FileTemplate($template);
         $this->template->registerFilter(new Engine());
         if ($storage) {
             $this->template->setCacheStorage($storage);
         }
     }
 }