From c723e50b4de8f7198e2a77307aad79f822755605 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20Duli=C3=A7i?= Date: Wed, 10 Mar 2021 18:08:43 +0300 Subject: [PATCH] Revert "overriding ManagesStacks.php is not necessary anymore" --- composer.json | 2 + .../View/Concerns/ManagesStacks.php | 201 ++++++++++++++++++ 2 files changed, 203 insertions(+) create mode 100644 overrides/Illuminate/View/Concerns/ManagesStacks.php diff --git a/composer.json b/composer.json index 7b5466255..999eec718 100644 --- a/composer.json +++ b/composer.json @@ -86,6 +86,7 @@ "Database\\Factories\\": "database/factories/", "Database\\Seeds\\": "database/seeds/", "Illuminate\\Translation\\": "overrides/Illuminate/Translation/", + "Illuminate\\View\\Concerns\\": "overrides/Illuminate/View/Concerns/", "Modules\\": "modules/", "Symfony\\Component\\Process\\": "overrides/symfony/process/" }, @@ -95,6 +96,7 @@ "vendor/akaunting/laravel-module/src/Commands/EnableCommand.php", "vendor/akaunting/laravel-module/src/Commands/InstallCommand.php", "vendor/laravel/framework/src/Illuminate/Translation/MessageSelector.php", + "vendor/laravel/framework/src/Illuminate/View/Concerns/ManagesStacks.php", "vendor/symfony/process/PhpExecutableFinder.php" ], "files": [ diff --git a/overrides/Illuminate/View/Concerns/ManagesStacks.php b/overrides/Illuminate/View/Concerns/ManagesStacks.php new file mode 100644 index 000000000..1825bc7e1 --- /dev/null +++ b/overrides/Illuminate/View/Concerns/ManagesStacks.php @@ -0,0 +1,201 @@ +pushStack[] = $section; + } + } else { + $this->extendPush($section, $content); + } + } + + /** + * Stop injecting content into a push section. + * + * @return string + * + * @throws \InvalidArgumentException + */ + public function stopPush() + { + if (empty($this->pushStack)) { + throw new InvalidArgumentException('Cannot end a push stack without first starting one.'); + } + + return tap(array_pop($this->pushStack), function ($last) { + $this->extendPush($last, ob_get_clean()); + }); + } + + /** + * Append content to a given push section. + * + * @param string $section + * @param string $content + * @return void + */ + protected function extendPush($section, $content) + { + if (! isset($this->pushes[$section])) { + $this->pushes[$section] = []; + } + + if (! isset($this->pushes[$section][$this->renderCount])) { + $this->pushes[$section][$this->renderCount] = $content; + } else { + $this->pushes[$section][$this->renderCount] .= $content; + } + } + + /** + * Start prepending content into a push section. + * + * @param string $section + * @param string $content + * @return void + */ + public function startPrepend($section, $content = '') + { + if ($content === '') { + if (ob_start()) { + $this->pushStack[] = $section; + } + } else { + $this->extendPrepend($section, $content); + } + } + + /** + * Stop prepending content into a push section. + * + * @return string + * + * @throws \InvalidArgumentException + */ + public function stopPrepend() + { + if (empty($this->pushStack)) { + throw new InvalidArgumentException('Cannot end a prepend operation without first starting one.'); + } + + return tap(array_pop($this->pushStack), function ($last) { + $this->extendPrepend($last, ob_get_clean()); + }); + } + + /** + * Prepend content to a given stack. + * + * @param string $section + * @param string $content + * @return void + */ + protected function extendPrepend($section, $content) + { + if (! isset($this->prepends[$section])) { + $this->prepends[$section] = []; + } + + if (! isset($this->prepends[$section][$this->renderCount])) { + $this->prepends[$section][$this->renderCount] = $content; + } else { + $this->prepends[$section][$this->renderCount] = $content.$this->prepends[$section][$this->renderCount]; + } + } + + /** + * Get the string contents of a push section. + * + * @param string $section + * @param string $default + * @return string + */ + public function yieldPushContent($section, $default = '') + { + if (! isset($this->pushes[$section]) && ! isset($this->prepends[$section])) { + return $default; + } + + $output = ''; + + if (isset($this->prepends[$section])) { + $output .= implode(array_reverse($this->prepends[$section])); + } + + if (isset($this->pushes[$section])) { + $output .= implode($this->pushes[$section]); + } + + return $output; + } + + /** + * Flush all of the stacks. + * + * @return void + */ + public function flushStacks() + { + $this->pushes = []; + $this->prepends = []; + $this->pushStack = []; + } + + /** + * Flush stack by key. + * + * @return void + */ + public function flushStack($key = null) + { + $properties = [ + 'pushes', + 'prepends', + 'pushStack', + ]; + + foreach ($properties as $property) { + if (!array_key_exists($key, $this->$property)) { + continue; + } + + unset($this->$property[$key]); + } + } +}