setAutoRefresh() public method

Sets auto-refresh mode.
public setAutoRefresh ( $on = TRUE ) : static
return static
Beispiel #1
0
 /**
  * Register the application services.
  *
  * @return void
  * @throws \InvalidArgumentException
  */
 public function register()
 {
     $this->app->singleton('latte.engine', function ($app) {
         $latte = new Latte\Engine();
         $latte->setAutoRefresh($app['config']['app.debug']);
         $latte->setTempDirectory($app['config']['view.compiled']);
         return $latte;
     });
     $this->app->resolving('view', function (Factory $viewFactory, Application $app) {
         if ($viewFactory instanceof \Illuminate\View\Factory) {
             $viewFactory->addExtension('latte', 'latte', function () use($app) {
                 return new LatteEngineBridge($app['latte.engine']);
             });
         } else {
             throw new \InvalidArgumentException('Can\'t register Latte\\Engine, ' . get_class($viewFactory) . ' view factory is not supported.');
         }
     });
 }
Beispiel #2
0
 /**
  * @return Engine
  */
 public function create()
 {
     $engine = new Engine();
     // Options
     $engine->setTempDirectory($this->tempDir);
     $engine->setAutoRefresh($this->autoRefresh);
     $engine->setContentType($this->contentType);
     // Filters
     foreach ($this->filters as $name => $callback) {
         $engine->addFilter($name, $callback);
     }
     // Macros
     $engine->onCompile[] = function (Engine $engine) {
         $compiler = $engine->getCompiler();
         foreach ($this->macros as $macro) {
             $macro::install($compiler);
         }
     };
     return $engine;
 }
Beispiel #3
0
 /**
  * @return Latte\Engine
  */
 private function getLatte()
 {
     if (!isset($this->latte)) {
         $this->latte = new Latte\Engine();
         $this->latte->setTempDirectory($this->tempDir);
         $this->latte->setAutoRefresh(FALSE);
         $this->latte->onCompile[] = function (Latte\Engine $latte) {
             $set = new Latte\Macros\MacroSet($latte->getCompiler());
             $set->addMacro('link', 'echo %escape(call_user_func($getLink, %node.word, %node.array))');
         };
         $this->latte->addFilter('attachmentLabel', function (MimePart $attachment) {
             $contentDisposition = $attachment->getHeader('Content-Disposition');
             $contentType = $attachment->getHeader('Content-Type');
             $matches = Strings::match($contentDisposition, '#filename="(.+?)"#');
             return ($matches ? "{$matches['1']} " : '') . "({$contentType})";
         });
         $this->latte->addFilter('plainText', function (MimePart $part) {
             $ref = new \ReflectionProperty('Nette\\Mail\\MimePart', 'parts');
             $ref->setAccessible(TRUE);
             $queue = array($part);
             for ($i = 0; $i < count($queue); $i++) {
                 /** @var MimePart $subPart */
                 foreach ($ref->getValue($queue[$i]) as $subPart) {
                     $contentType = $subPart->getHeader('Content-Type');
                     if (Strings::startsWith($contentType, 'text/plain') && $subPart->getHeader('Content-Transfer-Encoding') !== 'base64') {
                         // Take first available plain text
                         return (string) $subPart->getBody();
                     } elseif (Strings::startsWith($contentType, 'multipart/alternative')) {
                         $queue[] = $subPart;
                     }
                 }
             }
             return $part->getBody();
         });
     }
     return $this->latte;
 }