Skip to content

Commit

Permalink
[5.4] Add getSection to view factory (#19213)
Browse files Browse the repository at this point in the history
* Add getSection to view factory

* support php 5.6

* support php 5.6

* styleci changes

* Update ManagesLayouts.php
  • Loading branch information
VinceG authored and taylorotwell committed May 15, 2017
1 parent d394341 commit 7d19bfc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Illuminate/View/Concerns/ManagesLayouts.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,18 @@ public function hasSection($name)
return array_key_exists($name, $this->sections);
}

/**
* Get the contents of a section.
*
* @param string $name
* @param string $default
* @return mixed
*/
public function getSection($name, $default = null)
{
return isset($this->getSections()[$name]) ? $this->getSections()[$name] : $default;
}

/**
* Get the entire array of sections.
*
Expand Down
12 changes: 12 additions & 0 deletions tests/View/ViewFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,18 @@ public function testHasSection()
$this->assertFalse($factory->hasSection('bar'));
}

public function testGetSection()
{
$factory = $this->getFactory();
$factory->startSection('foo');
echo 'hi';
$factory->stopSection();

$this->assertEquals('hi', $factory->getSection('foo'));
$this->assertNull($factory->getSection('bar'));
$this->assertEquals('default', $factory->getSection('bar', 'default'));
}

public function testMakeWithSlashAndDot()
{
$factory = $this->getFactory();
Expand Down

0 comments on commit 7d19bfc

Please sign in to comment.