1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?php namespace Laravel;
- class Section {
-
- public static $sections = array();
-
- protected static $last = array();
-
- public static function start($section, $content = '')
- {
- if ($content === '') ob_start() and static::$last[] = $section;
- static::append($section, $content);
- }
-
- public static function inject($section, $content)
- {
- static::start($section, $content);
- }
-
- public static function stop()
- {
- static::append(array_pop(static::$last), ob_get_clean());
- }
-
- protected static function append($section, $content)
- {
- if (isset(static::$sections[$section]))
- {
- $content = static::$sections[$section].PHP_EOL.$content;
- }
- static::$sections[$section] = $content;
- }
-
- public static function yield($section)
- {
- return (isset(static::$sections[$section])) ? static::$sections[$section] : '';
- }
- }
|