Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 14 additions & 66 deletions src/Illuminate/View/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,6 @@ class Factory {
*/
protected $shared = array();

/**
* Array of registered view name aliases.
*
* @var array
*/
protected $aliases = array();

/**
* All of the registered view names.
*
* @var array
*/
protected $names = array();

/**
* The extension to engine bindings.
*
Expand Down Expand Up @@ -121,8 +107,6 @@ public function __construct(EngineResolver $engines, ViewFinderInterface $finder
*/
public function make($view, $data = array(), $mergeData = array())
{
if (isset($this->aliases[$view])) $view = $this->aliases[$view];

$path = $this->finder->find($view);

$data = array_merge($mergeData, $this->parseData($data));
Expand All @@ -143,42 +127,6 @@ protected function parseData($data)
return $data instanceof Arrayable ? $data->toArray() : $data;
}

/**
* Get the evaluated view contents for a named view.
*
* @param string $view
* @param mixed $data
* @return \Illuminate\View\View
*/
public function of($view, $data = array())
{
return $this->make($this->names[$view], $data);
}

/**
* Register a named view.
*
* @param string $view
* @param string $name
* @return void
*/
public function name($view, $name)
{
$this->names[$name] = $view;
}

/**
* Add an alias for a view.
*
* @param string $view
* @param string $alias
* @return void
*/
public function alias($view, $alias)
{
$this->aliases[$alias] = $view;
}

/**
* Determine if a given view exists.
*
Expand Down Expand Up @@ -614,21 +562,31 @@ public function yieldContent($section, $default = '')
*/
public function flushSections()
{
$this->renderCount = 0;

$this->sections = array();

$this->sectionStack = array();
}

/**
* Flush all of the factory state like sections and stacks.
*
* @return void
*/
public function flushState()
{
$this->renderCount = 0;

$this->flushSections();
}

/**
* Flush all of the section contents if done rendering.
*
* @return void
*/
public function flushSectionsIfDoneRendering()
public function flushStateIfDoneRendering()
{
if ($this->doneRendering()) $this->flushSections();
if ($this->doneRendering()) $this->flushState();
}

/**
Expand Down Expand Up @@ -833,14 +791,4 @@ public function getSections()
return $this->sections;
}

/**
* Get all of the registered named views in environment.
*
* @return array
*/
public function getNames()
{
return $this->names;
}

}
4 changes: 2 additions & 2 deletions src/Illuminate/View/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ public function render(?Closure $callback = null)
// Once we have the contents of the view, we will flush the sections if we are
// done rendering all views so that there is nothing left hanging over when
// another view gets rendered in the future by the application developer.
$this->factory->flushSectionsIfDoneRendering();
$this->factory->flushStateIfDoneRendering();

return $response ?: $contents;
} catch (Exception $e) {
$this->factory->flushSections();
$this->factory->flushState();

throw $e;
}
Expand Down
42 changes: 0 additions & 42 deletions tests/View/ViewFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,32 +78,6 @@ public function testEmptyViewsCanBeReturnedFromRenderEach()
}


public function testAddANamedViews()
{
$factory = $this->getFactory();
$factory->name('bar', 'foo');

$this->assertEquals(['foo' => 'bar'], $factory->getNames());
}


public function testMakeAViewFromNamedView()
{
$factory = $this->getFactory();
$factory->getFinder()->shouldReceive('find')->once()->with('view')->andReturn('path.php');
$factory->getEngineResolver()->shouldReceive('resolve')->once()->with('php')->andReturn($engine = m::mock(
EngineInterface::class
));
$factory->getFinder()->shouldReceive('addExtension')->once()->with('php');
$factory->getDispatcher()->shouldReceive('dispatch');
$factory->addExtension('php', 'php');
$factory->name('view', 'foo');
$view = $factory->of('foo', ['data']);

$this->assertSame($engine, $view->getEngine());
}


public function testRawStringsMayBeReturnedFromRenderEach()
{
$this->assertEquals('foo', $this->getFactory()->renderEach('foo', [], 'item', 'raw|foo'));
Expand Down Expand Up @@ -349,22 +323,6 @@ public function testSectionFlushing()
}


public function testMakeWithAlias()
{
$factory = $this->getFactory();
$factory->alias('real', 'alias');
$factory->getFinder()->shouldReceive('find')->once()->with('real')->andReturn('path.php');
$factory->getEngineResolver()->shouldReceive('resolve')->once()->with('php')->andReturn(m::mock(
EngineInterface::class
));
$factory->getDispatcher()->shouldReceive('dispatch');

$view = $factory->make('alias');

$this->assertEquals('real', $view->getName());
}


public function testExceptionIsThrownForUnknownExtension()
{
$this->expectException('InvalidArgumentException');
Expand Down
8 changes: 4 additions & 4 deletions tests/View/ViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function testRenderProperlyRendersView()
$view->getFactory()->shouldReceive('getShared')->once()->andReturn(['shared' => 'foo']);
$view->getEngine()->shouldReceive('get')->once()->with('path', ['foo' => 'bar', 'shared' => 'foo'])->andReturn('contents');
$view->getFactory()->shouldReceive('decrementRender')->once()->ordered();
$view->getFactory()->shouldReceive('flushSectionsIfDoneRendering')->once();
$view->getFactory()->shouldReceive('flushStateIfDoneRendering')->once();

$me = $this;
$callback = function(View $rendered, $contents) use ($me, $view)
Expand Down Expand Up @@ -86,7 +86,7 @@ public function testSectionsAreNotFlushedWhenNotDoneRendering()
$view->getFactory()->shouldReceive('getShared')->twice()->andReturn(['shared' => 'foo']);
$view->getEngine()->shouldReceive('get')->twice()->with('path', ['foo' => 'bar', 'shared' => 'foo'])->andReturn('contents');
$view->getFactory()->shouldReceive('decrementRender')->twice();
$view->getFactory()->shouldReceive('flushSectionsIfDoneRendering')->twice();
$view->getFactory()->shouldReceive('flushStateIfDoneRendering')->twice();

$this->assertEquals('contents', $view->render());
$this->assertEquals('contents', (string) $view);
Expand Down Expand Up @@ -176,7 +176,7 @@ public function testViewGatherDataWithRenderable()
$view->getFactory()->shouldReceive('getShared')->once()->andReturn(['shared' => 'foo']);
$view->getEngine()->shouldReceive('get')->once()->andReturn('contents');
$view->getFactory()->shouldReceive('decrementRender')->once()->ordered();
$view->getFactory()->shouldReceive('flushSectionsIfDoneRendering')->once();
$view->getFactory()->shouldReceive('flushStateIfDoneRendering')->once();

$view->renderable = m::mock(Renderable::class);
$view->renderable->shouldReceive('render')->once()->andReturn('text');
Expand All @@ -192,7 +192,7 @@ public function testViewRenderSections()
$view->getFactory()->shouldReceive('getShared')->once()->andReturn(['shared' => 'foo']);
$view->getEngine()->shouldReceive('get')->once()->andReturn('contents');
$view->getFactory()->shouldReceive('decrementRender')->once()->ordered();
$view->getFactory()->shouldReceive('flushSectionsIfDoneRendering')->once();
$view->getFactory()->shouldReceive('flushStateIfDoneRendering')->once();

$view->getFactory()->shouldReceive('getSections')->once()->andReturn(['foo','bar']);
$sections = $view->renderSections();
Expand Down
Loading