Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.4] Add getSection to view factory #19213

Merged
merged 5 commits into from
May 15, 2017
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
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