diff --git a/src/Illuminate/View/View.php b/src/Illuminate/View/View.php index 37a6bbe548de..a43900639dc2 100755 --- a/src/Illuminate/View/View.php +++ b/src/Illuminate/View/View.php @@ -127,18 +127,6 @@ protected function renderContents() return $contents; } - /** - * Get the sections of the rendered view. - * - * @return array - */ - public function renderSections() - { - return $this->render(function () { - return $this->factory->getSections(); - }); - } - /** * Get the evaluated contents of the view. * @@ -167,6 +155,18 @@ protected function gatherData() return $data; } + /** + * Get the sections of the rendered view. + * + * @return array + */ + public function renderSections() + { + return $this->render(function () { + return $this->factory->getSections(); + }); + } + /** * Add a piece of data to the view. * @@ -206,33 +206,21 @@ public function nest($key, $view, array $data = []) */ public function withErrors($provider) { - if ($provider instanceof MessageProvider) { - $this->with('errors', $provider->getMessageBag()); - } else { - $this->with('errors', new MessageBag((array) $provider)); - } + $this->with('errors', $this->formatErrors($provider)); return $this; } /** - * Get the view factory instance. + * Format the given message provider into a MessageBag. * - * @return \Illuminate\View\Factory - */ - public function getFactory() - { - return $this->factory; - } - - /** - * Get the view's rendering engine. - * - * @return \Illuminate\View\Engines\EngineInterface + * @param \Illuminate\Contracts\Support\MessageProvider|array $provider + * @return \Illuminate\Support\MessageBag */ - public function getEngine() + protected function formatErrors($provider) { - return $this->engine; + return $provider instanceof MessageProvider + ? $provider->getMessageBag() : new MessageBag((array) $provider); } /** @@ -286,6 +274,26 @@ public function setPath($path) $this->path = $path; } + /** + * Get the view factory instance. + * + * @return \Illuminate\View\Factory + */ + public function getFactory() + { + return $this->factory; + } + + /** + * Get the view's rendering engine. + * + * @return \Illuminate\View\Engines\EngineInterface + */ + public function getEngine() + { + return $this->engine; + } + /** * Determine if a piece of data is bound. * @@ -387,11 +395,11 @@ public function __unset($key) */ public function __call($method, $parameters) { - if (Str::startsWith($method, 'with')) { - return $this->with(Str::snake(substr($method, 4)), $parameters[0]); + if (! Str::startsWith($method, 'with')) { + throw new BadMethodCallException("Method [$method] does not exist on view."); } - throw new BadMethodCallException("Method [$method] does not exist on view."); + return $this->with(Str::snake(substr($method, 4)), $parameters[0]); } /**