本文整理汇总了PHP中Illuminate\View\Compilers\BladeCompiler::compileString方法的典型用法代码示例。如果您正苦于以下问题:PHP BladeCompiler::compileString方法的具体用法?PHP BladeCompiler::compileString怎么用?PHP BladeCompiler::compileString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\View\Compilers\BladeCompiler
的用法示例。
在下文中一共展示了BladeCompiler::compileString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testStatements
public function testStatements()
{
$this->bladedManager->expects($this->any())->method('getCommand')->will($this->returnValue($this));
$this->appMock->expects($this->any())->method('make')->will($this->returnCallback(function ($resolvable) {
switch ($resolvable) {
case 'view':
return $this->viewMock;
case 'laravel-commode.bladed':
return $this->bladedManager;
case BladedServiceProvider::PROVIDES_STRING_COMPILER:
return $this->stringCompiler;
default:
var_dump($resolvable, 'in testStatements');
die;
}
}));
foreach (['condition', 'statement', 'templates'] as $file) {
$this->assertSame(bl_get_contents('templates/results' . ucfirst($file)), $this->bladeCompiler->compileString(bl_get_contents("templates/{$file}.blade._php")));
}
$expect = bl_get_contents('templates/resultsIterators');
$compiled = $this->bladeCompiler->compileString(bl_get_contents("templates/iterators.blade._php"));
preg_match_all('/(\\$count[\\d\\w]{1,})/is', $compiled, $countVars);
$countVars = array_values($countVars[0]);
preg_match_all('/(\\$key[\\d\\w]{1,})/is', $compiled, $keyVars);
$keyVars = array_values($keyVars[0]);
$countIteration = 0;
$keyIteration = 0;
$expect = preg_replace_callback('/\\{\\{countVar\\}\\}/is', function ($match) use($countVars, &$countIteration) {
return $countVars[$countIteration++];
}, $expect);
$expect = preg_replace_callback('/\\{\\{\\$key\\}\\}/is', function ($match) use($keyVars, &$keyIteration) {
return $keyVars[$keyIteration++];
}, $expect);
$this->assertSame($expect, $compiled);
}
示例2: render
/**
* Get the evaluated contents of the file.
*/
public function render()
{
$viewContent = $this->buildBladeViewContent();
if ($this->isExpired()) {
$this->filesystem->put($this->cached, $this->bladeCompiler->compileString($viewContent));
}
$data = $this->getViewData();
return $this->engine->get($this->cached, $data);
}
示例3: render
/**
* render
*
* @param $string
* @param array $vars
* @return string
*/
public function render($string, array $vars = array())
{
$this->files->put($this->tmpFilePath, $this->compiler->compileString($string));
if (is_array($vars) && !empty($vars)) {
extract($vars);
}
ob_start();
include $this->tmpFilePath;
$var = ob_get_contents();
ob_end_clean();
$this->files->delete($this->tmpFilePath);
return $var;
}
示例4: render
/**
* render
*
* @param $string
* @param array $vars
* @return string
*/
public function render($string, array $vars = array())
{
$fileName = uniqid(time(), false);
$this->generateDirectoryStructure(storage_path(), ['sebwite/stubs']);
$path = storage_path("sebwite/stubs/{$fileName}");
$this->files->put($path, $this->compiler->compileString($string));
if (is_array($vars) && !empty($vars)) {
extract($vars);
}
ob_start();
include $path;
$var = ob_get_contents();
ob_end_clean();
$this->files->delete($path);
return $var;
}
示例5: fromString
/**
* {@inheritdoc}
*/
public static function fromString($string, Translations $translations, array $options = [])
{
$cachePath = empty($options['cachePath']) ? sys_get_temp_dir() : $options['cachePath'];
$bladeCompiler = new BladeCompiler(new Filesystem(), $cachePath);
$string = $bladeCompiler->compileString($string);
PhpCode::fromString($string, $translations, $options);
}
示例6: render
public function render($str, array $vars = [])
{
$__tmp_stub_file = Str::random() . uniqid(time(), false);
!$this->fs->exists($this->cachePath) && $this->fs->makeDirectory($this->cachePath, 0755, true);
$__tmp_stub_path = Path::join($this->cachePath, $__tmp_stub_file);
$this->fs->put($__tmp_stub_path, $this->compiler->compileString($str));
$__env = $this->getViewFactory();
if (is_array($vars) && 0 !== count($vars)) {
extract($vars);
}
ob_start();
include $__tmp_stub_path;
$var = ob_get_contents();
ob_end_clean();
$this->fs->delete($__tmp_stub_path);
return $var;
}
示例7: compileBlade
/**
* Parses and compiles strings by using Blade Template System.
*
* @param string $str
* @param array $data
* @return string
*/
public static function compileBlade($str, $data = [])
{
$empty_filesystem_instance = new Filesystem();
$blade = new BladeCompiler($empty_filesystem_instance, 'datatables');
$parsed_string = $blade->compileString($str);
ob_start() && extract($data, EXTR_SKIP);
eval('?>' . $parsed_string);
$str = ob_get_contents();
ob_end_clean();
return $str;
}
示例8: testCompileViews
public function testCompileViews()
{
$compiler = new BladeCompiler(new Filesystem(), $this->config['storage_path']);
$this->generator->compileViews($this->config['paths'], $this->config['storage_path']);
foreach ($this->config['paths'] as $path) {
$files = glob(realpath($path) . '/{,**/}*.php', GLOB_BRACE);
foreach ($files as $file) {
$contents = $this->generator->parseToken($this->files->get($file));
$this->assertEquals($compiler->compileString($contents), $this->files->get($this->config['storage_path'] . "/" . md5($file) . ".php"));
}
}
}
示例9: compileWiths
/**
* Compile blade template with passing arguments.
*
* @param $value
* @param array $args
* @throws \Exception
* @return string
*/
public function compileWiths($value, array $args = array())
{
$generated = parent::compileString($value);
ob_start() and extract($args, EXTR_SKIP);
try {
eval('?>' . $generated);
} catch (\Exception $e) {
ob_get_clean();
throw $e;
}
$content = ob_get_clean();
return $content;
}
示例10: getContent
private function getContent()
{
$compiler = new BladeCompiler(new Filesystem(), ".");
$template = $this->getTemplate();
$compiled = $compiler->compileString(' ?>' . $template);
$up = trim($this->up, "\n");
$down = trim($this->down, "\n");
ob_start();
eval($compiled);
$content = ob_get_contents();
ob_end_clean();
return $content;
}
示例11: compileBlade
/**
* Parses and compiles strings by using Blade Template System.
*
* @param string $str
* @param array $data
* @return string
* @throws \Exception
*/
public static function compileBlade($str, $data = [])
{
if (view()->exists($str)) {
return view($str, $data)->render();
}
$empty_filesystem_instance = new Filesystem();
$blade = new BladeCompiler($empty_filesystem_instance, 'datatables');
$parsed_string = $blade->compileString($str);
ob_start() && extract($data, EXTR_SKIP);
try {
eval('?>' . $parsed_string);
} catch (\Exception $e) {
ob_end_clean();
throw $e;
}
$str = ob_get_contents();
ob_end_clean();
return $str;
}
示例12: compileViews
/**
* Compile views.
*
* @param array $paths
* @param string $storagePath
* @return $this
*/
public function compileViews(array $paths, $storagePath)
{
$this->makeDestination($storagePath);
$compiler = new BladeCompiler($this->files, $storagePath);
foreach ($paths as $path) {
$files = $this->files->glob(realpath($path) . '/{,**/}*.php', GLOB_BRACE);
foreach ($files as $file) {
if (!Str::endsWith(strtolower($file), '.blade.php')) {
continue;
}
$compiler->setPath($file);
$contents = $this->parseToken($this->files->get($file));
$contents = $compiler->compileString($contents);
$compiledPath = $compiler->getCompiledPath($compiler->getPath());
$this->files->put($compiledPath . '.php', $contents);
}
}
return $this;
}
示例13: handle
public function handle()
{
$this->info('start view compiler');
$targetDir = storage_path(config('trans.view_store_path'));
if (!file_exists($targetDir)) {
$this->createDirectory($targetDir);
$this->comment('created directory ' . $targetDir);
}
$path = base_path(config('trans.view_blade_path'));
$fs = new Filesystem($path);
$files = $fs->allFiles(realpath($path));
$compiler = new BladeCompiler($fs, $targetDir);
foreach ($files as $file) {
$filePath = $file->getRealPath();
$this->comment('compile view: ' . $filePath);
$compiler->setPath($filePath);
$contents = $compiler->compileString($fs->get($filePath));
$compiledPath = $compiler->getCompiledPath($compiler->getPath());
$fs->put($compiledPath . '.php', $contents);
}
}
示例14: blader
/**
* Parses and compiles strings by using Blade Template System
*
* @return string
*/
private function blader($str, $data = array())
{
$empty_filesystem_instance = new Filesystem();
$blade = new BladeCompiler($empty_filesystem_instance, 'datatables');
$parsed_string = $blade->compileString($str);
ob_start() and extract($data, EXTR_SKIP);
try {
eval('?>' . $parsed_string);
} catch (\Exception $e) {
ob_end_clean();
throw $e;
}
$str = ob_get_contents();
ob_end_clean();
return $str;
}
示例15: compile
/**
* Compile blade template to HTML.
*
* @param string $template
* @param array $data
*
* @throws \Exception
* @return string
*/
public function compile($template, $data = array())
{
$compiler = new BladeCompiler($this->files, 'theme');
// Get blade compiler.
$parsed = $compiler->compileString($template);
ob_start() and extract($data, EXTR_SKIP);
try {
eval('?>' . $parsed);
} catch (\Exception $e) {
ob_end_clean();
throw $e;
}
$template = ob_get_contents();
ob_end_clean();
return $template;
}