/** * 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}"); } }
/** * Compile handlebars template into PHP code. * * @param string $template handlebars template string * @param array<string,array|string|integer> $options LightnCandy compile time and run time options, default is array('flags' => LightnCandy::FLAG_BESTPERFORMANCE) * * @return string|false Compiled PHP code when successed. If error happened and compile failed, return false. */ public static function compile($template, $options = array('flags' => self::FLAG_BESTPERFORMANCE)) { self::$compileHelpersOnly = isset($options['compile_helpers_only']) && $options['compile_helpers_only'] == true; return parent::compile($template, $options); }