Skip to content

Commit

Permalink
Clean up the view class.
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Dec 28, 2016
1 parent 180cac1 commit bb998dc
Showing 1 changed file with 42 additions and 34 deletions.
76 changes: 42 additions & 34 deletions src/Illuminate/View/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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]);
}

/**
Expand Down

0 comments on commit bb998dc

Please sign in to comment.