@@ -35,7 +35,7 @@ |
||
| 35 | 35 | */ |
| 36 | 36 | public function register() |
| 37 | 37 | { |
| 38 | - $this->app->singleton('cookie', function ($app) { |
|
| 38 | + $this->app->singleton('cookie', function($app) { |
|
| 39 | 39 | $config = $app->make('config')->get('session'); |
| 40 | 40 | |
| 41 | 41 | return (new CookieManager)->setDefaultPathAndDomain( |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | |
| 80 | 80 | try { |
| 81 | 81 | $this->files->getRequire($path, $data); |
| 82 | - } catch(Throwable $e) { |
|
| 82 | + } catch (Throwable $e) { |
|
| 83 | 83 | return $this->handleViewException($e, $obLevel); |
| 84 | 84 | } |
| 85 | 85 | |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | */ |
| 99 | 99 | protected function handleViewException(Throwable $e, $obLevel): void |
| 100 | 100 | { |
| 101 | - while(ob_get_level() > $obLevel) { |
|
| 101 | + while (ob_get_level() > $obLevel) { |
|
| 102 | 102 | ob_end_clean(); |
| 103 | 103 | } |
| 104 | 104 | |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | */ |
| 56 | 56 | public function registerView() |
| 57 | 57 | { |
| 58 | - $this->app->singleton('view', function ($app) { |
|
| 58 | + $this->app->singleton('view', function($app) { |
|
| 59 | 59 | // The resolver will be used by an environment to get each of the various |
| 60 | 60 | // engine implementations such as plain PHP or Plaze engine. |
| 61 | 61 | $resolver = $app['view.engine.resolver']; |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | */ |
| 103 | 103 | public function registerEngineResolver() |
| 104 | 104 | { |
| 105 | - $this->app->singleton('view.engine.resolver', function () { |
|
| 105 | + $this->app->singleton('view.engine.resolver', function() { |
|
| 106 | 106 | $resolver = new EngineResolver; |
| 107 | 107 | |
| 108 | 108 | // Register of the various view engines with the resolver |
@@ -27,45 +27,45 @@ |
||
| 27 | 27 | */ |
| 28 | 28 | trait Extensions |
| 29 | 29 | { |
| 30 | - /** |
|
| 31 | - * The file extension. |
|
| 32 | - * |
|
| 33 | - * @var array $extension |
|
| 34 | - */ |
|
| 35 | - protected $extension = [ |
|
| 36 | - 'plaze.php', |
|
| 37 | - 'php', |
|
| 38 | - 'html', |
|
| 39 | - ]; |
|
| 30 | + /** |
|
| 31 | + * The file extension. |
|
| 32 | + * |
|
| 33 | + * @var array $extension |
|
| 34 | + */ |
|
| 35 | + protected $extension = [ |
|
| 36 | + 'plaze.php', |
|
| 37 | + 'php', |
|
| 38 | + 'html', |
|
| 39 | + ]; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * The type to engine bindings. |
|
| 43 | - * |
|
| 44 | - * @var array $extensions |
|
| 45 | - */ |
|
| 46 | - protected $extensions = [ |
|
| 47 | - 'plaze.php' => 'plaze', |
|
| 48 | - 'php' => 'php', |
|
| 49 | - 'html' => 'file', |
|
| 50 | - ]; |
|
| 41 | + /** |
|
| 42 | + * The type to engine bindings. |
|
| 43 | + * |
|
| 44 | + * @var array $extensions |
|
| 45 | + */ |
|
| 46 | + protected $extensions = [ |
|
| 47 | + 'plaze.php' => 'plaze', |
|
| 48 | + 'php' => 'php', |
|
| 49 | + 'html' => 'file', |
|
| 50 | + ]; |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * Get the template file extension. |
|
| 54 | - * |
|
| 55 | - * @return array |
|
| 56 | - */ |
|
| 57 | - public function getExtensions(): array |
|
| 58 | - { |
|
| 59 | - return $this->extension; |
|
| 60 | - } |
|
| 52 | + /** |
|
| 53 | + * Get the template file extension. |
|
| 54 | + * |
|
| 55 | + * @return array |
|
| 56 | + */ |
|
| 57 | + public function getExtensions(): array |
|
| 58 | + { |
|
| 59 | + return $this->extension; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * Get type to engine bindings. |
|
| 64 | - * |
|
| 65 | - * @return array |
|
| 66 | - */ |
|
| 67 | - public function getKeysToExtensions(): array |
|
| 68 | - { |
|
| 69 | - return array_keys($this->extensions); |
|
| 70 | - } |
|
| 62 | + /** |
|
| 63 | + * Get type to engine bindings. |
|
| 64 | + * |
|
| 65 | + * @return array |
|
| 66 | + */ |
|
| 67 | + public function getKeysToExtensions(): array |
|
| 68 | + { |
|
| 69 | + return array_keys($this->extensions); |
|
| 70 | + } |
|
| 71 | 71 | } |
| 72 | 72 | \ No newline at end of file |
@@ -36,310 +36,310 @@ |
||
| 36 | 36 | */ |
| 37 | 37 | class Factory implements FactoryContract |
| 38 | 38 | { |
| 39 | - use Extensions, |
|
| 40 | - Concerns\ManagesStacks, |
|
| 41 | - Concerns\ManagesLayouts, |
|
| 42 | - Concerns\ManagesComponents, |
|
| 43 | - Concerns\ManagesTranslations; |
|
| 39 | + use Extensions, |
|
| 40 | + Concerns\ManagesStacks, |
|
| 41 | + Concerns\ManagesLayouts, |
|
| 42 | + Concerns\ManagesComponents, |
|
| 43 | + Concerns\ManagesTranslations; |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * The IoC container instance. |
|
| 47 | - * |
|
| 48 | - * @var \Syscodes\Components\Contracts\Container\Container $container |
|
| 49 | - */ |
|
| 50 | - protected $container; |
|
| 45 | + /** |
|
| 46 | + * The IoC container instance. |
|
| 47 | + * |
|
| 48 | + * @var \Syscodes\Components\Contracts\Container\Container $container |
|
| 49 | + */ |
|
| 50 | + protected $container; |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * The engine implementation. |
|
| 54 | - * |
|
| 55 | - * @var \Syscodes\Components\View\Engines\EngineResolver $engines |
|
| 56 | - */ |
|
| 57 | - protected $engines; |
|
| 52 | + /** |
|
| 53 | + * The engine implementation. |
|
| 54 | + * |
|
| 55 | + * @var \Syscodes\Components\View\Engines\EngineResolver $engines |
|
| 56 | + */ |
|
| 57 | + protected $engines; |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * The event dispatcher instance. |
|
| 61 | - * |
|
| 62 | - * @var \Syscodes\Components\Contracts\Events\Dispatcher $events |
|
| 63 | - */ |
|
| 64 | - protected $events; |
|
| 59 | + /** |
|
| 60 | + * The event dispatcher instance. |
|
| 61 | + * |
|
| 62 | + * @var \Syscodes\Components\Contracts\Events\Dispatcher $events |
|
| 63 | + */ |
|
| 64 | + protected $events; |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * The view finder implementation. |
|
| 68 | - * |
|
| 69 | - * @var \Syscodes\Components\View\FileViewFinder $finder |
|
| 70 | - */ |
|
| 71 | - protected $finder; |
|
| 66 | + /** |
|
| 67 | + * The view finder implementation. |
|
| 68 | + * |
|
| 69 | + * @var \Syscodes\Components\View\FileViewFinder $finder |
|
| 70 | + */ |
|
| 71 | + protected $finder; |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * The number of active rendering operations. |
|
| 75 | - * |
|
| 76 | - * @var int $renderCount |
|
| 77 | - */ |
|
| 78 | - protected $renderCount = 0; |
|
| 73 | + /** |
|
| 74 | + * The number of active rendering operations. |
|
| 75 | + * |
|
| 76 | + * @var int $renderCount |
|
| 77 | + */ |
|
| 78 | + protected $renderCount = 0; |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * Array of shared data. |
|
| 82 | - * |
|
| 83 | - * @var array $shared |
|
| 84 | - */ |
|
| 85 | - protected $shared = []; |
|
| 80 | + /** |
|
| 81 | + * Array of shared data. |
|
| 82 | + * |
|
| 83 | + * @var array $shared |
|
| 84 | + */ |
|
| 85 | + protected $shared = []; |
|
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * Constructor. Create a new Parser class instance. |
|
| 89 | - * |
|
| 90 | - * @param \Syscodes\Components\View\Engines\EngineResolver $engine |
|
| 91 | - * @param \Syscodes\Components\Contracts\View\ViewFinder $finder |
|
| 92 | - * @param \Syscodes\Components\Contracts\Events\Dispatcher $events |
|
| 93 | - * |
|
| 94 | - * @return void |
|
| 95 | - */ |
|
| 96 | - public function __construct(EngineResolver $engines, ViewFinder $finder, Dispatcher $events) |
|
| 97 | - { |
|
| 98 | - $this->finder = $finder; |
|
| 99 | - $this->engines = $engines; |
|
| 100 | - $this->events = $events; |
|
| 87 | + /** |
|
| 88 | + * Constructor. Create a new Parser class instance. |
|
| 89 | + * |
|
| 90 | + * @param \Syscodes\Components\View\Engines\EngineResolver $engine |
|
| 91 | + * @param \Syscodes\Components\Contracts\View\ViewFinder $finder |
|
| 92 | + * @param \Syscodes\Components\Contracts\Events\Dispatcher $events |
|
| 93 | + * |
|
| 94 | + * @return void |
|
| 95 | + */ |
|
| 96 | + public function __construct(EngineResolver $engines, ViewFinder $finder, Dispatcher $events) |
|
| 97 | + { |
|
| 98 | + $this->finder = $finder; |
|
| 99 | + $this->engines = $engines; |
|
| 100 | + $this->events = $events; |
|
| 101 | 101 | |
| 102 | - $this->share('__env', $this); |
|
| 103 | - } |
|
| 102 | + $this->share('__env', $this); |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - /** |
|
| 106 | - * Check existance view file. |
|
| 107 | - * |
|
| 108 | - * @param string $view |
|
| 109 | - * |
|
| 110 | - * @return bool |
|
| 111 | - */ |
|
| 112 | - public function viewExists($view): bool |
|
| 113 | - { |
|
| 114 | - try { |
|
| 115 | - $this->finder->find($view); |
|
| 116 | - } catch(InvalidArgumentException $e) { |
|
| 117 | - return false; |
|
| 118 | - } |
|
| 105 | + /** |
|
| 106 | + * Check existance view file. |
|
| 107 | + * |
|
| 108 | + * @param string $view |
|
| 109 | + * |
|
| 110 | + * @return bool |
|
| 111 | + */ |
|
| 112 | + public function viewExists($view): bool |
|
| 113 | + { |
|
| 114 | + try { |
|
| 115 | + $this->finder->find($view); |
|
| 116 | + } catch(InvalidArgumentException $e) { |
|
| 117 | + return false; |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - return true; |
|
| 121 | - } |
|
| 120 | + return true; |
|
| 121 | + } |
|
| 122 | 122 | |
| 123 | - /** |
|
| 124 | - * Global and local data are merged and extracted to create local variables within the view file. |
|
| 125 | - * Renders the view object to a string. |
|
| 126 | - * |
|
| 127 | - * @example $output = $view->make(); |
|
| 128 | - * |
|
| 129 | - * @param string $view View filename |
|
| 130 | - * @param array $data Array of values |
|
| 131 | - * |
|
| 132 | - * @return \Syscodes\Components\Contracts\View\View |
|
| 133 | - */ |
|
| 134 | - public function make($view, $data = []) |
|
| 135 | - { |
|
| 136 | - $path = $this->finder->find( |
|
| 137 | - $view = $this->normalizeName($view) |
|
| 138 | - ); |
|
| 123 | + /** |
|
| 124 | + * Global and local data are merged and extracted to create local variables within the view file. |
|
| 125 | + * Renders the view object to a string. |
|
| 126 | + * |
|
| 127 | + * @example $output = $view->make(); |
|
| 128 | + * |
|
| 129 | + * @param string $view View filename |
|
| 130 | + * @param array $data Array of values |
|
| 131 | + * |
|
| 132 | + * @return \Syscodes\Components\Contracts\View\View |
|
| 133 | + */ |
|
| 134 | + public function make($view, $data = []) |
|
| 135 | + { |
|
| 136 | + $path = $this->finder->find( |
|
| 137 | + $view = $this->normalizeName($view) |
|
| 138 | + ); |
|
| 139 | 139 | |
| 140 | - // Loader class instance. |
|
| 141 | - return take($this->viewInstance($view, $path, $data), fn ($view) => $this->callCreator($view)); |
|
| 142 | - } |
|
| 140 | + // Loader class instance. |
|
| 141 | + return take($this->viewInstance($view, $path, $data), fn ($view) => $this->callCreator($view)); |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | - /** |
|
| 145 | - * Normalize a view name. |
|
| 146 | - * |
|
| 147 | - * @param string $name |
|
| 148 | - * |
|
| 149 | - * @return string |
|
| 150 | - */ |
|
| 151 | - protected function normalizeName($name): string |
|
| 152 | - { |
|
| 153 | - return ViewName::normalize($name); |
|
| 154 | - } |
|
| 144 | + /** |
|
| 145 | + * Normalize a view name. |
|
| 146 | + * |
|
| 147 | + * @param string $name |
|
| 148 | + * |
|
| 149 | + * @return string |
|
| 150 | + */ |
|
| 151 | + protected function normalizeName($name): string |
|
| 152 | + { |
|
| 153 | + return ViewName::normalize($name); |
|
| 154 | + } |
|
| 155 | 155 | |
| 156 | - /** |
|
| 157 | - * Create a new view instance from the given arguments. |
|
| 158 | - * |
|
| 159 | - * @param string $file View filename |
|
| 160 | - * @param string $path Path filename |
|
| 161 | - * @param array $data Array of values |
|
| 162 | - * |
|
| 163 | - * @return \Syscodes\Components\Contracts\View\View |
|
| 164 | - */ |
|
| 165 | - protected function viewInstance($view, $path, $data) |
|
| 166 | - { |
|
| 167 | - return new View($this, $this->getEngineFromPath($path), $view, $path, $data); |
|
| 168 | - } |
|
| 156 | + /** |
|
| 157 | + * Create a new view instance from the given arguments. |
|
| 158 | + * |
|
| 159 | + * @param string $file View filename |
|
| 160 | + * @param string $path Path filename |
|
| 161 | + * @param array $data Array of values |
|
| 162 | + * |
|
| 163 | + * @return \Syscodes\Components\Contracts\View\View |
|
| 164 | + */ |
|
| 165 | + protected function viewInstance($view, $path, $data) |
|
| 166 | + { |
|
| 167 | + return new View($this, $this->getEngineFromPath($path), $view, $path, $data); |
|
| 168 | + } |
|
| 169 | 169 | |
| 170 | - /** |
|
| 171 | - * Get the appropriate view engine for the given path. |
|
| 172 | - * |
|
| 173 | - * @param string $path |
|
| 174 | - * |
|
| 175 | - * @return \Syscodes\Components\Contracts\View\Engine |
|
| 176 | - * |
|
| 177 | - * @throws \InvalidArgumentException |
|
| 178 | - */ |
|
| 179 | - public function getEngineFromPath($path) |
|
| 180 | - { |
|
| 181 | - if ( ! $extension = $this->getExtension($path)) { |
|
| 182 | - throw new InvalidArgumentException("Unrecognized extension in file: {$path}"); |
|
| 183 | - } |
|
| 170 | + /** |
|
| 171 | + * Get the appropriate view engine for the given path. |
|
| 172 | + * |
|
| 173 | + * @param string $path |
|
| 174 | + * |
|
| 175 | + * @return \Syscodes\Components\Contracts\View\Engine |
|
| 176 | + * |
|
| 177 | + * @throws \InvalidArgumentException |
|
| 178 | + */ |
|
| 179 | + public function getEngineFromPath($path) |
|
| 180 | + { |
|
| 181 | + if ( ! $extension = $this->getExtension($path)) { |
|
| 182 | + throw new InvalidArgumentException("Unrecognized extension in file: {$path}"); |
|
| 183 | + } |
|
| 184 | 184 | |
| 185 | - $engine = $this->extensions[$extension]; |
|
| 185 | + $engine = $this->extensions[$extension]; |
|
| 186 | 186 | |
| 187 | - return $this->engines->resolve($engine); |
|
| 188 | - } |
|
| 187 | + return $this->engines->resolve($engine); |
|
| 188 | + } |
|
| 189 | 189 | |
| 190 | - /** |
|
| 191 | - * Get the extension used by the view file. |
|
| 192 | - * |
|
| 193 | - * @param string $path |
|
| 194 | - * |
|
| 195 | - * @return string |
|
| 196 | - */ |
|
| 197 | - protected function getExtension($path) |
|
| 198 | - { |
|
| 199 | - $extensions = array_keys($this->extensions); |
|
| 190 | + /** |
|
| 191 | + * Get the extension used by the view file. |
|
| 192 | + * |
|
| 193 | + * @param string $path |
|
| 194 | + * |
|
| 195 | + * @return string |
|
| 196 | + */ |
|
| 197 | + protected function getExtension($path) |
|
| 198 | + { |
|
| 199 | + $extensions = array_keys($this->extensions); |
|
| 200 | 200 | |
| 201 | - return Arr::first($extensions, fn ($value) => Str::endsWith($path, '.'.$value)); |
|
| 202 | - } |
|
| 201 | + return Arr::first($extensions, fn ($value) => Str::endsWith($path, '.'.$value)); |
|
| 202 | + } |
|
| 203 | 203 | |
| 204 | - /** |
|
| 205 | - * Call the creator for a given view. |
|
| 206 | - * |
|
| 207 | - * @param \Syscodes\Components\View\View $view |
|
| 208 | - * |
|
| 209 | - * @return void |
|
| 210 | - */ |
|
| 211 | - public function callCreator(View $view): void |
|
| 212 | - { |
|
| 213 | - $this->events->dispatch('creating: '.$view->getView(), [$view]); |
|
| 214 | - } |
|
| 204 | + /** |
|
| 205 | + * Call the creator for a given view. |
|
| 206 | + * |
|
| 207 | + * @param \Syscodes\Components\View\View $view |
|
| 208 | + * |
|
| 209 | + * @return void |
|
| 210 | + */ |
|
| 211 | + public function callCreator(View $view): void |
|
| 212 | + { |
|
| 213 | + $this->events->dispatch('creating: '.$view->getView(), [$view]); |
|
| 214 | + } |
|
| 215 | 215 | |
| 216 | - /** |
|
| 217 | - * Get the extension to engine bindings. |
|
| 218 | - * |
|
| 219 | - * @return array |
|
| 220 | - */ |
|
| 221 | - public function getExtensions(): array |
|
| 222 | - { |
|
| 223 | - return $this->extensions; |
|
| 224 | - } |
|
| 216 | + /** |
|
| 217 | + * Get the extension to engine bindings. |
|
| 218 | + * |
|
| 219 | + * @return array |
|
| 220 | + */ |
|
| 221 | + public function getExtensions(): array |
|
| 222 | + { |
|
| 223 | + return $this->extensions; |
|
| 224 | + } |
|
| 225 | 225 | |
| 226 | - /** |
|
| 227 | - * Add a piece of shared data to the environment. |
|
| 228 | - * |
|
| 229 | - * @param array|string $key |
|
| 230 | - * @param mixed|null $value |
|
| 231 | - * |
|
| 232 | - * @return mixed |
|
| 233 | - */ |
|
| 234 | - public function share($key, $value = null) |
|
| 235 | - { |
|
| 236 | - $keys = is_array($key) ? $key : [$key => $value]; |
|
| 226 | + /** |
|
| 227 | + * Add a piece of shared data to the environment. |
|
| 228 | + * |
|
| 229 | + * @param array|string $key |
|
| 230 | + * @param mixed|null $value |
|
| 231 | + * |
|
| 232 | + * @return mixed |
|
| 233 | + */ |
|
| 234 | + public function share($key, $value = null) |
|
| 235 | + { |
|
| 236 | + $keys = is_array($key) ? $key : [$key => $value]; |
|
| 237 | 237 | |
| 238 | - foreach ($keys as $key => $value) { |
|
| 239 | - $this->shared[$key] = $value; |
|
| 240 | - } |
|
| 238 | + foreach ($keys as $key => $value) { |
|
| 239 | + $this->shared[$key] = $value; |
|
| 240 | + } |
|
| 241 | 241 | |
| 242 | - return $value; |
|
| 243 | - } |
|
| 242 | + return $value; |
|
| 243 | + } |
|
| 244 | 244 | |
| 245 | - /** |
|
| 246 | - * Replace the namespace hints for the given namespace. |
|
| 247 | - * |
|
| 248 | - * @param string $namespace |
|
| 249 | - * @param string|array $hints |
|
| 250 | - * |
|
| 251 | - * @return self |
|
| 252 | - */ |
|
| 253 | - public function replaceNamespace($namespace, $hints): self |
|
| 254 | - { |
|
| 255 | - $this->finder->replaceNamespace($namespace, $hints); |
|
| 245 | + /** |
|
| 246 | + * Replace the namespace hints for the given namespace. |
|
| 247 | + * |
|
| 248 | + * @param string $namespace |
|
| 249 | + * @param string|array $hints |
|
| 250 | + * |
|
| 251 | + * @return self |
|
| 252 | + */ |
|
| 253 | + public function replaceNamespace($namespace, $hints): self |
|
| 254 | + { |
|
| 255 | + $this->finder->replaceNamespace($namespace, $hints); |
|
| 256 | 256 | |
| 257 | - return $this; |
|
| 258 | - } |
|
| 257 | + return $this; |
|
| 258 | + } |
|
| 259 | 259 | |
| 260 | - /** |
|
| 261 | - * Increment the rendering counter. |
|
| 262 | - * |
|
| 263 | - * @return int |
|
| 264 | - */ |
|
| 265 | - public function increment(): int |
|
| 266 | - { |
|
| 267 | - return $this->renderCount++; |
|
| 268 | - } |
|
| 260 | + /** |
|
| 261 | + * Increment the rendering counter. |
|
| 262 | + * |
|
| 263 | + * @return int |
|
| 264 | + */ |
|
| 265 | + public function increment(): int |
|
| 266 | + { |
|
| 267 | + return $this->renderCount++; |
|
| 268 | + } |
|
| 269 | 269 | |
| 270 | - /** |
|
| 271 | - * Decrement the rendering counter. |
|
| 272 | - * |
|
| 273 | - * @return int |
|
| 274 | - */ |
|
| 275 | - public function decrement(): int |
|
| 276 | - { |
|
| 277 | - return $this->renderCount--; |
|
| 278 | - } |
|
| 270 | + /** |
|
| 271 | + * Decrement the rendering counter. |
|
| 272 | + * |
|
| 273 | + * @return int |
|
| 274 | + */ |
|
| 275 | + public function decrement(): int |
|
| 276 | + { |
|
| 277 | + return $this->renderCount--; |
|
| 278 | + } |
|
| 279 | 279 | |
| 280 | - /** |
|
| 281 | - * Check if there are no active render operations. |
|
| 282 | - * |
|
| 283 | - * @return bool |
|
| 284 | - */ |
|
| 285 | - public function doneRendering(): bool |
|
| 286 | - { |
|
| 287 | - return $this->renderCount == 0; |
|
| 288 | - } |
|
| 280 | + /** |
|
| 281 | + * Check if there are no active render operations. |
|
| 282 | + * |
|
| 283 | + * @return bool |
|
| 284 | + */ |
|
| 285 | + public function doneRendering(): bool |
|
| 286 | + { |
|
| 287 | + return $this->renderCount == 0; |
|
| 288 | + } |
|
| 289 | 289 | |
| 290 | - /** |
|
| 291 | - * Flush all of the parser state like sections. |
|
| 292 | - * |
|
| 293 | - * @return void |
|
| 294 | - */ |
|
| 295 | - public function flushState(): void |
|
| 296 | - { |
|
| 297 | - $this->renderCount = 0; |
|
| 290 | + /** |
|
| 291 | + * Flush all of the parser state like sections. |
|
| 292 | + * |
|
| 293 | + * @return void |
|
| 294 | + */ |
|
| 295 | + public function flushState(): void |
|
| 296 | + { |
|
| 297 | + $this->renderCount = 0; |
|
| 298 | 298 | |
| 299 | - $this->flushSections(); |
|
| 300 | - } |
|
| 299 | + $this->flushSections(); |
|
| 300 | + } |
|
| 301 | 301 | |
| 302 | - /** |
|
| 303 | - * Flush all of the section contents if done rendering. |
|
| 304 | - * |
|
| 305 | - * @return void |
|
| 306 | - */ |
|
| 307 | - public function flushStateIfDoneRendering(): void |
|
| 308 | - { |
|
| 309 | - if ($this->doneRendering()) { |
|
| 310 | - $this->flushState(); |
|
| 311 | - } |
|
| 312 | - } |
|
| 302 | + /** |
|
| 303 | + * Flush all of the section contents if done rendering. |
|
| 304 | + * |
|
| 305 | + * @return void |
|
| 306 | + */ |
|
| 307 | + public function flushStateIfDoneRendering(): void |
|
| 308 | + { |
|
| 309 | + if ($this->doneRendering()) { |
|
| 310 | + $this->flushState(); |
|
| 311 | + } |
|
| 312 | + } |
|
| 313 | 313 | |
| 314 | - /** |
|
| 315 | - * Get all of the shared data for the environment. |
|
| 316 | - * |
|
| 317 | - * @return array |
|
| 318 | - */ |
|
| 319 | - public function getShared(): array |
|
| 320 | - { |
|
| 321 | - return $this->shared; |
|
| 322 | - } |
|
| 314 | + /** |
|
| 315 | + * Get all of the shared data for the environment. |
|
| 316 | + * |
|
| 317 | + * @return array |
|
| 318 | + */ |
|
| 319 | + public function getShared(): array |
|
| 320 | + { |
|
| 321 | + return $this->shared; |
|
| 322 | + } |
|
| 323 | 323 | |
| 324 | - /** |
|
| 325 | - * Get the IoC container instance. |
|
| 326 | - * |
|
| 327 | - * @return \Syscodes\Components\Contracts\Container\Container |
|
| 328 | - */ |
|
| 329 | - public function getContainer() |
|
| 330 | - { |
|
| 331 | - return $this->container; |
|
| 332 | - } |
|
| 324 | + /** |
|
| 325 | + * Get the IoC container instance. |
|
| 326 | + * |
|
| 327 | + * @return \Syscodes\Components\Contracts\Container\Container |
|
| 328 | + */ |
|
| 329 | + public function getContainer() |
|
| 330 | + { |
|
| 331 | + return $this->container; |
|
| 332 | + } |
|
| 333 | 333 | |
| 334 | - /** |
|
| 335 | - * Set the IoC container instance. |
|
| 336 | - * |
|
| 337 | - * @param \Syscodes\Components\Contracts\Container\Container $container |
|
| 338 | - * |
|
| 339 | - * @return void |
|
| 340 | - */ |
|
| 341 | - public function setContainer(Container $container): void |
|
| 342 | - { |
|
| 343 | - $this->container = $container; |
|
| 344 | - } |
|
| 334 | + /** |
|
| 335 | + * Set the IoC container instance. |
|
| 336 | + * |
|
| 337 | + * @param \Syscodes\Components\Contracts\Container\Container $container |
|
| 338 | + * |
|
| 339 | + * @return void |
|
| 340 | + */ |
|
| 341 | + public function setContainer(Container $container): void |
|
| 342 | + { |
|
| 343 | + $this->container = $container; |
|
| 344 | + } |
|
| 345 | 345 | } |
| 346 | 346 | \ No newline at end of file |
@@ -113,7 +113,7 @@ |
||
| 113 | 113 | { |
| 114 | 114 | try { |
| 115 | 115 | $this->finder->find($view); |
| 116 | - } catch(InvalidArgumentException $e) { |
|
| 116 | + } catch (InvalidArgumentException $e) { |
|
| 117 | 117 | return false; |
| 118 | 118 | } |
| 119 | 119 | |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | public function stopPush() |
| 80 | 80 | { |
| 81 | 81 | if (empty($this->pushStack)) { |
| 82 | - throw new InvalidArgumentException('You cannot finish a section without first starting with one.'); |
|
| 82 | + throw new InvalidArgumentException('You cannot finish a section without first starting with one.'); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | return take(array_pop($this->pushStack), function ($last) { |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | public function stopPrepend() |
| 138 | 138 | { |
| 139 | 139 | if (empty($this->pushStack)) { |
| 140 | - throw new InvalidArgumentException('You cannot finish a section without first starting with one.'); |
|
| 140 | + throw new InvalidArgumentException('You cannot finish a section without first starting with one.'); |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | return take(array_pop($this->pushStack), function ($last) { |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | throw new InvalidArgumentException('You cannot finish a section without first starting with one.'); |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | - return take(array_pop($this->pushStack), function ($last) { |
|
| 85 | + return take(array_pop($this->pushStack), function($last) { |
|
| 86 | 86 | $this->extendPush($last, ob_get_clean()); |
| 87 | 87 | }); |
| 88 | 88 | } |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | throw new InvalidArgumentException('You cannot finish a section without first starting with one.'); |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | - return take(array_pop($this->pushStack), function ($last) { |
|
| 143 | + return take(array_pop($this->pushStack), function($last) { |
|
| 144 | 144 | $this->extendPrepend($last, ob_get_clean()); |
| 145 | 145 | }); |
| 146 | 146 | } |
@@ -30,191 +30,191 @@ |
||
| 30 | 30 | */ |
| 31 | 31 | trait ManagesLayouts |
| 32 | 32 | { |
| 33 | - /** |
|
| 34 | - * Started blocks. |
|
| 35 | - * |
|
| 36 | - * @var array $sections |
|
| 37 | - */ |
|
| 38 | - protected $sections = []; |
|
| 33 | + /** |
|
| 34 | + * Started blocks. |
|
| 35 | + * |
|
| 36 | + * @var array $sections |
|
| 37 | + */ |
|
| 38 | + protected $sections = []; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * The stack of in-progress sections. |
|
| 42 | - * |
|
| 43 | - * @var array $sectionStack |
|
| 44 | - */ |
|
| 45 | - protected $sectionStack = []; |
|
| 40 | + /** |
|
| 41 | + * The stack of in-progress sections. |
|
| 42 | + * |
|
| 43 | + * @var array $sectionStack |
|
| 44 | + */ |
|
| 45 | + protected $sectionStack = []; |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Starting section. |
|
| 49 | - * |
|
| 50 | - * @param string $section |
|
| 51 | - * @param string|null $content |
|
| 52 | - * |
|
| 53 | - * @return array |
|
| 54 | - */ |
|
| 55 | - public function startSection($section, $content = null) |
|
| 56 | - { |
|
| 57 | - if (null === $content) { |
|
| 58 | - if (ob_start()) { |
|
| 59 | - $this->sectionStack[] = $section; |
|
| 60 | - } |
|
| 61 | - } else { |
|
| 62 | - $this->extendSection($section, $content instanceof View ? $content : e($content)); |
|
| 63 | - } |
|
| 64 | - } |
|
| 47 | + /** |
|
| 48 | + * Starting section. |
|
| 49 | + * |
|
| 50 | + * @param string $section |
|
| 51 | + * @param string|null $content |
|
| 52 | + * |
|
| 53 | + * @return array |
|
| 54 | + */ |
|
| 55 | + public function startSection($section, $content = null) |
|
| 56 | + { |
|
| 57 | + if (null === $content) { |
|
| 58 | + if (ob_start()) { |
|
| 59 | + $this->sectionStack[] = $section; |
|
| 60 | + } |
|
| 61 | + } else { |
|
| 62 | + $this->extendSection($section, $content instanceof View ? $content : e($content)); |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * Inject inline content into a section. |
|
| 68 | - * |
|
| 69 | - * @param string $section |
|
| 70 | - * @param string $content |
|
| 71 | - * |
|
| 72 | - * @return void |
|
| 73 | - */ |
|
| 74 | - public function injectSection($section, $content) |
|
| 75 | - { |
|
| 76 | - $this->beginSection($section, $content); |
|
| 77 | - } |
|
| 66 | + /** |
|
| 67 | + * Inject inline content into a section. |
|
| 68 | + * |
|
| 69 | + * @param string $section |
|
| 70 | + * @param string $content |
|
| 71 | + * |
|
| 72 | + * @return void |
|
| 73 | + */ |
|
| 74 | + public function injectSection($section, $content) |
|
| 75 | + { |
|
| 76 | + $this->beginSection($section, $content); |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * Append content to a given section. |
|
| 81 | - * |
|
| 82 | - * @param string $section |
|
| 83 | - * @param string $content |
|
| 84 | - * |
|
| 85 | - * @return void |
|
| 86 | - */ |
|
| 87 | - protected function extendSection($section, $content) |
|
| 88 | - { |
|
| 89 | - if (isset($this->sections[$section])) { |
|
| 90 | - $content = str_replace(static::parent(), $content, $this->sections[$section]); |
|
| 91 | - } |
|
| 79 | + /** |
|
| 80 | + * Append content to a given section. |
|
| 81 | + * |
|
| 82 | + * @param string $section |
|
| 83 | + * @param string $content |
|
| 84 | + * |
|
| 85 | + * @return void |
|
| 86 | + */ |
|
| 87 | + protected function extendSection($section, $content) |
|
| 88 | + { |
|
| 89 | + if (isset($this->sections[$section])) { |
|
| 90 | + $content = str_replace(static::parent(), $content, $this->sections[$section]); |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - $this->sections[$section] = $content; |
|
| 94 | - } |
|
| 93 | + $this->sections[$section] = $content; |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - /** |
|
| 97 | - * Close and printing section. |
|
| 98 | - * |
|
| 99 | - * @return string |
|
| 100 | - */ |
|
| 101 | - public function showSection(): string |
|
| 102 | - { |
|
| 103 | - if (empty($this->sectionStack)) { |
|
| 104 | - return ''; |
|
| 105 | - } |
|
| 96 | + /** |
|
| 97 | + * Close and printing section. |
|
| 98 | + * |
|
| 99 | + * @return string |
|
| 100 | + */ |
|
| 101 | + public function showSection(): string |
|
| 102 | + { |
|
| 103 | + if (empty($this->sectionStack)) { |
|
| 104 | + return ''; |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - return $this->giveContent($this->stopSection()); |
|
| 108 | - } |
|
| 107 | + return $this->giveContent($this->stopSection()); |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | - /** |
|
| 111 | - * Give sections the page view from the master page. |
|
| 112 | - * |
|
| 113 | - * @param string $name |
|
| 114 | - * |
|
| 115 | - * @return string |
|
| 116 | - */ |
|
| 117 | - public function giveContent($name, $default = ''): string |
|
| 118 | - { |
|
| 119 | - $sectionContent = $default instanceof View ? $default : e($default); |
|
| 110 | + /** |
|
| 111 | + * Give sections the page view from the master page. |
|
| 112 | + * |
|
| 113 | + * @param string $name |
|
| 114 | + * |
|
| 115 | + * @return string |
|
| 116 | + */ |
|
| 117 | + public function giveContent($name, $default = ''): string |
|
| 118 | + { |
|
| 119 | + $sectionContent = $default instanceof View ? $default : e($default); |
|
| 120 | 120 | |
| 121 | - if (isset($this->sections[$name])) { |
|
| 122 | - $sectionContent = $this->sections[$name]; |
|
| 123 | - } |
|
| 121 | + if (isset($this->sections[$name])) { |
|
| 122 | + $sectionContent = $this->sections[$name]; |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | - return str_replace(static::parent(), '', $sectionContent); |
|
| 126 | - } |
|
| 125 | + return str_replace(static::parent(), '', $sectionContent); |
|
| 126 | + } |
|
| 127 | 127 | |
| 128 | - /** |
|
| 129 | - * Closing section. |
|
| 130 | - * |
|
| 131 | - * @param bool $overwrite |
|
| 132 | - * |
|
| 133 | - * @return mixed |
|
| 134 | - * |
|
| 135 | - * @throws \InvalidArgumentException |
|
| 136 | - */ |
|
| 137 | - public function stopSection($overwrite = false) |
|
| 138 | - { |
|
| 139 | - if (empty($this->sectionStack)) { |
|
| 140 | - throw new InvalidArgumentException('You cannot finish a section without first starting with one.'); |
|
| 141 | - } |
|
| 128 | + /** |
|
| 129 | + * Closing section. |
|
| 130 | + * |
|
| 131 | + * @param bool $overwrite |
|
| 132 | + * |
|
| 133 | + * @return mixed |
|
| 134 | + * |
|
| 135 | + * @throws \InvalidArgumentException |
|
| 136 | + */ |
|
| 137 | + public function stopSection($overwrite = false) |
|
| 138 | + { |
|
| 139 | + if (empty($this->sectionStack)) { |
|
| 140 | + throw new InvalidArgumentException('You cannot finish a section without first starting with one.'); |
|
| 141 | + } |
|
| 142 | 142 | |
| 143 | - $last = array_pop($this->sectionStack); |
|
| 143 | + $last = array_pop($this->sectionStack); |
|
| 144 | 144 | |
| 145 | - if ($overwrite) { |
|
| 146 | - $this->sections[$last] = ob_get_clean(); |
|
| 147 | - } else { |
|
| 148 | - $this->extendSection($last, ob_get_clean()); |
|
| 149 | - } |
|
| 145 | + if ($overwrite) { |
|
| 146 | + $this->sections[$last] = ob_get_clean(); |
|
| 147 | + } else { |
|
| 148 | + $this->extendSection($last, ob_get_clean()); |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | - return $last; |
|
| 152 | - } |
|
| 151 | + return $last; |
|
| 152 | + } |
|
| 153 | 153 | |
| 154 | - /** |
|
| 155 | - * Stop injecting content into a section and append it. |
|
| 156 | - * |
|
| 157 | - * @return string |
|
| 158 | - * |
|
| 159 | - * @throws \InvalidArgumentException |
|
| 160 | - */ |
|
| 161 | - public function appendSection() |
|
| 162 | - { |
|
| 163 | - if (empty($this->sectionStack)) { |
|
| 164 | - throw new InvalidArgumentException('You cannot finish a section without first starting with one.'); |
|
| 165 | - } |
|
| 154 | + /** |
|
| 155 | + * Stop injecting content into a section and append it. |
|
| 156 | + * |
|
| 157 | + * @return string |
|
| 158 | + * |
|
| 159 | + * @throws \InvalidArgumentException |
|
| 160 | + */ |
|
| 161 | + public function appendSection() |
|
| 162 | + { |
|
| 163 | + if (empty($this->sectionStack)) { |
|
| 164 | + throw new InvalidArgumentException('You cannot finish a section without first starting with one.'); |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | - $last = array_pop($this->sectionStack); |
|
| 167 | + $last = array_pop($this->sectionStack); |
|
| 168 | 168 | |
| 169 | - if (isset($this->sections[$last])) { |
|
| 170 | - $this->sections[$last] .= ob_get_clean(); |
|
| 171 | - } else { |
|
| 172 | - $this->sections[$last] = ob_get_clean(); |
|
| 173 | - } |
|
| 169 | + if (isset($this->sections[$last])) { |
|
| 170 | + $this->sections[$last] .= ob_get_clean(); |
|
| 171 | + } else { |
|
| 172 | + $this->sections[$last] = ob_get_clean(); |
|
| 173 | + } |
|
| 174 | 174 | |
| 175 | - return $last; |
|
| 176 | - } |
|
| 175 | + return $last; |
|
| 176 | + } |
|
| 177 | 177 | |
| 178 | - /** |
|
| 179 | - * Check if section exists. |
|
| 180 | - * |
|
| 181 | - * @param string $name |
|
| 182 | - * |
|
| 183 | - * @return bool |
|
| 184 | - */ |
|
| 185 | - public function hasSection($name): bool |
|
| 186 | - { |
|
| 187 | - return array_key_exists($name, $this->sections); |
|
| 188 | - } |
|
| 178 | + /** |
|
| 179 | + * Check if section exists. |
|
| 180 | + * |
|
| 181 | + * @param string $name |
|
| 182 | + * |
|
| 183 | + * @return bool |
|
| 184 | + */ |
|
| 185 | + public function hasSection($name): bool |
|
| 186 | + { |
|
| 187 | + return array_key_exists($name, $this->sections); |
|
| 188 | + } |
|
| 189 | 189 | |
| 190 | - /** |
|
| 191 | - * Get the entire array of sections. |
|
| 192 | - * |
|
| 193 | - * @return array |
|
| 194 | - */ |
|
| 195 | - public function getSections(): array |
|
| 196 | - { |
|
| 197 | - return $this->sections; |
|
| 198 | - } |
|
| 190 | + /** |
|
| 191 | + * Get the entire array of sections. |
|
| 192 | + * |
|
| 193 | + * @return array |
|
| 194 | + */ |
|
| 195 | + public function getSections(): array |
|
| 196 | + { |
|
| 197 | + return $this->sections; |
|
| 198 | + } |
|
| 199 | 199 | |
| 200 | - /** |
|
| 201 | - * Replace the @parent directive to a placeholder. |
|
| 202 | - * |
|
| 203 | - * @return string |
|
| 204 | - */ |
|
| 205 | - public static function parent(): string |
|
| 206 | - { |
|
| 207 | - return '@parent'; |
|
| 208 | - } |
|
| 200 | + /** |
|
| 201 | + * Replace the @parent directive to a placeholder. |
|
| 202 | + * |
|
| 203 | + * @return string |
|
| 204 | + */ |
|
| 205 | + public static function parent(): string |
|
| 206 | + { |
|
| 207 | + return '@parent'; |
|
| 208 | + } |
|
| 209 | 209 | |
| 210 | - /** |
|
| 211 | - * Flush all of the section contents. |
|
| 212 | - * |
|
| 213 | - * @return void |
|
| 214 | - */ |
|
| 215 | - public function flushSections(): void |
|
| 216 | - { |
|
| 217 | - $this->sections = []; |
|
| 218 | - $this->sectionStack = []; |
|
| 219 | - } |
|
| 210 | + /** |
|
| 211 | + * Flush all of the section contents. |
|
| 212 | + * |
|
| 213 | + * @return void |
|
| 214 | + */ |
|
| 215 | + public function flushSections(): void |
|
| 216 | + { |
|
| 217 | + $this->sections = []; |
|
| 218 | + $this->sectionStack = []; |
|
| 219 | + } |
|
| 220 | 220 | } |
| 221 | 221 | \ No newline at end of file |
@@ -332,29 +332,29 @@ |
||
| 332 | 332 | * |
| 333 | 333 | * @return void |
| 334 | 334 | */ |
| 335 | - public function if($name, callable $callback): void |
|
| 335 | + public function if ($name, callable $callback): void |
|
| 336 | 336 | { |
| 337 | 337 | $this->conditions[$name] = $callback; |
| 338 | 338 | |
| 339 | - $this->directive($name, function ($expression) use ($name) { |
|
| 339 | + $this->directive($name, function($expression) use ($name) { |
|
| 340 | 340 | return $expression !== '' |
| 341 | 341 | ? "<?php if (\Syscodes\Components\Support\Facades\Plaze::checkpoint('{$name}', {$expression})): ?>" |
| 342 | 342 | : "<?php if (\Syscodes\Components\Support\Facades\Plaze::checkpoint('{$name}')): ?>"; |
| 343 | 343 | }); |
| 344 | 344 | |
| 345 | - $this->directive('unless'.$name, function ($expression) use ($name) { |
|
| 345 | + $this->directive('unless'.$name, function($expression) use ($name) { |
|
| 346 | 346 | return $expression !== '' |
| 347 | 347 | ? "<?php if (! \Syscodes\Components\Support\Facades\Plaze::checkpoint('{$name}', {$expression})): ?>" |
| 348 | 348 | : "<?php if (! \Syscodes\Components\Support\Facades\Plaze::checkpoint('{$name}')): ?>"; |
| 349 | 349 | }); |
| 350 | 350 | |
| 351 | - $this->directive('else'.$name, function ($expression) use ($name) { |
|
| 351 | + $this->directive('else'.$name, function($expression) use ($name) { |
|
| 352 | 352 | return $expression !== '' |
| 353 | 353 | ? "<?php elseif (\Syscodes\Components\Support\Facades\Plaze::checkpoint('{$name}', {$expression})): ?>" |
| 354 | 354 | : "<?php elseif (\Syscodes\Components\Support\Facades\Plaze::checkpoint('{$name}')): ?>"; |
| 355 | 355 | }); |
| 356 | 356 | |
| 357 | - $this->directive('end'.$name, function () { |
|
| 357 | + $this->directive('end'.$name, function() { |
|
| 358 | 358 | return '<?php endif; ?>'; |
| 359 | 359 | }); |
| 360 | 360 | } |
@@ -92,7 +92,7 @@ |
||
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | return $this->files->lastModified($path) >= |
| 95 | - $this->files->lastModified($compiled); |
|
| 95 | + $this->files->lastModified($compiled); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | /** |