Пример #1
0
 /**
  * Setup token delimiter by default or provided string
  *
  * @param array<string,array|string|integer> $context Current context
  * @param string $left left string of a token
  * @param string $right right string of a token
  */
 protected static function setupToken(&$context, $left = '{{', $right = '}}')
 {
     parent::setupToken($context, $left, $right);
     if (self::$compileHelpersOnly) {
         $helperTokens = array();
         foreach ($context['helpers'] as $helper => $value) {
             $helperTokens[] = $helper . '.*?';
         }
         $helperTokens = implode('|', $helperTokens);
         $context['tokens']['search'] = "/^(.*?)(\\s*)({$left})(~?)([\\^#\\/!&>]?)(" . $helperTokens . ")(~?)({$right})(\\s*)(.*)\$/s";
     }
 }
 /**
  * Compile the view at the given path.
  *
  * @param  string $path
  * @param  bool   $raw
  */
 public function compileString($path, $raw = false)
 {
     $options = $this->options;
     // set partials directory
     if (!$raw) {
         $options['basedir'][] = dirname($path);
     }
     // set raw option
     array_set($options, 'compile_helpers_only', $raw);
     // set language helper functions
     if ($this->languageHelpers) {
         if (!$raw) {
             $helpers = array_merge($this->getLanguageHelpers(), $options['helpers']);
         } elseif ($this->translateRawOutput) {
             $helpers = $this->getLanguageHelpers();
         } else {
             $helpers = [];
         }
         array_set($options, 'helpers', $helpers);
     }
     // As of LightnCandy v0.91 resolving via `basedir` and `fileext` options has been stripped from LightnCandy.
     if (!$options['partialresolver']) {
         $options['partialresolver'] = function ($context, $name) use($options) {
             foreach ($options['basedir'] as $dir) {
                 foreach ($options['fileext'] as $ext) {
                     $path = sprintf('%s/%s.%s', rtrim($dir, DIRECTORY_SEPARATOR), $name, ltrim($ext, '.'));
                     if (file_exists($path)) {
                         return file_get_contents($path);
                     }
                 }
             }
             return "[Partial {$path} not found]";
         };
     }
     $contents = $this->lightncandy->compile($this->files->get($path), $options);
     if (!is_null($this->cachePath)) {
         // As of LightnCandy v0.90 generated PHP code will not includes `<?php`.
         $this->files->put($this->getCompiledPath($path, $raw), "<?php {$contents}");
     }
 }