laravel-6 support
This commit is contained in:
		| @@ -119,21 +119,10 @@ class BladeCompiler extends Compiler implements CompilerInterface | ||||
|         } | ||||
|  | ||||
|         if (! is_null($this->cachePath)) { | ||||
|             $contents = $this->compileString( | ||||
|                 $this->files->get($this->getPath()) | ||||
|             ); | ||||
|             $contents = $this->compileString($this->files->get($this->getPath())); | ||||
|  | ||||
|             if (! empty($this->getPath())) { | ||||
|                 $tokens = $this->getOpenAndClosingPhpTokens($contents); | ||||
|  | ||||
|                 // If the tokens we retrieved from the compiled contents have at least | ||||
|                 // one opening tag and if that last token isn't the closing tag, we | ||||
|                 // need to close the statement before adding the path at the end. | ||||
|                 if ($tokens->isNotEmpty() && $tokens->last() !== T_CLOSE_TAG) { | ||||
|                     $contents .= ' ?>'; | ||||
|                 } | ||||
|  | ||||
|                 $contents .= "<?php /**PATH {$this->getPath()} ENDPATH**/ ?>"; | ||||
|                 $contents = $this->appendFilePath($contents); | ||||
|             } | ||||
|  | ||||
|             $this->files->put( | ||||
| @@ -142,6 +131,23 @@ class BladeCompiler extends Compiler implements CompilerInterface | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Append the file path to the compiled string. | ||||
|      * | ||||
|      * @param  string  $contents | ||||
|      * @return string | ||||
|      */ | ||||
|     protected function appendFilePath($contents) | ||||
|     { | ||||
|         $tokens = $this->getOpenAndClosingPhpTokens($contents); | ||||
|  | ||||
|         if ($tokens->isNotEmpty() && $tokens->last() !== T_CLOSE_TAG) { | ||||
|             $contents .= ' ?>'; | ||||
|         } | ||||
|  | ||||
|         return $contents."<?php /**PATH {$this->getPath()} ENDPATH**/ ?>"; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get the open and closing PHP tag tokens from the given string. | ||||
|      * | ||||
| @@ -151,7 +157,7 @@ class BladeCompiler extends Compiler implements CompilerInterface | ||||
|     protected function getOpenAndClosingPhpTokens($contents) | ||||
|     { | ||||
|         return collect(token_get_all($contents)) | ||||
|             ->pluck($tokenNumber = 0) | ||||
|             ->pluck(0) | ||||
|             ->filter(function ($token) { | ||||
|                 return in_array($token, [T_OPEN_TAG, T_OPEN_TAG_WITH_ECHO, T_CLOSE_TAG]); | ||||
|             }); | ||||
| @@ -186,17 +192,9 @@ class BladeCompiler extends Compiler implements CompilerInterface | ||||
|      */ | ||||
|     public function compileString($value) | ||||
|     { | ||||
|         if (strpos($value, '@verbatim') !== false) { | ||||
|             $value = $this->storeVerbatimBlocks($value); | ||||
|         } | ||||
|         [$this->footer, $result] = [[], '']; | ||||
|  | ||||
|         $this->footer = []; | ||||
|  | ||||
|         if (strpos($value, '@php') !== false) { | ||||
|             $value = $this->storePhpBlocks($value); | ||||
|         } | ||||
|  | ||||
|         $result = ''; | ||||
|         $value = $this->storeUncompiledBlocks($value); | ||||
|  | ||||
|         // Here we will loop through all of the tokens returned by the Zend lexer and | ||||
|         // parse each one into the corresponding valid PHP. We will then have this | ||||
| @@ -219,6 +217,25 @@ class BladeCompiler extends Compiler implements CompilerInterface | ||||
|         return $result; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Store the blocks that do not receive compilation. | ||||
|      * | ||||
|      * @param  string  $value | ||||
|      * @return string | ||||
|      */ | ||||
|     protected function storeUncompiledBlocks($value) | ||||
|     { | ||||
|         if (strpos($value, '@verbatim') !== false) { | ||||
|             $value = $this->storeVerbatimBlocks($value); | ||||
|         } | ||||
|  | ||||
|         if (strpos($value, '@php') !== false) { | ||||
|             $value = $this->storePhpBlocks($value); | ||||
|         } | ||||
|  | ||||
|         return $value; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Store the verbatim blocks and replace them with a temporary placeholder. | ||||
|      * | ||||
| @@ -326,7 +343,7 @@ class BladeCompiler extends Compiler implements CompilerInterface | ||||
|     protected function compileExtensions($value) | ||||
|     { | ||||
|         foreach ($this->extensions as $compiler) { | ||||
|             $value = call_user_func($compiler, $value, $this); | ||||
|             $value = $compiler($value, $this); | ||||
|         } | ||||
|  | ||||
|         return $value; | ||||
| @@ -435,6 +452,12 @@ class BladeCompiler extends Compiler implements CompilerInterface | ||||
|                     : "<?php if (\Illuminate\Support\Facades\Blade::check('{$name}')): ?>"; | ||||
|         }); | ||||
|  | ||||
|         $this->directive('unless'.$name, function ($expression) use ($name) { | ||||
|             return $expression !== '' | ||||
|                 ? "<?php if (! \Illuminate\Support\Facades\Blade::check('{$name}', {$expression})): ?>" | ||||
|                 : "<?php if (! \Illuminate\Support\Facades\Blade::check('{$name}')): ?>"; | ||||
|         }); | ||||
|  | ||||
|         $this->directive('else'.$name, function ($expression) use ($name) { | ||||
|             return $expression !== '' | ||||
|                 ? "<?php elseif (\Illuminate\Support\Facades\Blade::check('{$name}', {$expression})): ?>" | ||||
| @@ -504,6 +527,8 @@ class BladeCompiler extends Compiler implements CompilerInterface | ||||
|      * @param  string  $name | ||||
|      * @param  callable  $handler | ||||
|      * @return void | ||||
|      * | ||||
|      * @throws \InvalidArgumentException | ||||
|      */ | ||||
|     public function directive($name, callable $handler) | ||||
|     { | ||||
|   | ||||
| @@ -2,8 +2,8 @@ | ||||
|  | ||||
| namespace Illuminate\View\Compilers; | ||||
|  | ||||
| use InvalidArgumentException; | ||||
| use Illuminate\Filesystem\Filesystem; | ||||
| use InvalidArgumentException; | ||||
|  | ||||
| abstract class Compiler | ||||
| { | ||||
| @@ -48,7 +48,7 @@ abstract class Compiler | ||||
|      */ | ||||
|     public function getCompiledPath($path) | ||||
|     { | ||||
|         return $this->cachePath.'/'.sha1($path).'.php'; | ||||
|         return $this->cachePath.'/'.sha1('v2'.$path).'.php'; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|   | ||||
| @@ -14,9 +14,11 @@ trait CompilesErrors | ||||
|     { | ||||
|         $expression = $this->stripParentheses($expression); | ||||
|  | ||||
|         return '<?php if ($errors->has('.$expression.')) : | ||||
| if (isset($message)) { $messageCache = $message; } | ||||
| $message = $errors->first('.$expression.'); ?>'; | ||||
|         return '<?php $__errorArgs = ['.$expression.']; | ||||
| $__bag = $errors->getBag($__errorArgs[1] ?? \'default\'); | ||||
| if ($__bag->has($__errorArgs[0])) : | ||||
| if (isset($message)) { $__messageOriginal = $message; } | ||||
| $message = $__bag->first($__errorArgs[0]); ?>'; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -28,7 +30,8 @@ $message = $errors->first('.$expression.'); ?>'; | ||||
|     protected function compileEnderror($expression) | ||||
|     { | ||||
|         return '<?php unset($message); | ||||
| if (isset($messageCache)) { $message = $messageCache; } | ||||
| endif; ?>'; | ||||
| if (isset($__messageOriginal)) { $message = $__messageOriginal; } | ||||
| endif; | ||||
| unset($__errorArgs, $__bag); ?>'; | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -54,6 +54,19 @@ trait CompilesIncludes | ||||
|         return "<?php echo \$__env->renderWhen($expression, \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path'])); ?>"; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Compile the include-unless statements into valid PHP. | ||||
|      * | ||||
|      * @param  string  $expression | ||||
|      * @return string | ||||
|      */ | ||||
|     protected function compileIncludeUnless($expression) | ||||
|     { | ||||
|         $expression = $this->stripParentheses($expression); | ||||
|  | ||||
|         return "<?php echo \$__env->renderWhen(! $expression, \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path'])); ?>"; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Compile the include-first statements into valid PHP. | ||||
|      * | ||||
|   | ||||
| @@ -2,8 +2,6 @@ | ||||
|  | ||||
| namespace Illuminate\View\Compilers\Concerns; | ||||
|  | ||||
| use Illuminate\View\Factory as ViewFactory; | ||||
|  | ||||
| trait CompilesLayouts | ||||
| { | ||||
|     /** | ||||
| @@ -50,7 +48,9 @@ trait CompilesLayouts | ||||
|      */ | ||||
|     protected function compileParent() | ||||
|     { | ||||
|         return ViewFactory::parentPlaceholder($this->lastSection ?: ''); | ||||
|         $escapedLastSection = strtr($this->lastSection, ['\\' => '\\\\', "'" => "\\'"]); | ||||
|  | ||||
|         return "<?php echo \Illuminate\View\Factory::parentPlaceholder('{$escapedLastSection}'); ?>"; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|   | ||||
| @@ -18,7 +18,7 @@ trait CompilesTranslations | ||||
|             return "<?php \$__env->startTranslation{$expression}; ?>"; | ||||
|         } | ||||
|  | ||||
|         return "<?php echo app('translator')->getFromJson{$expression}; ?>"; | ||||
|         return "<?php echo app('translator')->get{$expression}; ?>"; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 RafficMohammed
					RafficMohammed