本文整理汇总了PHP中Illuminate\View\Compilers\BladeCompiler类的典型用法代码示例。如果您正苦于以下问题:PHP BladeCompiler类的具体用法?PHP BladeCompiler怎么用?PHP BladeCompiler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BladeCompiler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fire
/**
* Execute the console command.
*
* @return void
*/
public function fire()
{
// Set directories
$inputPath = base_path('resources/views');
$outputPath = storage_path('gettext');
// Create $outputPath or empty it if already exists
if (File::isDirectory($outputPath)) {
File::cleanDirectory($outputPath);
} else {
File::makeDirectory($outputPath);
}
// Configure BladeCompiler to use our own custom storage subfolder
$compiler = new BladeCompiler(new Filesystem(), $outputPath);
$compiled = 0;
// Get all view files
$allFiles = File::allFiles($inputPath);
foreach ($allFiles as $f) {
// Skip not blade templates
$file = $f->getPathName();
if ('.blade.php' !== substr($file, -10)) {
continue;
}
// Compile the view
$compiler->compile($file);
$compiled++;
// Rename to human friendly
$human = str_replace(DIRECTORY_SEPARATOR, '-', ltrim($f->getRelativePathname(), DIRECTORY_SEPARATOR));
File::move($outputPath . DIRECTORY_SEPARATOR . sha1($file) . '.php', $outputPath . DIRECTORY_SEPARATOR . $human);
}
if ($compiled) {
$this->info("{$compiled} files compiled.");
} else {
$this->error('No .blade.php files found in ' . $inputPath);
}
}
示例2: registerDirectives
/**
* Add extra directives to the blade templating compiler.
*
* @param BladeCompiler $blade The compiler to extend
*
* @return void
*/
public static function registerDirectives(BladeCompiler $blade)
{
$keywords = ["namespace", "use"];
foreach ($keywords as $keyword) {
$blade->directive($keyword, function ($parameter) use($keyword) {
$parameter = trim($parameter, "()");
return "<?php {$keyword} {$parameter} ?>";
});
}
$assetify = function ($file, $type) {
$file = trim($file, "()");
if (in_array(substr($file, 0, 1), ["'", '"'], true)) {
$file = trim($file, "'\"");
} else {
return "{{ {$file} }}";
}
if (substr($file, 0, 1) !== "/") {
$file = "/{$type}/{$file}";
}
if (substr($file, (strlen($type) + 1) * -1) !== ".{$type}") {
$file .= ".{$type}";
}
return $file;
};
$blade->directive("css", function ($parameter) use($assetify) {
$file = $assetify($parameter, "css");
return "<link rel='stylesheet' type='text/css' href='{$file}'>";
});
$blade->directive("js", function ($parameter) use($assetify) {
$file = $assetify($parameter, "js");
return "<script type='text/javascript' src='{$file}'></script>";
});
}
示例3: registerBladeDirective
/**
* Register the custom Blade directive
*
* @param \Illuminate\View\Compilers\BladeCompiler $compiler
*/
private function registerBladeDirective($compiler)
{
$compiler->directive('notifications', function () {
$expression = 'Gloudemans\\Notify\\Notifications\\Notification';
return "<?php echo app('{$expression}')->render(); ?>";
});
}
示例4: __construct
/**
* Template constructor.
*
* @param Container $container
*/
public function __construct(Container $container)
{
$settings = $container->get('settings');
$compiledPath = $settings['storagePath'] . DIRECTORY_SEPARATOR . 'views';
$resolver = new EngineResolver();
$resolver->register('blade', function () use($compiledPath, &$settings) {
$bladeCompiler = new BladeCompiler(new Filesystem(), $compiledPath);
// Add the @webroot directive.
$bladeCompiler->directive('webroot', function ($expression) use(&$settings) {
$segments = explode(',', preg_replace("/[\\(\\)\\\"\\']/", '', $expression));
$path = rtrim($settings['webrootBasePath'], '/') . '/' . ltrim($segments[0], '/');
$path = str_replace("'", "\\'", $path);
return "<?= e('{$path}') ?>";
});
// Add the @route directive.
$bladeCompiler->directive('route', function ($expression) use(&$settings) {
$segments = explode(',', preg_replace("/[\\(\\)\\\"\\']/", '', $expression));
$path = rtrim($settings['routeBasePath'], '/') . '/' . ltrim($segments[0], '/');
$path = str_replace("'", "\\'", $path);
return "<?= e('{$path}') ?>";
});
return new CompilerEngine($bladeCompiler);
});
$finder = new FileViewFinder(new Filesystem(), [$settings['templatePath']]);
$factory = new ViewFactory($resolver, $finder, new Dispatcher());
$this->factory = $factory;
$this->container = $container;
}
示例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: extendTo
public function extendTo(BladeCompiler $blade)
{
$blade->directive('wploop', $this->start());
$blade->directive('wpempty', $this->ifempty());
$blade->directive('endwploop', $this->end());
$blade->directive('wpthe', $this->the());
}
示例7: registerEndLoop
/**
* @wpend
*
* @param BladeCompiler $compiler The blade compiler to extend
*/
private function registerEndLoop($compiler)
{
$compiler->extend(function ($view, $comp) {
$pattern = $comp->createPlainMatcher('endwploop');
$replacement = '$1<?php endif; wp_reset_postdata(); ?>';
return preg_replace($pattern, $replacement, $view);
});
}
示例8: registerDoShortcode
/**
* @shortcode
*
* @param BladeCompiler $compiler The blade compiler to extend
*/
private function registerDoShortcode($compiler)
{
$compiler->extend(function ($view, $comp) {
$pattern = $comp->createMatcher('shortcode');
$replacement = '$1<?php do_shortcode($2); ?> ';
return preg_replace($pattern, $replacement, $view);
});
}
示例9: 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;
}
示例10: 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"));
}
}
}
示例11: 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;
}
示例12: addLoopControlDirectives
/**
* Extend blade by continue and break directives.
*
* @param BladeCompiler $blade
*
* @return BladeCompiler
*/
private function addLoopControlDirectives(BladeCompiler $blade)
{
$blade->extend(function ($value) {
$pattern = '/(?<!\\w)(\\s*)@continue\\s*\\(([^)]*)\\)/';
$replacement = '$1<?php if ($2) { continue; } ?>';
return preg_replace($pattern, $replacement, $value);
});
$blade->extend(function ($value) {
$pattern = '/(?<!\\w)(\\s*)@break\\s*\\(([^)]*)\\)/';
$replacement = '$1<?php if ($2) { break; } ?>';
return preg_replace($pattern, $replacement, $value);
});
return $blade;
}
示例13: allowHighlightTag
/**
* Add basic syntax highlighting.
*
* This just adds markup that is picked up by a javascript highlighting library.
*
* @param BladeCompiler $compiler
*/
protected function allowHighlightTag(BladeCompiler $compiler)
{
$compiler->directive('highlight', function ($expression) {
if (is_null($expression)) {
$expression = "('php')";
}
return "<?php \$__env->startSection{$expression}; ?>";
});
$compiler->directive('endhighlight', function () {
return <<<'HTML'
<?php $last = $__env->stopSection(); echo '<pre><code class="language-', $last, '">', trim($__env->yieldContent($last)), '</code></pre>'; ?>
HTML;
});
}
示例14: 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);
}
示例15: registerSearchForm
protected function registerSearchForm(Compiler $blade, $name)
{
$blade->extend(function ($view, $compiler) use($name) {
$pattern = $compiler->createMatcher($name);
$code = <<<'EOD'
$1<?php
if (isset($searchForm)) {
echo $searchForm;
} else{
$passed = array$2;
if (count($passed) == 2) {
$m = $passed[0];
$res = $passed[1];
}
if (count($passed) == 1) {
$m = $passed[0];
$res = isset($resource) ? $resource : null;
}
if (count($passed) == 0) {
$m = isset($model) ? $model : null;
$res = isset($resource) ? $resource : null;
}
echo Resource::searchForm($m, $res);
}
?>
EOD;
return preg_replace($pattern, $code, $view);
});
}