• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Compilers\BladeCompiler类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中Illuminate\View\Compilers\BladeCompiler的典型用法代码示例。如果您正苦于以下问题:PHP BladeCompiler类的具体用法?PHP BladeCompiler怎么用?PHP BladeCompiler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了BladeCompiler类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
     }
 }
开发者ID:nerea91,项目名称:laravel,代码行数:40,代码来源:GettextCommand.php


示例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>";
     });
 }
开发者ID:quenti77,项目名称:easyhq,代码行数:40,代码来源:Blade.php


示例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(); ?>";
     });
 }
开发者ID:Crinsane,项目名称:LaravelNotify,代码行数:12,代码来源:NotificationsDirectiveTest.php


示例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;
 }
开发者ID:garbetjie,项目名称:tiny,代码行数:33,代码来源:TemplateRenderer.php


示例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);
 }
开发者ID:parkerj,项目名称:eduTrac-SIS,代码行数:10,代码来源:Blade.php


示例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());
 }
开发者ID:kenvunz,项目名称:lucent,代码行数:7,代码来源:Loop.php


示例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);
     });
 }
开发者ID:jubstuff,项目名称:baobab,代码行数:13,代码来源:WordPressLoopExtension.php


示例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);
     });
 }
开发者ID:jubstuff,项目名称:baobab,代码行数:13,代码来源:WordPressShortcodeExtension.php


示例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;
 }
开发者ID:rayhan0421,项目名称:laravel-datatables,代码行数:18,代码来源:Helper.php


示例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"));
         }
     }
 }
开发者ID:pauluse,项目名称:laravel-gettext,代码行数:12,代码来源:PoGeneratorTest.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;
 }
开发者ID:PlatiniumGroup,项目名称:DBDiff,代码行数:13,代码来源:Templater.php


示例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;
 }
开发者ID:advmaker,项目名称:blade-loop,代码行数:21,代码来源:BladeLoopServiceProvider.php


示例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;
        });
    }
开发者ID:parsnick,项目名称:steak,代码行数:21,代码来源:RegisterBladeExtensions.php


示例14: register

 /**
  * Register.
  *
  * @param \Illuminate\View\Compilers\BladeCompiler $compiler
  *
  * @return void
  */
 public static function register(BladeCompiler $compiler)
 {
     $compiler->directive('money', function ($expression) {
         if (Str::startsWith($expression, '(')) {
             $expression = substr($expression, 1, -1);
         }
         return "<?php echo money({$expression}); ?>";
     });
     $compiler->directive('currency', function ($expression) {
         if (Str::startsWith($expression, '(')) {
             $expression = substr($expression, 1, -1);
         }
         return "<?php echo currency({$expression}); ?>";
     });
 }
开发者ID:cknow,项目名称:laravel-money,代码行数:22,代码来源:BladeExtensions.php


示例15: 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;
 }
开发者ID:pauluse,项目名称:laravel-gettext,代码行数:26,代码来源:PoGenerator.php


示例16: extend

 /**
  * extend
  *
  * @param   BladeCompiler $blade
  * @param   string        $name
  * @param   callable      $closure
  *
  * @return  void
  */
 public static function extend(BladeCompiler $blade, $name, $closure)
 {
     // For 5.0 after
     if (is_callable(array($blade, 'directive'))) {
         $blade->directive($name, $closure);
         return;
     }
     // For 4.x before
     $blade->extend(function ($view, BladeCompiler $compiler) use($name, $closure) {
         $pattern = $compiler->createMatcher($name);
         return preg_replace_callback($pattern, function ($matches) use($closure) {
             if (empty($matches[2])) {
                 return $matches[0];
             }
             return $matches[1] . $closure($matches[2]);
         }, $view);
     });
     return;
 }
开发者ID:im286er,项目名称:windwalker,代码行数:28,代码来源:BladeExtending.php


示例17: 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;
 }
开发者ID:rxfu,项目名称:student,代码行数:27,代码来源:Helper.php


示例18: fire

 public function fire()
 {
     $app = app();
     $cache = $app['path.storage'] . '/views';
     $compiler = new BladeCompiler($app['files'], $cache);
     // delete compiled
     $files = new \GlobIterator(TEMP_PATH . '/views/*');
     foreach ($files as $file) {
         if ($file->getExtension() !== '.gitignore') {
             unlink($file);
         }
     }
     // generate new ones
     $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(VIEWS_PATH), \RecursiveIteratorIterator::SELF_FIRST);
     foreach ($files as $file) {
         if ($file->getExtension() === 'blade') {
             $compiler->compile($file->getPathname());
         }
     }
 }
开发者ID:stanmay,项目名称:unflare,代码行数:20,代码来源:CompileViews.php


示例19: 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);
 }
开发者ID:laravel-commode,项目名称:bladed,代码行数:35,代码来源:BladedCompilerTest.php


示例20: 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);
        });
    }
开发者ID:realholgi,项目名称:cmsable,代码行数:29,代码来源:ResourceDirectives.php



注:本文中的Illuminate\View\Compilers\BladeCompiler类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Engines\EngineResolver类代码示例发布时间:2022-05-23
下一篇:
PHP View\View类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap