コード例 #1
0
 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
0
 /**
  * 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
0
 /**
  * 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
0
ファイル: StubGenerator.php プロジェクト: docit/support
 /**
  * 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
0
ファイル: Blade.php プロジェクト: parkerj/eduTrac-SIS
 /**
  * {@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
0
ファイル: Blade.php プロジェクト: laradic-old/illuminate
 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
0
 /**
  * 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
0
 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
0
 /**
  * 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
0
ファイル: Templater.php プロジェクト: PlatiniumGroup/DBDiff
 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
0
ファイル: Helper.php プロジェクト: rxfu/student
 /**
  * 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
0
 /**
  * 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
0
 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
0
 /**
  * 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
0
ファイル: Breadcrumb.php プロジェクト: bokbok123/ORS
 /**
  * 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;
 }
コード例 #16
0
ファイル: Blade.php プロジェクト: Marketing1by1/Gettext
 /**
  * {@inheritdoc}
  */
 public static function fromString($string, Translations $translations = null, $file = '')
 {
     $bladeCompiler = new BladeCompiler(new Filesystem(), null);
     $string = $bladeCompiler->compileString($string);
     return PhpCode::fromString($string, $translations, $file);
 }
コード例 #17
0
ファイル: utils.php プロジェクト: schpill/standalone
 public function blader($str, $data = [])
 {
     $blade = new BladeCompiler(new Filesystem(), 'thin');
     $parsedString = $blade->compileString($str);
     ob_start() && extract($data, EXTR_SKIP);
     try {
         eval('?>' . $parsedString);
     } catch (\Exception $e) {
         ob_end_clean();
         throw $e;
     }
     $str = ob_get_contents();
     ob_end_clean();
     return $str;
 }
コード例 #18
0
 public function testCurrency()
 {
     $this->assertEquals('<?php echo currency("BRL"); ?>', $this->compiler->compileString('@currency("BRL")'));
 }
コード例 #19
0
ファイル: _ide_helper.php プロジェクト: satriashp/tour
 /**
  * Compile the given Blade template contents.
  *
  * @param string $value
  * @return string 
  * @static 
  */
 public static function compileString($value)
 {
     return \Illuminate\View\Compilers\BladeCompiler::compileString($value);
 }
コード例 #20
0
 /**
  * Compile blade template with passing arguments.
  *
  * @param  string $value
  * @param  array  $args  variables to be extracted
  * @return string        the compiled output
  */
 private function prv_compileBladeSyntax($value, array $args = array())
 {
     $compiler = new BladeCompiler(App::make('files'), App::make('path') . '/storage/views');
     $generated = $compiler->compileString($value);
     //return $generated;
     //if( is_array( $args ) == false ) $args = array( $args );
     ob_start() and extract($args, EXTR_SKIP);
     eval('?>' . $generated . '<?php ');
     /*try
             {
                 eval('?>'.$generated.'<?php ');
             }
             // If we caught an exception, just return $value unparsed for now, or empty string
             catch (\Exception $e)
             {
                 ob_get_clean(); //throw $e;
                 return $value;
             }
     */
     $content = ob_get_clean();
     return $content;
 }