@@ -259,7 +259,7 @@ discard block |
||
| 259 | 259 | */ |
| 260 | 260 | public function select($query, $bindings = [], $useReadPdo = true) |
| 261 | 261 | { |
| 262 | - return $this->run($query, $bindings, function ($query, $bindings) use ($useReadPdo) { |
|
| 262 | + return $this->run($query, $bindings, function($query, $bindings) use ($useReadPdo) { |
|
| 263 | 263 | |
| 264 | 264 | if ($this->pretending()) { |
| 265 | 265 | return []; |
@@ -326,7 +326,7 @@ discard block |
||
| 326 | 326 | */ |
| 327 | 327 | public function statement($query, $bindings = []) |
| 328 | 328 | { |
| 329 | - return $this->run($query, $bindings, function ($query, $bindings) { |
|
| 329 | + return $this->run($query, $bindings, function($query, $bindings) { |
|
| 330 | 330 | if ($this->pretending()) { |
| 331 | 331 | return true; |
| 332 | 332 | } |
@@ -350,7 +350,7 @@ discard block |
||
| 350 | 350 | */ |
| 351 | 351 | public function affectingStatement($query, $bindings = []) |
| 352 | 352 | { |
| 353 | - return $this->run($query, $bindings, function ($query, $bindings) { |
|
| 353 | + return $this->run($query, $bindings, function($query, $bindings) { |
|
| 354 | 354 | |
| 355 | 355 | if ($this->pretending()) |
| 356 | 356 | { |
@@ -379,7 +379,7 @@ discard block |
||
| 379 | 379 | */ |
| 380 | 380 | public function prepend(Closure $callback) |
| 381 | 381 | { |
| 382 | - return $this->withFreshQueryLog(function () use ($callback) { |
|
| 382 | + return $this->withFreshQueryLog(function() use ($callback) { |
|
| 383 | 383 | |
| 384 | 384 | $this->pretending = true; |
| 385 | 385 | |
@@ -588,7 +588,7 @@ discard block |
||
| 588 | 588 | return; |
| 589 | 589 | } |
| 590 | 590 | |
| 591 | - switch($event) |
|
| 591 | + switch ($event) |
|
| 592 | 592 | { |
| 593 | 593 | case 'beginTransaction': |
| 594 | 594 | return $this->events->dispatch(new TransactionBegin($this)); |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | |
| 82 | 82 | try { |
| 83 | 83 | $this->files->getRequire($path, $data); |
| 84 | - } catch(Throwable $e) { |
|
| 84 | + } catch (Throwable $e) { |
|
| 85 | 85 | return $this->handleViewException($e, $obLevel); |
| 86 | 86 | } |
| 87 | 87 | |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | */ |
| 101 | 101 | protected function handleViewException(Throwable $e, $obLevel) |
| 102 | 102 | { |
| 103 | - while(ob_get_level() > $obLevel) { |
|
| 103 | + while (ob_get_level() > $obLevel) { |
|
| 104 | 104 | ob_end_clean(); |
| 105 | 105 | } |
| 106 | 106 | |
@@ -42,12 +42,12 @@ |
||
| 42 | 42 | { |
| 43 | 43 | $delimiter = ViewFinder::HINT_PATH_DELIMITER; |
| 44 | 44 | |
| 45 | - if (strpos($name, $delimiter) === false) { |
|
| 46 | - return str_replace('/', '.', $name); |
|
| 47 | - } |
|
| 45 | + if (strpos($name, $delimiter) === false) { |
|
| 46 | + return str_replace('/', '.', $name); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - [$namespace, $name] = explode($delimiter, $name); |
|
| 49 | + [$namespace, $name] = explode($delimiter, $name); |
|
| 50 | 50 | |
| 51 | - return $namespace.$delimiter.str_replace('/', '.', $name); |
|
| 51 | + return $namespace.$delimiter.str_replace('/', '.', $name); |
|
| 52 | 52 | } |
| 53 | 53 | } |
| 54 | 54 | \ No newline at end of file |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | { |
| 115 | 115 | try { |
| 116 | 116 | $this->finder->find($view); |
| 117 | - } catch(InvalidArgumentException $e) { |
|
| 117 | + } catch (InvalidArgumentException $e) { |
|
| 118 | 118 | return false; |
| 119 | 119 | } |
| 120 | 120 | |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | ); |
| 140 | 140 | |
| 141 | 141 | // Loader class instance. |
| 142 | - return take($this->viewInstance($view, $path, $data), function ($view) { |
|
| 142 | + return take($this->viewInstance($view, $path, $data), function($view) { |
|
| 143 | 143 | $this->callCreator($view); |
| 144 | 144 | }); |
| 145 | 145 | } |
@@ -38,313 +38,313 @@ |
||
| 38 | 38 | */ |
| 39 | 39 | class Factory implements FactoryContract |
| 40 | 40 | { |
| 41 | - use Extensions, |
|
| 42 | - Concerns\ManagesLayouts, |
|
| 43 | - Concerns\ManagesComponents, |
|
| 44 | - Concerns\ManagesTranslations; |
|
| 41 | + use Extensions, |
|
| 42 | + Concerns\ManagesLayouts, |
|
| 43 | + Concerns\ManagesComponents, |
|
| 44 | + Concerns\ManagesTranslations; |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * The IoC container instance. |
|
| 48 | - * |
|
| 49 | - * @var \Syscodes\Contracts\Container\Container $container |
|
| 50 | - */ |
|
| 51 | - protected $container; |
|
| 46 | + /** |
|
| 47 | + * The IoC container instance. |
|
| 48 | + * |
|
| 49 | + * @var \Syscodes\Contracts\Container\Container $container |
|
| 50 | + */ |
|
| 51 | + protected $container; |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * The engine implementation. |
|
| 55 | - * |
|
| 56 | - * @var \Syscodes\View\Engines\EngineResolver $engines |
|
| 57 | - */ |
|
| 58 | - protected $engines; |
|
| 53 | + /** |
|
| 54 | + * The engine implementation. |
|
| 55 | + * |
|
| 56 | + * @var \Syscodes\View\Engines\EngineResolver $engines |
|
| 57 | + */ |
|
| 58 | + protected $engines; |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * The event dispatcher instance. |
|
| 62 | - * |
|
| 63 | - * @var \Syscodes\Contracts\Events\Dispatcher $events |
|
| 64 | - */ |
|
| 65 | - protected $events; |
|
| 60 | + /** |
|
| 61 | + * The event dispatcher instance. |
|
| 62 | + * |
|
| 63 | + * @var \Syscodes\Contracts\Events\Dispatcher $events |
|
| 64 | + */ |
|
| 65 | + protected $events; |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * The view finder implementation. |
|
| 69 | - * |
|
| 70 | - * @var \Syscodes\View\FileViewFinder $finder |
|
| 71 | - */ |
|
| 72 | - protected $finder; |
|
| 67 | + /** |
|
| 68 | + * The view finder implementation. |
|
| 69 | + * |
|
| 70 | + * @var \Syscodes\View\FileViewFinder $finder |
|
| 71 | + */ |
|
| 72 | + protected $finder; |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * The number of active rendering operations. |
|
| 76 | - * |
|
| 77 | - * @var int $renderCount |
|
| 78 | - */ |
|
| 79 | - protected $renderCount = 0; |
|
| 74 | + /** |
|
| 75 | + * The number of active rendering operations. |
|
| 76 | + * |
|
| 77 | + * @var int $renderCount |
|
| 78 | + */ |
|
| 79 | + protected $renderCount = 0; |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * Array of shared data. |
|
| 83 | - * |
|
| 84 | - * @var array $shared |
|
| 85 | - */ |
|
| 86 | - protected $shared = []; |
|
| 81 | + /** |
|
| 82 | + * Array of shared data. |
|
| 83 | + * |
|
| 84 | + * @var array $shared |
|
| 85 | + */ |
|
| 86 | + protected $shared = []; |
|
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * Constructor: Create a new Parser class instance. |
|
| 90 | - * |
|
| 91 | - * @param \Syscodes\View\Engines\EngineResolver $engine |
|
| 92 | - * @param \Syscodes\Contracts\View\ViewFinder $finder |
|
| 93 | - * @param \Syscodes\Contracts\Events\Dispatcher $events |
|
| 94 | - * |
|
| 95 | - * @return void |
|
| 96 | - */ |
|
| 97 | - public function __construct(EngineResolver $engines, ViewFinder $finder, Dispatcher $events) |
|
| 98 | - { |
|
| 99 | - $this->finder = $finder; |
|
| 100 | - $this->engines = $engines; |
|
| 101 | - $this->events = $events; |
|
| 88 | + /** |
|
| 89 | + * Constructor: Create a new Parser class instance. |
|
| 90 | + * |
|
| 91 | + * @param \Syscodes\View\Engines\EngineResolver $engine |
|
| 92 | + * @param \Syscodes\Contracts\View\ViewFinder $finder |
|
| 93 | + * @param \Syscodes\Contracts\Events\Dispatcher $events |
|
| 94 | + * |
|
| 95 | + * @return void |
|
| 96 | + */ |
|
| 97 | + public function __construct(EngineResolver $engines, ViewFinder $finder, Dispatcher $events) |
|
| 98 | + { |
|
| 99 | + $this->finder = $finder; |
|
| 100 | + $this->engines = $engines; |
|
| 101 | + $this->events = $events; |
|
| 102 | 102 | |
| 103 | - $this->share('__env', $this); |
|
| 104 | - } |
|
| 103 | + $this->share('__env', $this); |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - /** |
|
| 107 | - * Check existance view file. |
|
| 108 | - * |
|
| 109 | - * @param string $view |
|
| 110 | - * |
|
| 111 | - * @return bool |
|
| 112 | - */ |
|
| 113 | - public function viewExists($view) |
|
| 114 | - { |
|
| 115 | - try { |
|
| 116 | - $this->finder->find($view); |
|
| 117 | - } catch(InvalidArgumentException $e) { |
|
| 118 | - return false; |
|
| 119 | - } |
|
| 106 | + /** |
|
| 107 | + * Check existance view file. |
|
| 108 | + * |
|
| 109 | + * @param string $view |
|
| 110 | + * |
|
| 111 | + * @return bool |
|
| 112 | + */ |
|
| 113 | + public function viewExists($view) |
|
| 114 | + { |
|
| 115 | + try { |
|
| 116 | + $this->finder->find($view); |
|
| 117 | + } catch(InvalidArgumentException $e) { |
|
| 118 | + return false; |
|
| 119 | + } |
|
| 120 | 120 | |
| 121 | - return true; |
|
| 122 | - } |
|
| 121 | + return true; |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | - /** |
|
| 125 | - * Global and local data are merged and extracted to create local variables within the view file. |
|
| 126 | - * Renders the view object to a string. |
|
| 127 | - * |
|
| 128 | - * @example $output = $view->make(); |
|
| 129 | - * |
|
| 130 | - * @param string $view View filename |
|
| 131 | - * @param array $data Array of values |
|
| 132 | - * |
|
| 133 | - * @return string |
|
| 134 | - */ |
|
| 135 | - public function make($view, $data = []) |
|
| 136 | - { |
|
| 137 | - $path = $this->finder->find( |
|
| 138 | - $view = $this->normalizeName($view) |
|
| 139 | - ); |
|
| 124 | + /** |
|
| 125 | + * Global and local data are merged and extracted to create local variables within the view file. |
|
| 126 | + * Renders the view object to a string. |
|
| 127 | + * |
|
| 128 | + * @example $output = $view->make(); |
|
| 129 | + * |
|
| 130 | + * @param string $view View filename |
|
| 131 | + * @param array $data Array of values |
|
| 132 | + * |
|
| 133 | + * @return string |
|
| 134 | + */ |
|
| 135 | + public function make($view, $data = []) |
|
| 136 | + { |
|
| 137 | + $path = $this->finder->find( |
|
| 138 | + $view = $this->normalizeName($view) |
|
| 139 | + ); |
|
| 140 | 140 | |
| 141 | - // Loader class instance. |
|
| 142 | - return take($this->viewInstance($view, $path, $data), function ($view) { |
|
| 143 | - $this->callCreator($view); |
|
| 144 | - }); |
|
| 145 | - } |
|
| 141 | + // Loader class instance. |
|
| 142 | + return take($this->viewInstance($view, $path, $data), function ($view) { |
|
| 143 | + $this->callCreator($view); |
|
| 144 | + }); |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | - /** |
|
| 148 | - * Normalize a view name. |
|
| 149 | - * |
|
| 150 | - * @param string $name |
|
| 151 | - * |
|
| 152 | - * @return string |
|
| 153 | - */ |
|
| 154 | - protected function normalizeName($name) |
|
| 147 | + /** |
|
| 148 | + * Normalize a view name. |
|
| 149 | + * |
|
| 150 | + * @param string $name |
|
| 151 | + * |
|
| 152 | + * @return string |
|
| 153 | + */ |
|
| 154 | + protected function normalizeName($name) |
|
| 155 | 155 | { |
| 156 | - return ViewName::normalize($name); |
|
| 156 | + return ViewName::normalize($name); |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | - /** |
|
| 160 | - * Create a new view instance from the given arguments. |
|
| 161 | - * |
|
| 162 | - * @param string $file View filename |
|
| 163 | - * * @param string $path Path filename |
|
| 164 | - * @param array $data Array of values |
|
| 165 | - * |
|
| 166 | - * @return \Syscodes\Contracts\View\View |
|
| 167 | - */ |
|
| 168 | - protected function viewInstance($view, $path, $data) |
|
| 169 | - { |
|
| 170 | - return new View($this, $this->getEngineFromPath($path), $view, $path, $data); |
|
| 171 | - } |
|
| 159 | + /** |
|
| 160 | + * Create a new view instance from the given arguments. |
|
| 161 | + * |
|
| 162 | + * @param string $file View filename |
|
| 163 | + * * @param string $path Path filename |
|
| 164 | + * @param array $data Array of values |
|
| 165 | + * |
|
| 166 | + * @return \Syscodes\Contracts\View\View |
|
| 167 | + */ |
|
| 168 | + protected function viewInstance($view, $path, $data) |
|
| 169 | + { |
|
| 170 | + return new View($this, $this->getEngineFromPath($path), $view, $path, $data); |
|
| 171 | + } |
|
| 172 | 172 | |
| 173 | - /** |
|
| 174 | - * Get the appropriate view engine for the given path. |
|
| 175 | - * |
|
| 176 | - * @param string $path |
|
| 177 | - * |
|
| 178 | - * @return \Illuminate\Contracts\View\Engine |
|
| 179 | - * |
|
| 180 | - * @throws \InvalidArgumentException |
|
| 181 | - */ |
|
| 182 | - public function getEngineFromPath($path) |
|
| 183 | - { |
|
| 184 | - if ( ! $extension = $this->getExtension($path)) { |
|
| 185 | - throw new InvalidArgumentException("Unrecognized extension in file: {$path}"); |
|
| 186 | - } |
|
| 173 | + /** |
|
| 174 | + * Get the appropriate view engine for the given path. |
|
| 175 | + * |
|
| 176 | + * @param string $path |
|
| 177 | + * |
|
| 178 | + * @return \Illuminate\Contracts\View\Engine |
|
| 179 | + * |
|
| 180 | + * @throws \InvalidArgumentException |
|
| 181 | + */ |
|
| 182 | + public function getEngineFromPath($path) |
|
| 183 | + { |
|
| 184 | + if ( ! $extension = $this->getExtension($path)) { |
|
| 185 | + throw new InvalidArgumentException("Unrecognized extension in file: {$path}"); |
|
| 186 | + } |
|
| 187 | 187 | |
| 188 | - $engine = $this->extensions[$extension]; |
|
| 188 | + $engine = $this->extensions[$extension]; |
|
| 189 | 189 | |
| 190 | - return $this->engines->resolve($engine); |
|
| 191 | - } |
|
| 190 | + return $this->engines->resolve($engine); |
|
| 191 | + } |
|
| 192 | 192 | |
| 193 | - /** |
|
| 194 | - * Get the extension used by the view file. |
|
| 195 | - * |
|
| 196 | - * @param string $path |
|
| 197 | - * |
|
| 198 | - * @return string |
|
| 199 | - */ |
|
| 200 | - protected function getExtension($path) |
|
| 201 | - { |
|
| 202 | - $extensions = array_keys($this->extensions); |
|
| 193 | + /** |
|
| 194 | + * Get the extension used by the view file. |
|
| 195 | + * |
|
| 196 | + * @param string $path |
|
| 197 | + * |
|
| 198 | + * @return string |
|
| 199 | + */ |
|
| 200 | + protected function getExtension($path) |
|
| 201 | + { |
|
| 202 | + $extensions = array_keys($this->extensions); |
|
| 203 | 203 | |
| 204 | - return Arr::first($extensions, function($key, $value) use ($path) { |
|
| 205 | - return Str::endsWith($path, '.'.$value); |
|
| 206 | - }); |
|
| 207 | - } |
|
| 204 | + return Arr::first($extensions, function($key, $value) use ($path) { |
|
| 205 | + return Str::endsWith($path, '.'.$value); |
|
| 206 | + }); |
|
| 207 | + } |
|
| 208 | 208 | |
| 209 | - /** |
|
| 210 | - * Call the creator for a given view. |
|
| 211 | - * |
|
| 212 | - * @param \Syscodes\View\View $view |
|
| 213 | - * |
|
| 214 | - * @return void |
|
| 215 | - */ |
|
| 216 | - public function callCreator(View $view) |
|
| 217 | - { |
|
| 218 | - $this->events->dispatch('creating: '.$view->getView(), [$view]); |
|
| 219 | - } |
|
| 209 | + /** |
|
| 210 | + * Call the creator for a given view. |
|
| 211 | + * |
|
| 212 | + * @param \Syscodes\View\View $view |
|
| 213 | + * |
|
| 214 | + * @return void |
|
| 215 | + */ |
|
| 216 | + public function callCreator(View $view) |
|
| 217 | + { |
|
| 218 | + $this->events->dispatch('creating: '.$view->getView(), [$view]); |
|
| 219 | + } |
|
| 220 | 220 | |
| 221 | - /** |
|
| 222 | - * Get the extension to engine bindings. |
|
| 223 | - * |
|
| 224 | - * @return array |
|
| 225 | - */ |
|
| 226 | - public function getExtensions() |
|
| 227 | - { |
|
| 228 | - return $this->extensions; |
|
| 229 | - } |
|
| 221 | + /** |
|
| 222 | + * Get the extension to engine bindings. |
|
| 223 | + * |
|
| 224 | + * @return array |
|
| 225 | + */ |
|
| 226 | + public function getExtensions() |
|
| 227 | + { |
|
| 228 | + return $this->extensions; |
|
| 229 | + } |
|
| 230 | 230 | |
| 231 | - /** |
|
| 232 | - * Add a piece of shared data to the environment. |
|
| 233 | - * |
|
| 234 | - * @param array|string $key |
|
| 235 | - * @param mixed|null $value |
|
| 236 | - * |
|
| 237 | - * @return mixed |
|
| 238 | - */ |
|
| 239 | - public function share($key, $value = null) |
|
| 240 | - { |
|
| 241 | - $keys = is_array($key) ? $key : [$key => $value]; |
|
| 231 | + /** |
|
| 232 | + * Add a piece of shared data to the environment. |
|
| 233 | + * |
|
| 234 | + * @param array|string $key |
|
| 235 | + * @param mixed|null $value |
|
| 236 | + * |
|
| 237 | + * @return mixed |
|
| 238 | + */ |
|
| 239 | + public function share($key, $value = null) |
|
| 240 | + { |
|
| 241 | + $keys = is_array($key) ? $key : [$key => $value]; |
|
| 242 | 242 | |
| 243 | - foreach ($keys as $key => $value) { |
|
| 244 | - $this->shared[$key] = $value; |
|
| 245 | - } |
|
| 243 | + foreach ($keys as $key => $value) { |
|
| 244 | + $this->shared[$key] = $value; |
|
| 245 | + } |
|
| 246 | 246 | |
| 247 | - return $value; |
|
| 248 | - } |
|
| 247 | + return $value; |
|
| 248 | + } |
|
| 249 | 249 | |
| 250 | - /** |
|
| 251 | - * Replace the namespace hints for the given namespace. |
|
| 252 | - * |
|
| 253 | - * @param string $namespace |
|
| 254 | - * @param string|array $hints |
|
| 255 | - * |
|
| 256 | - * @return $this |
|
| 257 | - */ |
|
| 258 | - public function replaceNamespace($namespace, $hints) |
|
| 259 | - { |
|
| 260 | - $this->finder->replaceNamespace($namespace, $hints); |
|
| 250 | + /** |
|
| 251 | + * Replace the namespace hints for the given namespace. |
|
| 252 | + * |
|
| 253 | + * @param string $namespace |
|
| 254 | + * @param string|array $hints |
|
| 255 | + * |
|
| 256 | + * @return $this |
|
| 257 | + */ |
|
| 258 | + public function replaceNamespace($namespace, $hints) |
|
| 259 | + { |
|
| 260 | + $this->finder->replaceNamespace($namespace, $hints); |
|
| 261 | 261 | |
| 262 | - return $this; |
|
| 263 | - } |
|
| 262 | + return $this; |
|
| 263 | + } |
|
| 264 | 264 | |
| 265 | - /** |
|
| 266 | - * Increment the rendering counter. |
|
| 267 | - * |
|
| 268 | - * @return void |
|
| 269 | - */ |
|
| 270 | - public function increment() |
|
| 271 | - { |
|
| 272 | - return $this->renderCount++; |
|
| 273 | - } |
|
| 265 | + /** |
|
| 266 | + * Increment the rendering counter. |
|
| 267 | + * |
|
| 268 | + * @return void |
|
| 269 | + */ |
|
| 270 | + public function increment() |
|
| 271 | + { |
|
| 272 | + return $this->renderCount++; |
|
| 273 | + } |
|
| 274 | 274 | |
| 275 | - /** |
|
| 276 | - * Decrement the rendering counter. |
|
| 277 | - * |
|
| 278 | - * @return void |
|
| 279 | - */ |
|
| 280 | - public function decrement() |
|
| 281 | - { |
|
| 282 | - return $this->renderCount--; |
|
| 283 | - } |
|
| 275 | + /** |
|
| 276 | + * Decrement the rendering counter. |
|
| 277 | + * |
|
| 278 | + * @return void |
|
| 279 | + */ |
|
| 280 | + public function decrement() |
|
| 281 | + { |
|
| 282 | + return $this->renderCount--; |
|
| 283 | + } |
|
| 284 | 284 | |
| 285 | - /** |
|
| 286 | - * Check if there are no active render operations. |
|
| 287 | - * |
|
| 288 | - * @return bool |
|
| 289 | - */ |
|
| 290 | - public function doneRendering() |
|
| 291 | - { |
|
| 292 | - return $this->renderCount == 0; |
|
| 293 | - } |
|
| 285 | + /** |
|
| 286 | + * Check if there are no active render operations. |
|
| 287 | + * |
|
| 288 | + * @return bool |
|
| 289 | + */ |
|
| 290 | + public function doneRendering() |
|
| 291 | + { |
|
| 292 | + return $this->renderCount == 0; |
|
| 293 | + } |
|
| 294 | 294 | |
| 295 | - /** |
|
| 296 | - * Flush all of the parser state like sections. |
|
| 297 | - * |
|
| 298 | - * @return void |
|
| 299 | - */ |
|
| 300 | - public function flushState() |
|
| 301 | - { |
|
| 302 | - $this->renderCount = 0; |
|
| 295 | + /** |
|
| 296 | + * Flush all of the parser state like sections. |
|
| 297 | + * |
|
| 298 | + * @return void |
|
| 299 | + */ |
|
| 300 | + public function flushState() |
|
| 301 | + { |
|
| 302 | + $this->renderCount = 0; |
|
| 303 | 303 | |
| 304 | - $this->flushSections(); |
|
| 305 | - } |
|
| 304 | + $this->flushSections(); |
|
| 305 | + } |
|
| 306 | 306 | |
| 307 | - /** |
|
| 308 | - * Flush all of the section contents if done rendering. |
|
| 309 | - * |
|
| 310 | - * @return void |
|
| 311 | - */ |
|
| 312 | - public function flushStateIfDoneRendering() |
|
| 313 | - { |
|
| 314 | - if ($this->doneRendering()) { |
|
| 315 | - $this->flushState(); |
|
| 316 | - } |
|
| 317 | - } |
|
| 307 | + /** |
|
| 308 | + * Flush all of the section contents if done rendering. |
|
| 309 | + * |
|
| 310 | + * @return void |
|
| 311 | + */ |
|
| 312 | + public function flushStateIfDoneRendering() |
|
| 313 | + { |
|
| 314 | + if ($this->doneRendering()) { |
|
| 315 | + $this->flushState(); |
|
| 316 | + } |
|
| 317 | + } |
|
| 318 | 318 | |
| 319 | - /** |
|
| 320 | - * Get all of the shared data for the environment. |
|
| 321 | - * |
|
| 322 | - * @return void |
|
| 323 | - */ |
|
| 324 | - public function getShared() |
|
| 325 | - { |
|
| 326 | - return $this->shared; |
|
| 327 | - } |
|
| 319 | + /** |
|
| 320 | + * Get all of the shared data for the environment. |
|
| 321 | + * |
|
| 322 | + * @return void |
|
| 323 | + */ |
|
| 324 | + public function getShared() |
|
| 325 | + { |
|
| 326 | + return $this->shared; |
|
| 327 | + } |
|
| 328 | 328 | |
| 329 | - /** |
|
| 330 | - * Get the IoC container instance. |
|
| 331 | - * |
|
| 332 | - * @return \Syscodes\Contracts\Container\Container |
|
| 333 | - */ |
|
| 334 | - public function getContainer() |
|
| 335 | - { |
|
| 336 | - return $this->container; |
|
| 337 | - } |
|
| 329 | + /** |
|
| 330 | + * Get the IoC container instance. |
|
| 331 | + * |
|
| 332 | + * @return \Syscodes\Contracts\Container\Container |
|
| 333 | + */ |
|
| 334 | + public function getContainer() |
|
| 335 | + { |
|
| 336 | + return $this->container; |
|
| 337 | + } |
|
| 338 | 338 | |
| 339 | - /** |
|
| 340 | - * Set the IoC container instance. |
|
| 341 | - * |
|
| 342 | - * @param \Syscodes\Contracts\Container\Container $container |
|
| 343 | - * |
|
| 344 | - * @return void |
|
| 345 | - */ |
|
| 346 | - public function setContainer($container) |
|
| 347 | - { |
|
| 348 | - $this->container = $container; |
|
| 349 | - } |
|
| 339 | + /** |
|
| 340 | + * Set the IoC container instance. |
|
| 341 | + * |
|
| 342 | + * @param \Syscodes\Contracts\Container\Container $container |
|
| 343 | + * |
|
| 344 | + * @return void |
|
| 345 | + */ |
|
| 346 | + public function setContainer($container) |
|
| 347 | + { |
|
| 348 | + $this->container = $container; |
|
| 349 | + } |
|
| 350 | 350 | } |
| 351 | 351 | \ No newline at end of file |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | $this->factory->flushStateIfDoneRendering(); |
| 121 | 121 | |
| 122 | 122 | return ! is_null($response) ? $response : $contents; |
| 123 | - } catch(Throwable $e) { |
|
| 123 | + } catch (Throwable $e) { |
|
| 124 | 124 | $this->factory->flushState(); |
| 125 | 125 | |
| 126 | 126 | throw $e; |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | { |
| 163 | 163 | $data = array_merge($this->factory->getShared(), $this->data); |
| 164 | 164 | |
| 165 | - return array_map(function ($value) { |
|
| 165 | + return array_map(function($value) { |
|
| 166 | 166 | return ($value instanceof Renderable) ? $value->render() : $value; |
| 167 | 167 | }, $data); |
| 168 | 168 | } |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | */ |
| 177 | 177 | public function renderSections() |
| 178 | 178 | { |
| 179 | - return $this->render(function () { |
|
| 179 | + return $this->render(function() { |
|
| 180 | 180 | return $this->factory->getSections(); |
| 181 | 181 | }); |
| 182 | 182 | } |
@@ -216,7 +216,7 @@ discard block |
||
| 216 | 216 | */ |
| 217 | 217 | public function bind($key, & $value) |
| 218 | 218 | { |
| 219 | - $this->data[$key] =& $value; |
|
| 219 | + $this->data[$key] = & $value; |
|
| 220 | 220 | |
| 221 | 221 | return $this; |
| 222 | 222 | } |
@@ -42,469 +42,469 @@ |
||
| 42 | 42 | */ |
| 43 | 43 | class View implements ArrayAccess, Webable, ViewContract |
| 44 | 44 | { |
| 45 | - /** |
|
| 46 | - * Array of local variables. |
|
| 47 | - * |
|
| 48 | - * @var array $data |
|
| 49 | - */ |
|
| 50 | - protected $data = []; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * The engine implementation. |
|
| 54 | - * |
|
| 55 | - * @var \Syscodes\Contracts\View\Engine $engine |
|
| 56 | - */ |
|
| 57 | - protected $engine; |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * The view factory instance. |
|
| 61 | - * |
|
| 62 | - * @var \Syscodes\View\factory $factory |
|
| 63 | - */ |
|
| 64 | - protected $factory; |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * The path to the view file. |
|
| 68 | - * |
|
| 69 | - * @var string $path |
|
| 70 | - */ |
|
| 71 | - protected $path; |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * Get the name of the view. |
|
| 75 | - * |
|
| 76 | - * @var string $view |
|
| 77 | - */ |
|
| 78 | - protected $view; |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Constructor: Create a new view instance. |
|
| 82 | - * |
|
| 83 | - * @param \Syscodes\View\factory $factory |
|
| 84 | - * @param \Syscodes\Contracts\View\Engine $engine |
|
| 85 | - * @param string $view |
|
| 86 | - * @param string $path |
|
| 87 | - * @param array $data |
|
| 88 | - * |
|
| 89 | - * @return void |
|
| 90 | - * |
|
| 91 | - * @throws \InvalidArgumentException |
|
| 92 | - */ |
|
| 93 | - public function __construct(Factory $factory, Engine $engine, $view, $path, $data = []) |
|
| 94 | - { |
|
| 95 | - $this->factory = $factory; |
|
| 96 | - $this->engine = $engine; |
|
| 97 | - $this->view = $view; |
|
| 98 | - $this->path = $path; |
|
| 99 | - $this->data = $data instanceof Arrayable ? $data->toArray() : (array) $data; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Get the string contents of the view. |
|
| 104 | - * |
|
| 105 | - * @example View::render(); |
|
| 106 | - * |
|
| 107 | - * @param \Callable|null $callback |
|
| 108 | - * |
|
| 109 | - * @return array|string |
|
| 110 | - * |
|
| 111 | - * @throws \Throwable |
|
| 112 | - */ |
|
| 113 | - public function render(Callable $callback = null) |
|
| 114 | - { |
|
| 115 | - try { |
|
| 116 | - $contents = $this->renderContents(); |
|
| 117 | - |
|
| 118 | - $response = isset($callback) ? $callback($this, $contents) : null; |
|
| 119 | - |
|
| 120 | - $this->factory->flushStateIfDoneRendering(); |
|
| 121 | - |
|
| 122 | - return ! is_null($response) ? $response : $contents; |
|
| 123 | - } catch(Throwable $e) { |
|
| 124 | - $this->factory->flushState(); |
|
| 125 | - |
|
| 126 | - throw $e; |
|
| 127 | - } |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * Get the contents of the view instance. |
|
| 132 | - * |
|
| 133 | - * @return void |
|
| 134 | - */ |
|
| 135 | - protected function renderContents() |
|
| 136 | - { |
|
| 137 | - $this->factory->increment(); |
|
| 138 | - |
|
| 139 | - $contents = $this->getContents(); |
|
| 140 | - |
|
| 141 | - $this->factory->decrement(); |
|
| 142 | - |
|
| 143 | - return $contents; |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * Get the evaluated contents of the view. |
|
| 148 | - * |
|
| 149 | - * @return void |
|
| 150 | - */ |
|
| 151 | - protected function getContents() |
|
| 152 | - { |
|
| 153 | - return $this->engine->get($this->path, $this->getArrayData()); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * The view data will be extracted. |
|
| 158 | - * |
|
| 159 | - * @return array |
|
| 160 | - */ |
|
| 161 | - public function getArrayData() |
|
| 162 | - { |
|
| 163 | - $data = array_merge($this->factory->getShared(), $this->data); |
|
| 45 | + /** |
|
| 46 | + * Array of local variables. |
|
| 47 | + * |
|
| 48 | + * @var array $data |
|
| 49 | + */ |
|
| 50 | + protected $data = []; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * The engine implementation. |
|
| 54 | + * |
|
| 55 | + * @var \Syscodes\Contracts\View\Engine $engine |
|
| 56 | + */ |
|
| 57 | + protected $engine; |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * The view factory instance. |
|
| 61 | + * |
|
| 62 | + * @var \Syscodes\View\factory $factory |
|
| 63 | + */ |
|
| 64 | + protected $factory; |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * The path to the view file. |
|
| 68 | + * |
|
| 69 | + * @var string $path |
|
| 70 | + */ |
|
| 71 | + protected $path; |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * Get the name of the view. |
|
| 75 | + * |
|
| 76 | + * @var string $view |
|
| 77 | + */ |
|
| 78 | + protected $view; |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Constructor: Create a new view instance. |
|
| 82 | + * |
|
| 83 | + * @param \Syscodes\View\factory $factory |
|
| 84 | + * @param \Syscodes\Contracts\View\Engine $engine |
|
| 85 | + * @param string $view |
|
| 86 | + * @param string $path |
|
| 87 | + * @param array $data |
|
| 88 | + * |
|
| 89 | + * @return void |
|
| 90 | + * |
|
| 91 | + * @throws \InvalidArgumentException |
|
| 92 | + */ |
|
| 93 | + public function __construct(Factory $factory, Engine $engine, $view, $path, $data = []) |
|
| 94 | + { |
|
| 95 | + $this->factory = $factory; |
|
| 96 | + $this->engine = $engine; |
|
| 97 | + $this->view = $view; |
|
| 98 | + $this->path = $path; |
|
| 99 | + $this->data = $data instanceof Arrayable ? $data->toArray() : (array) $data; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Get the string contents of the view. |
|
| 104 | + * |
|
| 105 | + * @example View::render(); |
|
| 106 | + * |
|
| 107 | + * @param \Callable|null $callback |
|
| 108 | + * |
|
| 109 | + * @return array|string |
|
| 110 | + * |
|
| 111 | + * @throws \Throwable |
|
| 112 | + */ |
|
| 113 | + public function render(Callable $callback = null) |
|
| 114 | + { |
|
| 115 | + try { |
|
| 116 | + $contents = $this->renderContents(); |
|
| 117 | + |
|
| 118 | + $response = isset($callback) ? $callback($this, $contents) : null; |
|
| 119 | + |
|
| 120 | + $this->factory->flushStateIfDoneRendering(); |
|
| 121 | + |
|
| 122 | + return ! is_null($response) ? $response : $contents; |
|
| 123 | + } catch(Throwable $e) { |
|
| 124 | + $this->factory->flushState(); |
|
| 125 | + |
|
| 126 | + throw $e; |
|
| 127 | + } |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * Get the contents of the view instance. |
|
| 132 | + * |
|
| 133 | + * @return void |
|
| 134 | + */ |
|
| 135 | + protected function renderContents() |
|
| 136 | + { |
|
| 137 | + $this->factory->increment(); |
|
| 138 | + |
|
| 139 | + $contents = $this->getContents(); |
|
| 140 | + |
|
| 141 | + $this->factory->decrement(); |
|
| 142 | + |
|
| 143 | + return $contents; |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * Get the evaluated contents of the view. |
|
| 148 | + * |
|
| 149 | + * @return void |
|
| 150 | + */ |
|
| 151 | + protected function getContents() |
|
| 152 | + { |
|
| 153 | + return $this->engine->get($this->path, $this->getArrayData()); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * The view data will be extracted. |
|
| 158 | + * |
|
| 159 | + * @return array |
|
| 160 | + */ |
|
| 161 | + public function getArrayData() |
|
| 162 | + { |
|
| 163 | + $data = array_merge($this->factory->getShared(), $this->data); |
|
| 164 | 164 | |
| 165 | - return array_map(function ($value) { |
|
| 166 | - return ($value instanceof Renderable) ? $value->render() : $value; |
|
| 167 | - }, $data); |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * Get the sections of the rendered view. |
|
| 172 | - * |
|
| 173 | - * @return array |
|
| 174 | - * |
|
| 175 | - * @throws \Throwable |
|
| 176 | - */ |
|
| 177 | - public function renderSections() |
|
| 178 | - { |
|
| 179 | - return $this->render(function () { |
|
| 180 | - return $this->factory->getSections(); |
|
| 181 | - }); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - /** |
|
| 185 | - * Add a piece of data to the view. |
|
| 186 | - * |
|
| 187 | - * @example $view->assign($content, $data); |
|
| 188 | - * |
|
| 189 | - * @param string|array $key |
|
| 190 | - * @param mixed $value |
|
| 191 | - * |
|
| 192 | - * @return $this |
|
| 193 | - */ |
|
| 194 | - public function assign($key, $value = null) |
|
| 195 | - { |
|
| 196 | - if (is_array($key)) { |
|
| 197 | - $this->data = array_merge($this->data, $key); |
|
| 198 | - } else { |
|
| 199 | - $this->data = [$key => $value]; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - return $this; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - /** |
|
| 206 | - * Assigns a value by reference. The benefit of binding is that values can be altered |
|
| 207 | - * without re-setting them. It is also possible to bind variables before they have values. |
|
| 208 | - * Assigned values will be available as a variable within the view file: |
|
| 209 | - * |
|
| 210 | - * @example $view->bind('ref', $bar); |
|
| 211 | - * |
|
| 212 | - * @param string $key Variable name |
|
| 213 | - * @param mixed $value Referenced variable |
|
| 214 | - * |
|
| 215 | - * @return $this |
|
| 216 | - */ |
|
| 217 | - public function bind($key, & $value) |
|
| 218 | - { |
|
| 219 | - $this->data[$key] =& $value; |
|
| 220 | - |
|
| 221 | - return $this; |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - /** |
|
| 225 | - * Get the array of view data. |
|
| 226 | - * |
|
| 227 | - * @return array |
|
| 228 | - */ |
|
| 229 | - public function getData() |
|
| 230 | - { |
|
| 231 | - return $this->data; |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - /** |
|
| 235 | - * Get the name of the view. |
|
| 236 | - * |
|
| 237 | - * @return string |
|
| 238 | - */ |
|
| 239 | - public function getView() |
|
| 240 | - { |
|
| 241 | - return $this->view; |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - /** |
|
| 245 | - * Get the path to the view file. |
|
| 246 | - * |
|
| 247 | - * @return string |
|
| 248 | - */ |
|
| 249 | - public function getPath() |
|
| 250 | - { |
|
| 251 | - return $this->path; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * Set the path to the view file. |
|
| 256 | - * |
|
| 257 | - * @param string $path |
|
| 258 | - * |
|
| 259 | - * @return void |
|
| 260 | - */ |
|
| 261 | - public function setPath($path) |
|
| 262 | - { |
|
| 263 | - $this->path = $path; |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * Get the view factory instance. |
|
| 268 | - * |
|
| 269 | - * @return \Syscodes\View\factory |
|
| 270 | - */ |
|
| 271 | - public function getFactory() |
|
| 272 | - { |
|
| 273 | - return $this->factory; |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - /** |
|
| 277 | - * Get the view's rendering engine. |
|
| 278 | - * |
|
| 279 | - * @return \Syscodes\Contracts\View\Engine |
|
| 280 | - */ |
|
| 281 | - public function getEngine() |
|
| 282 | - { |
|
| 283 | - return $this->engine; |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * Searches for the given variable and returns its value. |
|
| 288 | - * Local variables will be returned before global variables. |
|
| 289 | - * |
|
| 290 | - * @example $value = $view->get('foo', 'bar'); |
|
| 291 | - * |
|
| 292 | - * If the key is not given or null, the entire data array is returned. |
|
| 293 | - * |
|
| 294 | - * @param string $key The variable name |
|
| 295 | - * @param mixed $default The default value to return |
|
| 296 | - * |
|
| 297 | - * @return mixed |
|
| 298 | - * |
|
| 299 | - * @uses \Syscodes\Contracts\Core\Lenevor |
|
| 300 | - * |
|
| 301 | - * @throws \InvalidArgumentException |
|
| 302 | - */ |
|
| 303 | - public function &get($key, $default = null) |
|
| 304 | - { |
|
| 305 | - if (strpos($key, '.') === false) { |
|
| 306 | - if (array_key_exists($key, $this->data)) { |
|
| 307 | - return $this->data[$key]; |
|
| 308 | - } else { |
|
| 309 | - throw new InvalidArgumentException(__('view.variableNotSet')); |
|
| 310 | - } |
|
| 311 | - } else { |
|
| 312 | - return value($default); |
|
| 313 | - } |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - /** |
|
| 317 | - * Assigns a variable by name. Assigned values will be available as a |
|
| 318 | - * variable within the view file: |
|
| 319 | - * |
|
| 320 | - * This value can be accessed as $var within the view |
|
| 321 | - * @example $view->set(array('food' => 'bread', 'beverage' => 'water')); |
|
| 322 | - * |
|
| 323 | - * @param string|array $key Variable name |
|
| 324 | - * @param mixed $value Value |
|
| 325 | - * |
|
| 326 | - * @return $this |
|
| 327 | - * |
|
| 328 | - * @uses instanceof \Traversable |
|
| 329 | - */ |
|
| 330 | - public function set($key, $value = null) |
|
| 331 | - { |
|
| 332 | - if (is_array($key) || $key instanceof Traversable) { |
|
| 333 | - foreach ($key as $name => $value) { |
|
| 334 | - $this->set($name, $value); |
|
| 335 | - } |
|
| 336 | - } else { |
|
| 337 | - if (strpos($key, '.') === false) { |
|
| 338 | - $this->data[$key] = $value; |
|
| 339 | - } else { |
|
| 340 | - Arr::set($this->data, $key, $value); |
|
| 341 | - } |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - return $this; |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - /* |
|
| 165 | + return array_map(function ($value) { |
|
| 166 | + return ($value instanceof Renderable) ? $value->render() : $value; |
|
| 167 | + }, $data); |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * Get the sections of the rendered view. |
|
| 172 | + * |
|
| 173 | + * @return array |
|
| 174 | + * |
|
| 175 | + * @throws \Throwable |
|
| 176 | + */ |
|
| 177 | + public function renderSections() |
|
| 178 | + { |
|
| 179 | + return $this->render(function () { |
|
| 180 | + return $this->factory->getSections(); |
|
| 181 | + }); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + /** |
|
| 185 | + * Add a piece of data to the view. |
|
| 186 | + * |
|
| 187 | + * @example $view->assign($content, $data); |
|
| 188 | + * |
|
| 189 | + * @param string|array $key |
|
| 190 | + * @param mixed $value |
|
| 191 | + * |
|
| 192 | + * @return $this |
|
| 193 | + */ |
|
| 194 | + public function assign($key, $value = null) |
|
| 195 | + { |
|
| 196 | + if (is_array($key)) { |
|
| 197 | + $this->data = array_merge($this->data, $key); |
|
| 198 | + } else { |
|
| 199 | + $this->data = [$key => $value]; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + return $this; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + /** |
|
| 206 | + * Assigns a value by reference. The benefit of binding is that values can be altered |
|
| 207 | + * without re-setting them. It is also possible to bind variables before they have values. |
|
| 208 | + * Assigned values will be available as a variable within the view file: |
|
| 209 | + * |
|
| 210 | + * @example $view->bind('ref', $bar); |
|
| 211 | + * |
|
| 212 | + * @param string $key Variable name |
|
| 213 | + * @param mixed $value Referenced variable |
|
| 214 | + * |
|
| 215 | + * @return $this |
|
| 216 | + */ |
|
| 217 | + public function bind($key, & $value) |
|
| 218 | + { |
|
| 219 | + $this->data[$key] =& $value; |
|
| 220 | + |
|
| 221 | + return $this; |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + /** |
|
| 225 | + * Get the array of view data. |
|
| 226 | + * |
|
| 227 | + * @return array |
|
| 228 | + */ |
|
| 229 | + public function getData() |
|
| 230 | + { |
|
| 231 | + return $this->data; |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + /** |
|
| 235 | + * Get the name of the view. |
|
| 236 | + * |
|
| 237 | + * @return string |
|
| 238 | + */ |
|
| 239 | + public function getView() |
|
| 240 | + { |
|
| 241 | + return $this->view; |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + /** |
|
| 245 | + * Get the path to the view file. |
|
| 246 | + * |
|
| 247 | + * @return string |
|
| 248 | + */ |
|
| 249 | + public function getPath() |
|
| 250 | + { |
|
| 251 | + return $this->path; |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * Set the path to the view file. |
|
| 256 | + * |
|
| 257 | + * @param string $path |
|
| 258 | + * |
|
| 259 | + * @return void |
|
| 260 | + */ |
|
| 261 | + public function setPath($path) |
|
| 262 | + { |
|
| 263 | + $this->path = $path; |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * Get the view factory instance. |
|
| 268 | + * |
|
| 269 | + * @return \Syscodes\View\factory |
|
| 270 | + */ |
|
| 271 | + public function getFactory() |
|
| 272 | + { |
|
| 273 | + return $this->factory; |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + /** |
|
| 277 | + * Get the view's rendering engine. |
|
| 278 | + * |
|
| 279 | + * @return \Syscodes\Contracts\View\Engine |
|
| 280 | + */ |
|
| 281 | + public function getEngine() |
|
| 282 | + { |
|
| 283 | + return $this->engine; |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * Searches for the given variable and returns its value. |
|
| 288 | + * Local variables will be returned before global variables. |
|
| 289 | + * |
|
| 290 | + * @example $value = $view->get('foo', 'bar'); |
|
| 291 | + * |
|
| 292 | + * If the key is not given or null, the entire data array is returned. |
|
| 293 | + * |
|
| 294 | + * @param string $key The variable name |
|
| 295 | + * @param mixed $default The default value to return |
|
| 296 | + * |
|
| 297 | + * @return mixed |
|
| 298 | + * |
|
| 299 | + * @uses \Syscodes\Contracts\Core\Lenevor |
|
| 300 | + * |
|
| 301 | + * @throws \InvalidArgumentException |
|
| 302 | + */ |
|
| 303 | + public function &get($key, $default = null) |
|
| 304 | + { |
|
| 305 | + if (strpos($key, '.') === false) { |
|
| 306 | + if (array_key_exists($key, $this->data)) { |
|
| 307 | + return $this->data[$key]; |
|
| 308 | + } else { |
|
| 309 | + throw new InvalidArgumentException(__('view.variableNotSet')); |
|
| 310 | + } |
|
| 311 | + } else { |
|
| 312 | + return value($default); |
|
| 313 | + } |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + /** |
|
| 317 | + * Assigns a variable by name. Assigned values will be available as a |
|
| 318 | + * variable within the view file: |
|
| 319 | + * |
|
| 320 | + * This value can be accessed as $var within the view |
|
| 321 | + * @example $view->set(array('food' => 'bread', 'beverage' => 'water')); |
|
| 322 | + * |
|
| 323 | + * @param string|array $key Variable name |
|
| 324 | + * @param mixed $value Value |
|
| 325 | + * |
|
| 326 | + * @return $this |
|
| 327 | + * |
|
| 328 | + * @uses instanceof \Traversable |
|
| 329 | + */ |
|
| 330 | + public function set($key, $value = null) |
|
| 331 | + { |
|
| 332 | + if (is_array($key) || $key instanceof Traversable) { |
|
| 333 | + foreach ($key as $name => $value) { |
|
| 334 | + $this->set($name, $value); |
|
| 335 | + } |
|
| 336 | + } else { |
|
| 337 | + if (strpos($key, '.') === false) { |
|
| 338 | + $this->data[$key] = $value; |
|
| 339 | + } else { |
|
| 340 | + Arr::set($this->data, $key, $value); |
|
| 341 | + } |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + return $this; |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + /* |
|
| 348 | 348 | |----------------------------------------------------------------- |
| 349 | 349 | | ArrayAccess Methods |
| 350 | 350 | |----------------------------------------------------------------- |
| 351 | 351 | */ |
| 352 | 352 | |
| 353 | - /** |
|
| 354 | - * Whether or not an offset exists. |
|
| 355 | - * |
|
| 356 | - * @param string $offset |
|
| 357 | - * |
|
| 358 | - * @return bool |
|
| 359 | - */ |
|
| 360 | - public function offsetExists($offset) |
|
| 361 | - { |
|
| 362 | - return array_key_exists($offset, $this->data); |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - /** |
|
| 366 | - * Returns the value at specified offset. |
|
| 367 | - * |
|
| 368 | - * @param string $offset |
|
| 369 | - * |
|
| 370 | - * @return mixed |
|
| 371 | - */ |
|
| 372 | - public function offsetGet($offset) |
|
| 373 | - { |
|
| 374 | - return $this->data[$offset]; |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - /** |
|
| 378 | - * Assigns a value to the specified offset |
|
| 379 | - * |
|
| 380 | - * @param string $offset |
|
| 381 | - * @param mixed $value |
|
| 382 | - * |
|
| 383 | - * @return void |
|
| 384 | - */ |
|
| 385 | - public function offsetSet($offset, $value) |
|
| 386 | - { |
|
| 387 | - $this->assign($offset, $value); |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - /** |
|
| 391 | - * Unsets an offset. |
|
| 392 | - * |
|
| 393 | - * @param string $offset |
|
| 394 | - * |
|
| 395 | - * @return void |
|
| 396 | - */ |
|
| 397 | - public function offsetUnset($offset) |
|
| 398 | - { |
|
| 399 | - unset($this->data[$offset]); |
|
| 400 | - } |
|
| 401 | - |
|
| 402 | - /** |
|
| 403 | - * Magic method. Searches for the given variable and returns its value. |
|
| 404 | - * Local variables will be returned before global variables. |
|
| 405 | - * |
|
| 406 | - * @example $value = $view->var; |
|
| 407 | - * |
|
| 408 | - * @param string $key Variable name |
|
| 409 | - * |
|
| 410 | - * @return mixed |
|
| 411 | - * |
|
| 412 | - * @throws \Syscodes\LenevorException |
|
| 413 | - */ |
|
| 414 | - public function &__get($key) |
|
| 415 | - { |
|
| 416 | - return $this->get($key); |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - /** |
|
| 420 | - * Magic method. Calls [$this->set] with the same parameters. |
|
| 421 | - * |
|
| 422 | - * @example $view->var = 'something'; |
|
| 423 | - * |
|
| 424 | - * @param string $key Variable name |
|
| 425 | - * @param mixed $value Value |
|
| 426 | - * |
|
| 427 | - * @return void |
|
| 428 | - */ |
|
| 429 | - public function __set($key, $value) |
|
| 430 | - { |
|
| 431 | - $this->set($key, $value); |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - /** |
|
| 435 | - * Magic method. Determines if a variable is set. |
|
| 436 | - * |
|
| 437 | - * @example isset($view->foo); |
|
| 438 | - * |
|
| 439 | - * Variables are not considered to be set. |
|
| 440 | - * |
|
| 441 | - * @param string $key variable name |
|
| 442 | - * |
|
| 443 | - * @return boolean |
|
| 444 | - */ |
|
| 445 | - public function __isset($key) |
|
| 446 | - { |
|
| 447 | - return isset($this->data[$key]); |
|
| 448 | - } |
|
| 449 | - |
|
| 450 | - /** |
|
| 451 | - * Magic method. Unsets a given variable. |
|
| 452 | - * |
|
| 453 | - * @example unset($view->var); |
|
| 454 | - * |
|
| 455 | - * @param string $key Variable name |
|
| 456 | - * |
|
| 457 | - * @return void |
|
| 458 | - */ |
|
| 459 | - public function __unset($key) |
|
| 460 | - { |
|
| 461 | - unset($this->data[$key]); |
|
| 462 | - } |
|
| 463 | - |
|
| 464 | - /** |
|
| 465 | - * Magic Method for handling dynamic functions. |
|
| 466 | - * |
|
| 467 | - * @param string $method |
|
| 468 | - * @param array $parameters |
|
| 469 | - * |
|
| 470 | - * @return mixed |
|
| 471 | - * |
|
| 472 | - * @throws \BadMethodCallException; |
|
| 473 | - */ |
|
| 474 | - public function __call($method, $parameters) |
|
| 475 | - { |
|
| 476 | - if (Str::startsWith($method, 'assign')) { |
|
| 477 | - $name = Str::camelcase(substr($method, 4)); |
|
| 478 | - |
|
| 479 | - return $this->assign($name, $parameters[0]); |
|
| 480 | - } |
|
| 481 | - |
|
| 482 | - throw new BadMethodCallException(sprintf( |
|
| 483 | - 'Method %s::%s does not exist.', static::class, $method) |
|
| 484 | - ); |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - /** |
|
| 488 | - * Get content as a string of HTML. |
|
| 489 | - * |
|
| 490 | - * @return string |
|
| 491 | - */ |
|
| 492 | - public function toHtml() |
|
| 493 | - { |
|
| 494 | - return $this->render(); |
|
| 495 | - } |
|
| 496 | - |
|
| 497 | - /** |
|
| 498 | - * Magic method. Returns the output of [static::render]. |
|
| 499 | - * |
|
| 500 | - * @return string |
|
| 501 | - * |
|
| 502 | - * @uses View->render() |
|
| 503 | - * |
|
| 504 | - * @throws \Throwable |
|
| 505 | - */ |
|
| 506 | - public function __toString() |
|
| 507 | - { |
|
| 508 | - return $this->render(); |
|
| 509 | - } |
|
| 353 | + /** |
|
| 354 | + * Whether or not an offset exists. |
|
| 355 | + * |
|
| 356 | + * @param string $offset |
|
| 357 | + * |
|
| 358 | + * @return bool |
|
| 359 | + */ |
|
| 360 | + public function offsetExists($offset) |
|
| 361 | + { |
|
| 362 | + return array_key_exists($offset, $this->data); |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + /** |
|
| 366 | + * Returns the value at specified offset. |
|
| 367 | + * |
|
| 368 | + * @param string $offset |
|
| 369 | + * |
|
| 370 | + * @return mixed |
|
| 371 | + */ |
|
| 372 | + public function offsetGet($offset) |
|
| 373 | + { |
|
| 374 | + return $this->data[$offset]; |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + /** |
|
| 378 | + * Assigns a value to the specified offset |
|
| 379 | + * |
|
| 380 | + * @param string $offset |
|
| 381 | + * @param mixed $value |
|
| 382 | + * |
|
| 383 | + * @return void |
|
| 384 | + */ |
|
| 385 | + public function offsetSet($offset, $value) |
|
| 386 | + { |
|
| 387 | + $this->assign($offset, $value); |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + /** |
|
| 391 | + * Unsets an offset. |
|
| 392 | + * |
|
| 393 | + * @param string $offset |
|
| 394 | + * |
|
| 395 | + * @return void |
|
| 396 | + */ |
|
| 397 | + public function offsetUnset($offset) |
|
| 398 | + { |
|
| 399 | + unset($this->data[$offset]); |
|
| 400 | + } |
|
| 401 | + |
|
| 402 | + /** |
|
| 403 | + * Magic method. Searches for the given variable and returns its value. |
|
| 404 | + * Local variables will be returned before global variables. |
|
| 405 | + * |
|
| 406 | + * @example $value = $view->var; |
|
| 407 | + * |
|
| 408 | + * @param string $key Variable name |
|
| 409 | + * |
|
| 410 | + * @return mixed |
|
| 411 | + * |
|
| 412 | + * @throws \Syscodes\LenevorException |
|
| 413 | + */ |
|
| 414 | + public function &__get($key) |
|
| 415 | + { |
|
| 416 | + return $this->get($key); |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + /** |
|
| 420 | + * Magic method. Calls [$this->set] with the same parameters. |
|
| 421 | + * |
|
| 422 | + * @example $view->var = 'something'; |
|
| 423 | + * |
|
| 424 | + * @param string $key Variable name |
|
| 425 | + * @param mixed $value Value |
|
| 426 | + * |
|
| 427 | + * @return void |
|
| 428 | + */ |
|
| 429 | + public function __set($key, $value) |
|
| 430 | + { |
|
| 431 | + $this->set($key, $value); |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + /** |
|
| 435 | + * Magic method. Determines if a variable is set. |
|
| 436 | + * |
|
| 437 | + * @example isset($view->foo); |
|
| 438 | + * |
|
| 439 | + * Variables are not considered to be set. |
|
| 440 | + * |
|
| 441 | + * @param string $key variable name |
|
| 442 | + * |
|
| 443 | + * @return boolean |
|
| 444 | + */ |
|
| 445 | + public function __isset($key) |
|
| 446 | + { |
|
| 447 | + return isset($this->data[$key]); |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + /** |
|
| 451 | + * Magic method. Unsets a given variable. |
|
| 452 | + * |
|
| 453 | + * @example unset($view->var); |
|
| 454 | + * |
|
| 455 | + * @param string $key Variable name |
|
| 456 | + * |
|
| 457 | + * @return void |
|
| 458 | + */ |
|
| 459 | + public function __unset($key) |
|
| 460 | + { |
|
| 461 | + unset($this->data[$key]); |
|
| 462 | + } |
|
| 463 | + |
|
| 464 | + /** |
|
| 465 | + * Magic Method for handling dynamic functions. |
|
| 466 | + * |
|
| 467 | + * @param string $method |
|
| 468 | + * @param array $parameters |
|
| 469 | + * |
|
| 470 | + * @return mixed |
|
| 471 | + * |
|
| 472 | + * @throws \BadMethodCallException; |
|
| 473 | + */ |
|
| 474 | + public function __call($method, $parameters) |
|
| 475 | + { |
|
| 476 | + if (Str::startsWith($method, 'assign')) { |
|
| 477 | + $name = Str::camelcase(substr($method, 4)); |
|
| 478 | + |
|
| 479 | + return $this->assign($name, $parameters[0]); |
|
| 480 | + } |
|
| 481 | + |
|
| 482 | + throw new BadMethodCallException(sprintf( |
|
| 483 | + 'Method %s::%s does not exist.', static::class, $method) |
|
| 484 | + ); |
|
| 485 | + } |
|
| 486 | + |
|
| 487 | + /** |
|
| 488 | + * Get content as a string of HTML. |
|
| 489 | + * |
|
| 490 | + * @return string |
|
| 491 | + */ |
|
| 492 | + public function toHtml() |
|
| 493 | + { |
|
| 494 | + return $this->render(); |
|
| 495 | + } |
|
| 496 | + |
|
| 497 | + /** |
|
| 498 | + * Magic method. Returns the output of [static::render]. |
|
| 499 | + * |
|
| 500 | + * @return string |
|
| 501 | + * |
|
| 502 | + * @uses View->render() |
|
| 503 | + * |
|
| 504 | + * @throws \Throwable |
|
| 505 | + */ |
|
| 506 | + public function __toString() |
|
| 507 | + { |
|
| 508 | + return $this->render(); |
|
| 509 | + } |
|
| 510 | 510 | } |
| 511 | 511 | \ No newline at end of file |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | */ |
| 58 | 58 | public function registerView() |
| 59 | 59 | { |
| 60 | - $this->app->singleton('view', function ($app) { |
|
| 60 | + $this->app->singleton('view', function($app) { |
|
| 61 | 61 | // The resolver will be used by an environment to get each of the various |
| 62 | 62 | // engine implementations such as plain PHP or Plaze engine. |
| 63 | 63 | $resolver = $app['view.engine.resolver']; |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | */ |
| 85 | 85 | public function registerViewFinder() |
| 86 | 86 | { |
| 87 | - $this->app->bind('view.finder', function ($app) { |
|
| 87 | + $this->app->bind('view.finder', function($app) { |
|
| 88 | 88 | return new FileViewFinder($app['files'], $app['config']['view.paths']); |
| 89 | 89 | }); |
| 90 | 90 | } |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | */ |
| 97 | 97 | public function registerPlazeTranspiler() |
| 98 | 98 | { |
| 99 | - $this->app->singleton('plaze.transpiler', function ($app) { |
|
| 99 | + $this->app->singleton('plaze.transpiler', function($app) { |
|
| 100 | 100 | return new PlazeTranspiler( |
| 101 | 101 | $app['files'], $app['config']['view.transpiled'] |
| 102 | 102 | ); |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | */ |
| 112 | 112 | public function registerEngineResolver() |
| 113 | 113 | { |
| 114 | - $this->app->singleton('view.engine.resolver', function () { |
|
| 114 | + $this->app->singleton('view.engine.resolver', function() { |
|
| 115 | 115 | $resolver = new EngineResolver; |
| 116 | 116 | |
| 117 | 117 | // Register of the various view engines with the resolver |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | */ |
| 134 | 134 | public function registerFileEngine($resolver) |
| 135 | 135 | { |
| 136 | - $resolver->register('file', function () { |
|
| 136 | + $resolver->register('file', function() { |
|
| 137 | 137 | return new FileEngine; |
| 138 | 138 | }); |
| 139 | 139 | } |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | */ |
| 148 | 148 | public function registerPhpEngine($resolver) |
| 149 | 149 | { |
| 150 | - $resolver->register('php', function () { |
|
| 150 | + $resolver->register('php', function() { |
|
| 151 | 151 | return new PhpEngine($this->app['files']); |
| 152 | 152 | }); |
| 153 | 153 | } |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | */ |
| 162 | 162 | public function registerPlazeEngine($resolver) |
| 163 | 163 | { |
| 164 | - $resolver->register('plaze', function () { |
|
| 164 | + $resolver->register('plaze', function() { |
|
| 165 | 165 | return new TranspilerEngine($this->app['plaze.transpiler'], $this->app['files']); |
| 166 | 166 | }); |
| 167 | 167 | } |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | { |
| 72 | 72 | $pattern = sprintf('/(@)?%s\s*(.+?)\s*%s(\r?\n)?/s', $this->rawTags[0], $this->rawTags[1]); |
| 73 | 73 | |
| 74 | - $callback = function ($matches) { |
|
| 74 | + $callback = function($matches) { |
|
| 75 | 75 | $whitespace = empty($matches[3]) ? '' : $matches[3].$matches[3]; |
| 76 | 76 | |
| 77 | 77 | return $matches[1] ? substr($matches[0], 1) : "<?php echo {$matches[2]}; ?>{$whitespace}"; |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | { |
| 92 | 92 | $pattern = sprintf('/(@)?%s\s*(.+?)\s*%s(\r?\n)?/s', $this->contentTags[0], $this->contentTags[1]); |
| 93 | 93 | |
| 94 | - $callback = function ($matches) { |
|
| 94 | + $callback = function($matches) { |
|
| 95 | 95 | $whitespace = empty($matches[3]) ? '' : $matches[3].$matches[3]; |
| 96 | 96 | |
| 97 | 97 | $wrapped = sprintf($this->echoFormat, $matches[2]); |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | { |
| 114 | 114 | $pattern = sprintf('/(@)?%s\s*(.+?)\s*%s(\r?\n)?/s', $this->escapedTags[0], $this->escapedTags[1]); |
| 115 | 115 | |
| 116 | - $callback = function ($matches) { |
|
| 116 | + $callback = function($matches) { |
|
| 117 | 117 | $whitespace = empty($matches[3]) ? '' : $matches[3].$matches[3]; |
| 118 | 118 | |
| 119 | 119 | return $matches[1] ? $matches[0] : "<?php echo e({$matches[2]}); ?>{$whitespace}"; |
@@ -164,7 +164,7 @@ |
||
| 164 | 164 | |
| 165 | 165 | foreach ($transitions as $transition) { |
| 166 | 166 | if ($transition['time'] > $this->format('U')) { |
| 167 | - $dayLightSaving = (bool) $transition['isdst'] ?? $dayLightSaving; |
|
| 167 | + $dayLightSaving = (bool) $transition['isdst'] ?? $dayLightSaving; |
|
| 168 | 168 | } |
| 169 | 169 | } |
| 170 | 170 | |
@@ -167,7 +167,7 @@ |
||
| 167 | 167 | |
| 168 | 168 | if ( ! empty($file) || ! is_null($file)) { |
| 169 | 169 | $file = str_replace(['::', '.'], DIRECTORY_SEPARATOR, $file); |
| 170 | - } else { |
|
| 170 | + } else { |
|
| 171 | 171 | $file = $file ?: 'empty'; |
| 172 | 172 | |
| 173 | 173 | throw new InvalidArgumentException("File not found: [{$file}]"); |