upgraded dependencies
This commit is contained in:
		| @@ -45,6 +45,13 @@ class BladeCompiler extends Compiler implements CompilerInterface | ||||
|      */ | ||||
|     protected $conditions = []; | ||||
|  | ||||
|     /** | ||||
|      * All of the registered precompilers. | ||||
|      * | ||||
|      * @var array | ||||
|      */ | ||||
|     protected $precompilers = []; | ||||
|  | ||||
|     /** | ||||
|      * The file currently being compiled. | ||||
|      * | ||||
| @@ -58,7 +65,7 @@ class BladeCompiler extends Compiler implements CompilerInterface | ||||
|      * @var array | ||||
|      */ | ||||
|     protected $compilers = [ | ||||
|         'Comments', | ||||
|         // 'Comments', | ||||
|         'Extensions', | ||||
|         'Statements', | ||||
|         'Echos', | ||||
| @@ -106,6 +113,20 @@ class BladeCompiler extends Compiler implements CompilerInterface | ||||
|      */ | ||||
|     protected $rawBlocks = []; | ||||
|  | ||||
|     /** | ||||
|      * The array of class component aliases and their class names. | ||||
|      * | ||||
|      * @var array | ||||
|      */ | ||||
|     protected $classComponentAliases = []; | ||||
|  | ||||
|     /** | ||||
|      * Indicates if component tags should be compiled. | ||||
|      * | ||||
|      * @var bool | ||||
|      */ | ||||
|     protected $compilesComponentTags = true; | ||||
|  | ||||
|     /** | ||||
|      * Compile the view at the given path. | ||||
|      * | ||||
| @@ -194,7 +215,16 @@ class BladeCompiler extends Compiler implements CompilerInterface | ||||
|     { | ||||
|         [$this->footer, $result] = [[], '']; | ||||
|  | ||||
|         $value = $this->storeUncompiledBlocks($value); | ||||
|         // First we will compile the Blade component tags. This is a precompile style | ||||
|         // step which compiles the component Blade tags into @component directives | ||||
|         // that may be used by Blade. Then we should call any other precompilers. | ||||
|         $value = $this->compileComponentTags( | ||||
|             $this->compileComments($this->storeUncompiledBlocks($value)) | ||||
|         ); | ||||
|  | ||||
|         foreach ($this->precompilers as $precompiler) { | ||||
|             $value = call_user_func($precompiler, $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 | ||||
| @@ -275,6 +305,23 @@ class BladeCompiler extends Compiler implements CompilerInterface | ||||
|         ); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Compile the component tags. | ||||
|      * | ||||
|      * @param  string  $value | ||||
|      * @return string | ||||
|      */ | ||||
|     protected function compileComponentTags($value) | ||||
|     { | ||||
|         if (! $this->compilesComponentTags) { | ||||
|             return $value; | ||||
|         } | ||||
|  | ||||
|         return (new ComponentTagCompiler( | ||||
|             $this->classComponentAliases, $this | ||||
|         ))->compile($value); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Replace the raw placeholders with the original code stored in the raw blocks. | ||||
|      * | ||||
| @@ -311,8 +358,8 @@ class BladeCompiler extends Compiler implements CompilerInterface | ||||
|      */ | ||||
|     protected function addFooters($result) | ||||
|     { | ||||
|         return ltrim($result, PHP_EOL) | ||||
|                 .PHP_EOL.implode(PHP_EOL, array_reverse($this->footer)); | ||||
|         return ltrim($result, "\n") | ||||
|                 ."\n".implode("\n", array_reverse($this->footer)); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -481,6 +528,63 @@ class BladeCompiler extends Compiler implements CompilerInterface | ||||
|         return call_user_func($this->conditions[$name], ...$parameters); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Register a class-based component alias directive. | ||||
|      * | ||||
|      * @param  string  $class | ||||
|      * @param  string|null  $alias | ||||
|      * @param  string  $prefix | ||||
|      * @return void | ||||
|      */ | ||||
|     public function component($class, $alias = null, $prefix = '') | ||||
|     { | ||||
|         if (! is_null($alias) && Str::contains($alias, '\\')) { | ||||
|             [$class, $alias] = [$alias, $class]; | ||||
|         } | ||||
|  | ||||
|         if (is_null($alias)) { | ||||
|             $alias = Str::contains($class, '\\View\\Components\\') | ||||
|                             ? collect(explode('\\', Str::after($class, '\\View\\Components\\')))->map(function ($segment) { | ||||
|                                 return Str::kebab($segment); | ||||
|                             })->implode(':') | ||||
|                             : Str::kebab(class_basename($class)); | ||||
|         } | ||||
|  | ||||
|         if (! empty($prefix)) { | ||||
|             $alias = $prefix.'-'.$alias; | ||||
|         } | ||||
|  | ||||
|         $this->classComponentAliases[$alias] = $class; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Register an array of class-based components. | ||||
|      * | ||||
|      * @param  array  $components | ||||
|      * @param  string  $prefix | ||||
|      * @return void | ||||
|      */ | ||||
|     public function components(array $components, $prefix = '') | ||||
|     { | ||||
|         foreach ($components as $key => $value) { | ||||
|             if (is_numeric($key)) { | ||||
|                 static::component($value, null, $prefix); | ||||
|             } else { | ||||
|                 static::component($key, $value, $prefix); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get the registered class component aliases. | ||||
|      * | ||||
|      * @return array | ||||
|      */ | ||||
|     public function getClassComponentAliases() | ||||
|     { | ||||
|         return $this->classComponentAliases; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Register a component alias directive. | ||||
|      * | ||||
| @@ -488,7 +592,7 @@ class BladeCompiler extends Compiler implements CompilerInterface | ||||
|      * @param  string|null  $alias | ||||
|      * @return void | ||||
|      */ | ||||
|     public function component($path, $alias = null) | ||||
|     public function aliasComponent($path, $alias = null) | ||||
|     { | ||||
|         $alias = $alias ?: Arr::last(explode('.', $path)); | ||||
|  | ||||
| @@ -511,6 +615,18 @@ class BladeCompiler extends Compiler implements CompilerInterface | ||||
|      * @return void | ||||
|      */ | ||||
|     public function include($path, $alias = null) | ||||
|     { | ||||
|         return $this->aliasInclude($path, $alias); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Register an include alias directive. | ||||
|      * | ||||
|      * @param  string  $path | ||||
|      * @param  string|null  $alias | ||||
|      * @return void | ||||
|      */ | ||||
|     public function aliasInclude($path, $alias = null) | ||||
|     { | ||||
|         $alias = $alias ?: Arr::last(explode('.', $path)); | ||||
|  | ||||
| @@ -549,6 +665,17 @@ class BladeCompiler extends Compiler implements CompilerInterface | ||||
|         return $this->customDirectives; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Register a new precompiler. | ||||
|      * | ||||
|      * @param  callable  $precompiler | ||||
|      * @return void | ||||
|      */ | ||||
|     public function precompiler(callable $precompiler) | ||||
|     { | ||||
|         $this->precompilers[] = $precompiler; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Set the echo format to be used by the compiler. | ||||
|      * | ||||
| @@ -579,4 +706,14 @@ class BladeCompiler extends Compiler implements CompilerInterface | ||||
|     { | ||||
|         $this->setEchoFormat('e(%s, false)'); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Indicate that component tags should not be compiled. | ||||
|      * | ||||
|      * @return void | ||||
|      */ | ||||
|     public function withoutComponentTags() | ||||
|     { | ||||
|         $this->compilesComponentTags = false; | ||||
|     } | ||||
| } | ||||
|   | ||||
							
								
								
									
										488
									
								
								vendor/laravel/framework/src/Illuminate/View/Compilers/ComponentTagCompiler.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										488
									
								
								vendor/laravel/framework/src/Illuminate/View/Compilers/ComponentTagCompiler.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,488 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Illuminate\View\Compilers; | ||||
|  | ||||
| use Illuminate\Container\Container; | ||||
| use Illuminate\Contracts\Foundation\Application; | ||||
| use Illuminate\Contracts\View\Factory; | ||||
| use Illuminate\Filesystem\Filesystem; | ||||
| use Illuminate\Support\Str; | ||||
| use Illuminate\View\AnonymousComponent; | ||||
| use Illuminate\View\ViewFinderInterface; | ||||
| use InvalidArgumentException; | ||||
| use ReflectionClass; | ||||
|  | ||||
| /** | ||||
|  * @author Spatie bvba <info@spatie.be> | ||||
|  * @author Taylor Otwell <taylor@laravel.com> | ||||
|  */ | ||||
| class ComponentTagCompiler | ||||
| { | ||||
|     /** | ||||
|      * The Blade compiler instance. | ||||
|      * | ||||
|      * @var \Illuminate\View\Compilers\BladeCompiler | ||||
|      */ | ||||
|     protected $blade; | ||||
|  | ||||
|     /** | ||||
|      * The component class aliases. | ||||
|      * | ||||
|      * @var array | ||||
|      */ | ||||
|     protected $aliases = []; | ||||
|  | ||||
|     /** | ||||
|      * The "bind:" attributes that have been compiled for the current component. | ||||
|      * | ||||
|      * @var array | ||||
|      */ | ||||
|     protected $boundAttributes = []; | ||||
|  | ||||
|     /** | ||||
|      * Create new component tag compiler. | ||||
|      * | ||||
|      * @param  array  $aliases | ||||
|      * @param  \Illuminate\View\Compilers\BladeCompiler|null | ||||
|      * @return void | ||||
|      */ | ||||
|     public function __construct(array $aliases = [], ?BladeCompiler $blade = null) | ||||
|     { | ||||
|         $this->aliases = $aliases; | ||||
|  | ||||
|         $this->blade = $blade ?: new BladeCompiler(new Filesystem, sys_get_temp_dir()); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Compile the component and slot tags within the given string. | ||||
|      * | ||||
|      * @param  string  $value | ||||
|      * @return string | ||||
|      */ | ||||
|     public function compile(string $value) | ||||
|     { | ||||
|         $value = $this->compileSlots($value); | ||||
|  | ||||
|         return $this->compileTags($value); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Compile the tags within the given string. | ||||
|      * | ||||
|      * @param  string  $value | ||||
|      * @return string | ||||
|      * | ||||
|      * @throws \InvalidArgumentException | ||||
|      */ | ||||
|     public function compileTags(string $value) | ||||
|     { | ||||
|         $value = $this->compileSelfClosingTags($value); | ||||
|         $value = $this->compileOpeningTags($value); | ||||
|         $value = $this->compileClosingTags($value); | ||||
|  | ||||
|         return $value; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Compile the opening tags within the given string. | ||||
|      * | ||||
|      * @param  string  $value | ||||
|      * @return string | ||||
|      * | ||||
|      * @throws \InvalidArgumentException | ||||
|      */ | ||||
|     protected function compileOpeningTags(string $value) | ||||
|     { | ||||
|         $pattern = "/ | ||||
|             < | ||||
|                 \s* | ||||
|                 x[-\:]([\w\-\:\.]*) | ||||
|                 (?<attributes> | ||||
|                     (?: | ||||
|                         \s+ | ||||
|                         [\w\-:.@]+ | ||||
|                         ( | ||||
|                             = | ||||
|                             (?: | ||||
|                                 \\\"[^\\\"]*\\\" | ||||
|                                 | | ||||
|                                 \'[^\']*\' | ||||
|                                 | | ||||
|                                 [^\'\\\"=<>]+ | ||||
|                             ) | ||||
|                         ) | ||||
|                     ?)* | ||||
|                     \s* | ||||
|                 ) | ||||
|                 (?<![\/=\-]) | ||||
|             > | ||||
|         /x"; | ||||
|  | ||||
|         return preg_replace_callback($pattern, function (array $matches) { | ||||
|             $this->boundAttributes = []; | ||||
|  | ||||
|             $attributes = $this->getAttributesFromAttributeString($matches['attributes']); | ||||
|  | ||||
|             return $this->componentString($matches[1], $attributes); | ||||
|         }, $value); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Compile the self-closing tags within the given string. | ||||
|      * | ||||
|      * @param  string  $value | ||||
|      * @return string | ||||
|      * | ||||
|      * @throws \InvalidArgumentException | ||||
|      */ | ||||
|     protected function compileSelfClosingTags(string $value) | ||||
|     { | ||||
|         $pattern = "/ | ||||
|             < | ||||
|                 \s* | ||||
|                 x[-\:]([\w\-\:\.]*) | ||||
|                 \s* | ||||
|                 (?<attributes> | ||||
|                     (?: | ||||
|                         \s+ | ||||
|                         [\w\-:.@]+ | ||||
|                         ( | ||||
|                             = | ||||
|                             (?: | ||||
|                                 \\\"[^\\\"]*\\\" | ||||
|                                 | | ||||
|                                 \'[^\']*\' | ||||
|                                 | | ||||
|                                 [^\'\\\"=<>]+ | ||||
|                             ) | ||||
|                         )? | ||||
|                     )* | ||||
|                     \s* | ||||
|                 ) | ||||
|             \/> | ||||
|         /x"; | ||||
|  | ||||
|         return preg_replace_callback($pattern, function (array $matches) { | ||||
|             $this->boundAttributes = []; | ||||
|  | ||||
|             $attributes = $this->getAttributesFromAttributeString($matches['attributes']); | ||||
|  | ||||
|             return $this->componentString($matches[1], $attributes)."\n@endcomponentClass "; | ||||
|         }, $value); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Compile the Blade component string for the given component and attributes. | ||||
|      * | ||||
|      * @param  string  $component | ||||
|      * @param  array  $attributes | ||||
|      * @return string | ||||
|      * | ||||
|      * @throws \InvalidArgumentException | ||||
|      */ | ||||
|     protected function componentString(string $component, array $attributes) | ||||
|     { | ||||
|         $class = $this->componentClass($component); | ||||
|  | ||||
|         [$data, $attributes] = $this->partitionDataAndAttributes($class, $attributes); | ||||
|  | ||||
|         $data = $data->mapWithKeys(function ($value, $key) { | ||||
|             return [Str::camel($key) => $value]; | ||||
|         }); | ||||
|  | ||||
|         // If the component doesn't exists as a class we'll assume it's a class-less | ||||
|         // component and pass the component as a view parameter to the data so it | ||||
|         // can be accessed within the component and we can render out the view. | ||||
|         if (! class_exists($class)) { | ||||
|             $parameters = [ | ||||
|                 'view' => "'$class'", | ||||
|                 'data' => '['.$this->attributesToString($data->all(), $escapeBound = false).']', | ||||
|             ]; | ||||
|  | ||||
|             $class = AnonymousComponent::class; | ||||
|         } else { | ||||
|             $parameters = $data->all(); | ||||
|         } | ||||
|  | ||||
|         return " @component('{$class}', '{$component}', [".$this->attributesToString($parameters, $escapeBound = false).']) | ||||
| <?php $component->withAttributes(['.$this->attributesToString($attributes->all()).']); ?>'; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get the component class for a given component alias. | ||||
|      * | ||||
|      * @param  string  $component | ||||
|      * @return string | ||||
|      * | ||||
|      * @throws \InvalidArgumentException | ||||
|      */ | ||||
|     protected function componentClass(string $component) | ||||
|     { | ||||
|         $viewFactory = Container::getInstance()->make(Factory::class); | ||||
|  | ||||
|         if (isset($this->aliases[$component])) { | ||||
|             if (class_exists($alias = $this->aliases[$component])) { | ||||
|                 return $alias; | ||||
|             } | ||||
|  | ||||
|             if ($viewFactory->exists($alias)) { | ||||
|                 return $alias; | ||||
|             } | ||||
|  | ||||
|             throw new InvalidArgumentException( | ||||
|                 "Unable to locate class or view [{$alias}] for component [{$component}]." | ||||
|             ); | ||||
|         } | ||||
|  | ||||
|         if (class_exists($class = $this->guessClassName($component))) { | ||||
|             return $class; | ||||
|         } | ||||
|  | ||||
|         if ($viewFactory->exists($view = $this->guessViewName($component))) { | ||||
|             return $view; | ||||
|         } | ||||
|  | ||||
|         throw new InvalidArgumentException( | ||||
|             "Unable to locate a class or view for component [{$component}]." | ||||
|         ); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Guess the class name for the given component. | ||||
|      * | ||||
|      * @param  string  $component | ||||
|      * @return string | ||||
|      */ | ||||
|     public function guessClassName(string $component) | ||||
|     { | ||||
|         $namespace = Container::getInstance() | ||||
|                     ->make(Application::class) | ||||
|                     ->getNamespace(); | ||||
|  | ||||
|         $componentPieces = array_map(function ($componentPiece) { | ||||
|             return ucfirst(Str::camel($componentPiece)); | ||||
|         }, explode('.', $component)); | ||||
|  | ||||
|         return $namespace.'View\\Components\\'.implode('\\', $componentPieces); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Guess the view name for the given component. | ||||
|      * | ||||
|      * @param  string  $name | ||||
|      * @return string | ||||
|      */ | ||||
|     public function guessViewName($name) | ||||
|     { | ||||
|         $prefix = 'components.'; | ||||
|  | ||||
|         $delimiter = ViewFinderInterface::HINT_PATH_DELIMITER; | ||||
|  | ||||
|         if (Str::contains($name, $delimiter)) { | ||||
|             return Str::replaceFirst($delimiter, $delimiter.$prefix, $name); | ||||
|         } | ||||
|  | ||||
|         return $prefix.$name; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Partition the data and extra attributes from the given array of attributes. | ||||
|      * | ||||
|      * @param  string  $class | ||||
|      * @param  array  $attributes | ||||
|      * @return array | ||||
|      */ | ||||
|     protected function partitionDataAndAttributes($class, array $attributes) | ||||
|     { | ||||
|         // If the class doesn't exists, we'll assume it's a class-less component and | ||||
|         // return all of the attributes as both data and attributes since we have | ||||
|         // now way to partition them. The user can exclude attributes manually. | ||||
|         if (! class_exists($class)) { | ||||
|             return [collect($attributes), collect($attributes)]; | ||||
|         } | ||||
|  | ||||
|         $constructor = (new ReflectionClass($class))->getConstructor(); | ||||
|  | ||||
|         $parameterNames = $constructor | ||||
|                     ? collect($constructor->getParameters())->map->getName()->all() | ||||
|                     : []; | ||||
|  | ||||
|         return collect($attributes)->partition(function ($value, $key) use ($parameterNames) { | ||||
|             return in_array(Str::camel($key), $parameterNames); | ||||
|         })->all(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Compile the closing tags within the given string. | ||||
|      * | ||||
|      * @param  string  $value | ||||
|      * @return string | ||||
|      */ | ||||
|     protected function compileClosingTags(string $value) | ||||
|     { | ||||
|         return preg_replace("/<\/\s*x[-\:][\w\-\:\.]*\s*>/", ' @endcomponentClass ', $value); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Compile the slot tags within the given string. | ||||
|      * | ||||
|      * @param  string  $value | ||||
|      * @return string | ||||
|      */ | ||||
|     public function compileSlots(string $value) | ||||
|     { | ||||
|         $value = preg_replace_callback('/<\s*x[\-\:]slot\s+(:?)name=(?<name>(\"[^\"]+\"|\\\'[^\\\']+\\\'|[^\s>]+))\s*>/', function ($matches) { | ||||
|             $name = $this->stripQuotes($matches['name']); | ||||
|  | ||||
|             if ($matches[1] !== ':') { | ||||
|                 $name = "'{$name}'"; | ||||
|             } | ||||
|  | ||||
|             return " @slot({$name}) "; | ||||
|         }, $value); | ||||
|  | ||||
|         return preg_replace('/<\/\s*x[\-\:]slot[^>]*>/', ' @endslot', $value); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get an array of attributes from the given attribute string. | ||||
|      * | ||||
|      * @param  string  $attributeString | ||||
|      * @return array | ||||
|      */ | ||||
|     protected function getAttributesFromAttributeString(string $attributeString) | ||||
|     { | ||||
|         $attributeString = $this->parseBindAttributes($attributeString); | ||||
|  | ||||
|         $pattern = '/ | ||||
|             (?<attribute>[\w\-:.@]+) | ||||
|             ( | ||||
|                 = | ||||
|                 (?<value> | ||||
|                     ( | ||||
|                         \"[^\"]+\" | ||||
|                         | | ||||
|                         \\\'[^\\\']+\\\' | ||||
|                         | | ||||
|                         [^\s>]+ | ||||
|                     ) | ||||
|                 ) | ||||
|             )? | ||||
|         /x'; | ||||
|  | ||||
|         if (! preg_match_all($pattern, $attributeString, $matches, PREG_SET_ORDER)) { | ||||
|             return []; | ||||
|         } | ||||
|  | ||||
|         return collect($matches)->mapWithKeys(function ($match) { | ||||
|             $attribute = $match['attribute']; | ||||
|             $value = $match['value'] ?? null; | ||||
|  | ||||
|             if (is_null($value)) { | ||||
|                 $value = 'true'; | ||||
|  | ||||
|                 $attribute = Str::start($attribute, 'bind:'); | ||||
|             } | ||||
|  | ||||
|             $value = $this->stripQuotes($value); | ||||
|  | ||||
|             if (Str::startsWith($attribute, 'bind:')) { | ||||
|                 $attribute = Str::after($attribute, 'bind:'); | ||||
|  | ||||
|                 $this->boundAttributes[$attribute] = true; | ||||
|             } else { | ||||
|                 $value = "'".$this->compileAttributeEchos($value)."'"; | ||||
|             } | ||||
|  | ||||
|             return [$attribute => $value]; | ||||
|         })->toArray(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Parse the "bind" attributes in a given attribute string into their fully-qualified syntax. | ||||
|      * | ||||
|      * @param  string  $attributeString | ||||
|      * @return string | ||||
|      */ | ||||
|     protected function parseBindAttributes(string $attributeString) | ||||
|     { | ||||
|         $pattern = "/ | ||||
|             (?:^|\s+)     # start of the string or whitespace between attributes | ||||
|             :             # attribute needs to start with a semicolon | ||||
|             ([\w\-:.@]+)  # match the actual attribute name | ||||
|             =             # only match attributes that have a value | ||||
|         /xm"; | ||||
|  | ||||
|         return preg_replace($pattern, ' bind:$1=', $attributeString); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Compile any Blade echo statements that are present in the attribute string. | ||||
|      * | ||||
|      * These echo statements need to be converted to string concatenation statements. | ||||
|      * | ||||
|      * @param  string  $attributeString | ||||
|      * @return string | ||||
|      */ | ||||
|     protected function compileAttributeEchos(string $attributeString) | ||||
|     { | ||||
|         $value = $this->blade->compileEchos($attributeString); | ||||
|  | ||||
|         $value = $this->escapeSingleQuotesOutsideOfPhpBlocks($value); | ||||
|  | ||||
|         $value = str_replace('<?php echo ', '\'.', $value); | ||||
|         $value = str_replace('; ?>', '.\'', $value); | ||||
|  | ||||
|         return $value; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Escape the single quotes in the given string that are outside of PHP blocks. | ||||
|      * | ||||
|      * @param  string  $value | ||||
|      * @return string | ||||
|      */ | ||||
|     protected function escapeSingleQuotesOutsideOfPhpBlocks(string $value) | ||||
|     { | ||||
|         return collect(token_get_all($value))->map(function ($token) { | ||||
|             if (! is_array($token)) { | ||||
|                 return $token; | ||||
|             } | ||||
|  | ||||
|             return $token[0] === T_INLINE_HTML | ||||
|                         ? str_replace("'", "\\'", $token[1]) | ||||
|                         : $token[1]; | ||||
|         })->implode(''); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Convert an array of attributes to a string. | ||||
|      * | ||||
|      * @param  array  $attributes | ||||
|      * @param  bool  $escapeBound | ||||
|      * @return string | ||||
|      */ | ||||
|     protected function attributesToString(array $attributes, $escapeBound = true) | ||||
|     { | ||||
|         return collect($attributes) | ||||
|                 ->map(function (string $value, string $attribute) use ($escapeBound) { | ||||
|                     return $escapeBound && isset($this->boundAttributes[$attribute]) && $value !== 'true' && ! is_numeric($value) | ||||
|                                 ? "'{$attribute}' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute({$value})" | ||||
|                                 : "'{$attribute}' => {$value}"; | ||||
|                 }) | ||||
|                 ->implode(','); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Strip any quotes from the given string. | ||||
|      * | ||||
|      * @param  string  $value | ||||
|      * @return string | ||||
|      */ | ||||
|     public function stripQuotes(string $value) | ||||
|     { | ||||
|         return Str::startsWith($value, ['"', '\'']) | ||||
|                     ? substr($value, 1, -1) | ||||
|                     : $value; | ||||
|     } | ||||
| } | ||||
| @@ -2,8 +2,17 @@ | ||||
|  | ||||
| namespace Illuminate\View\Compilers\Concerns; | ||||
|  | ||||
| use Illuminate\Support\Str; | ||||
|  | ||||
| trait CompilesComponents | ||||
| { | ||||
|     /** | ||||
|      * The component name hash stack. | ||||
|      * | ||||
|      * @var array | ||||
|      */ | ||||
|     protected static $componentHashStack = []; | ||||
|  | ||||
|     /** | ||||
|      * Compile the component statements into valid PHP. | ||||
|      * | ||||
| @@ -12,9 +21,54 @@ trait CompilesComponents | ||||
|      */ | ||||
|     protected function compileComponent($expression) | ||||
|     { | ||||
|         [$component, $alias, $data] = strpos($expression, ',') !== false | ||||
|                     ? array_map('trim', explode(',', trim($expression, '()'), 3)) + ['', '', ''] | ||||
|                     : [trim($expression, '()'), '', '']; | ||||
|  | ||||
|         $component = trim($component, '\'"'); | ||||
|  | ||||
|         $hash = static::newComponentHash($component); | ||||
|  | ||||
|         if (Str::contains($component, ['::class', '\\'])) { | ||||
|             return static::compileClassComponentOpening($component, $alias, $data, $hash); | ||||
|         } | ||||
|  | ||||
|         return "<?php \$__env->startComponent{$expression}; ?>"; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get a new component hash for a component name. | ||||
|      * | ||||
|      * @param  string  $component | ||||
|      * @return string | ||||
|      */ | ||||
|     public static function newComponentHash(string $component) | ||||
|     { | ||||
|         static::$componentHashStack[] = $hash = sha1($component); | ||||
|  | ||||
|         return $hash; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Compile a class component opening. | ||||
|      * | ||||
|      * @param  string  $component | ||||
|      * @param  string  $alias | ||||
|      * @param  string  $data | ||||
|      * @param  string  $hash | ||||
|      * @return string | ||||
|      */ | ||||
|     public static function compileClassComponentOpening(string $component, string $alias, string $data, string $hash) | ||||
|     { | ||||
|         return implode("\n", [ | ||||
|             '<?php if (isset($component)) { $__componentOriginal'.$hash.' = $component; } ?>', | ||||
|             '<?php $component = $__env->getContainer()->make('.Str::finish($component, '::class').', '.($data ?: '[]').'); ?>', | ||||
|             '<?php $component->withName('.$alias.'); ?>', | ||||
|             '<?php if ($component->shouldRender()): ?>', | ||||
|             '<?php $__env->startComponent($component->resolveView(), $component->data()); ?>', | ||||
|         ]); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Compile the end-component statements into valid PHP. | ||||
|      * | ||||
| @@ -22,7 +76,27 @@ trait CompilesComponents | ||||
|      */ | ||||
|     protected function compileEndComponent() | ||||
|     { | ||||
|         return '<?php echo $__env->renderComponent(); ?>'; | ||||
|         $hash = array_pop(static::$componentHashStack); | ||||
|  | ||||
|         return implode("\n", [ | ||||
|             '<?php if (isset($__componentOriginal'.$hash.')): ?>', | ||||
|             '<?php $component = $__componentOriginal'.$hash.'; ?>', | ||||
|             '<?php unset($__componentOriginal'.$hash.'); ?>', | ||||
|             '<?php endif; ?>', | ||||
|             '<?php echo $__env->renderComponent(); ?>', | ||||
|         ]); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Compile the end-component statements into valid PHP. | ||||
|      * | ||||
|      * @return string | ||||
|      */ | ||||
|     public function compileEndComponentClass() | ||||
|     { | ||||
|         return static::compileEndComponent()."\n".implode("\n", [ | ||||
|             '<?php endif; ?>', | ||||
|         ]); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -66,4 +140,37 @@ trait CompilesComponents | ||||
|     { | ||||
|         return $this->compileEndComponent(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Compile the prop statement into valid PHP. | ||||
|      * | ||||
|      * @param  string  $expression | ||||
|      * @return string | ||||
|      */ | ||||
|     protected function compileProps($expression) | ||||
|     { | ||||
|         return "<?php \$attributes = \$attributes->exceptProps{$expression}; ?> | ||||
| <?php foreach (array_filter({$expression}, 'is_string', ARRAY_FILTER_USE_KEY) as \$__key => \$__value) { | ||||
|     \$\$__key = \$\$__key ?? \$__value; | ||||
| } ?> | ||||
| <?php \$__defined_vars = get_defined_vars(); ?> | ||||
| <?php foreach (\$attributes as \$__key => \$__value) { | ||||
|     if (array_key_exists(\$__key, \$__defined_vars)) unset(\$\$__key); | ||||
| } ?> | ||||
| <?php unset(\$__defined_vars); ?>"; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Sanitize the given component attribute value. | ||||
|      * | ||||
|      * @param  mixed  $value | ||||
|      * @return mixed | ||||
|      */ | ||||
|     public static function sanitizeComponentAttribute($value) | ||||
|     { | ||||
|         return is_string($value) || | ||||
|                (is_object($value) && method_exists($value, '__toString')) | ||||
|                         ? e($value) | ||||
|                         : $value; | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -2,6 +2,8 @@ | ||||
|  | ||||
| namespace Illuminate\View\Compilers\Concerns; | ||||
|  | ||||
| use Illuminate\Support\Str; | ||||
|  | ||||
| trait CompilesConditionals | ||||
| { | ||||
|     /** | ||||
| @@ -47,6 +49,47 @@ trait CompilesConditionals | ||||
|         return '<?php endif; ?>'; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Compile the env statements into valid PHP. | ||||
|      * | ||||
|      * @param  string  $environments | ||||
|      * @return string | ||||
|      */ | ||||
|     protected function compileEnv($environments) | ||||
|     { | ||||
|         return "<?php if(app()->environment{$environments}): ?>"; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Compile the end-env statements into valid PHP. | ||||
|      * | ||||
|      * @return string | ||||
|      */ | ||||
|     protected function compileEndEnv() | ||||
|     { | ||||
|         return '<?php endif; ?>'; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Compile the production statements into valid PHP. | ||||
|      * | ||||
|      * @return string | ||||
|      */ | ||||
|     protected function compileProduction() | ||||
|     { | ||||
|         return "<?php if(app()->environment('production')): ?>"; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Compile the end-production statements into valid PHP. | ||||
|      * | ||||
|      * @return string | ||||
|      */ | ||||
|     protected function compileEndProduction() | ||||
|     { | ||||
|         return '<?php endif; ?>'; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Compile the if-guest statements into valid PHP. | ||||
|      * | ||||
| @@ -94,6 +137,17 @@ trait CompilesConditionals | ||||
|         return "<?php if (! empty(trim(\$__env->yieldContent{$expression}))): ?>"; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Compile the section-missing statements into valid PHP. | ||||
|      * | ||||
|      * @param  string  $expression | ||||
|      * @return string | ||||
|      */ | ||||
|     protected function compileSectionMissing($expression) | ||||
|     { | ||||
|         return "<?php if (empty(trim(\$__env->yieldContent{$expression}))): ?>"; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Compile the if statements into valid PHP. | ||||
|      * | ||||
| @@ -227,4 +281,26 @@ trait CompilesConditionals | ||||
|     { | ||||
|         return '<?php endswitch; ?>'; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Compile an once block into valid PHP. | ||||
|      * | ||||
|      * @return string | ||||
|      */ | ||||
|     protected function compileOnce($id = null) | ||||
|     { | ||||
|         $id = $id ? $this->stripParentheses($id) : "'".(string) Str::uuid()."'"; | ||||
|  | ||||
|         return '<?php if (! $__env->hasRenderedOnce('.$id.')): $__env->markAsRenderedOnce('.$id.'); ?>'; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Compile an end-once block into valid PHP. | ||||
|      * | ||||
|      * @return string | ||||
|      */ | ||||
|     public function compileEndOnce() | ||||
|     { | ||||
|         return '<?php endif; ?>'; | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -10,7 +10,7 @@ trait CompilesEchos | ||||
|      * @param  string  $value | ||||
|      * @return string | ||||
|      */ | ||||
|     protected function compileEchos($value) | ||||
|     public function compileEchos($value) | ||||
|     { | ||||
|         foreach ($this->getEchoMethods() as $method) { | ||||
|             $value = $this->$method($value); | ||||
|   | ||||
| @@ -7,7 +7,7 @@ trait CompilesTranslations | ||||
|     /** | ||||
|      * Compile the lang statements into valid PHP. | ||||
|      * | ||||
|      * @param  string  $expression | ||||
|      * @param  string|null  $expression | ||||
|      * @return string | ||||
|      */ | ||||
|     protected function compileLang($expression) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 RafficMohammed
					RafficMohammed