-
Notifications
You must be signed in to change notification settings - Fork 180
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
Upgrade End Func #177 #178
Conversation
- Updated the end func to multi-purpose and just simply end the output buffering - Updated the start func to utilize the new end func and perform the start section semantics Signed-off-by: RJ Garcia <[email protected]>
@@ -28,43 +28,51 @@ function sectionFunc() { | |||
|
|||
/** Starts the output buffering for a section, update of 0 = replace, 1 = append, 2 = prepend */ | |||
function startFunc($update = START_REPLACE) { | |||
return function(FuncArgs $args) use ($update) { | |||
$section_def = $args->template->getContextItem('_section_def') ?: []; | |||
return startBufferFunc(function(FuncArgs $args) use ($update) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expected 1 space after FUNCTION keyword; 0 found
return function(FuncArgs $args) use ($update) { | ||
$section_def = $args->template->getContextItem('_section_def') ?: []; | ||
return startBufferFunc(function(FuncArgs $args) use ($update) { | ||
return function($contents) use ($update, $args) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expected 1 space after FUNCTION keyword; 0 found
|
||
ob_start(); | ||
$section_def[] = [$args->args[0], $update, ob_get_level()]; | ||
function startBufferFunc(callable $create_callback) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opening brace should be on a new line
ob_start(); | ||
$section_def[] = [$args->args[0], $update, ob_get_level()]; | ||
function startBufferFunc(callable $create_callback) { | ||
return function(FuncArgs $args) use ($create_callback) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expected 1 space after FUNCTION keyword; 0 found
@@ -1,45 +1,132 @@ | |||
<?php | |||
|
|||
use League\Plates\{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There must be one USE keyword per declaration
Exception\FuncException | ||
}; | ||
|
||
use function Eloquent\Phony\{on, mock}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- There must be one USE keyword per declaration
- Closing brace must be on a line by itself
}; | ||
|
||
use function Eloquent\Phony\{on, mock}; | ||
use function League\Plates\{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There must be one USE keyword per declaration
Template\getSections, | ||
Util\stack | ||
}; | ||
use function League\Plates\RenderContext\{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There must be one USE keyword per declaration
startBufferFunc, | ||
endFunc | ||
}; | ||
use const League\Plates\RenderContext\{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There must be one USE keyword per declaration
}); | ||
xdescribe('platesFunc', function() { | ||
it('creates the default plates func stack'); | ||
describe('Funcs', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expected 1 space after FUNCTION keyword; 0 found
xdescribe('platesFunc', function() { | ||
it('creates the default plates func stack'); | ||
describe('Funcs', function() { | ||
beforeEach(function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expected 1 space after FUNCTION keyword; 0 found
$this->template = new Template(''); | ||
$this->args = new FuncArgs($this->render, $this->template, '', []); | ||
}); | ||
describe('layoutFunc', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expected 1 space after FUNCTION keyword; 0 found
describe('layoutFunc', function() { | ||
it('forks a template and sets the layout'); | ||
}); | ||
xdescribe('sectionFunc', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expected 1 space after FUNCTION keyword; 0 found
xdescribe('sectionFunc', function() { | ||
it('gets a section from the template sections'); | ||
}); | ||
describe('startFunc', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expected 1 space after FUNCTION keyword; 0 found
it('gets a section from the template sections'); | ||
}); | ||
describe('startFunc', function() { | ||
$create_test = function($update_text, $update, $expected) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expected 1 space after FUNCTION keyword; 0 found
}); | ||
describe('startFunc', function() { | ||
$create_test = function($update_text, $update, $expected) { | ||
it("can start buffering and {$update_text} the section", function() use ($update, $expected) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expected 1 space after FUNCTION keyword; 0 found
$create_test('append', START_APPEND, 'bazbar'); | ||
$create_test('prepend', START_PREPEND, 'barbaz'); | ||
}); | ||
describe('startBufferFunc', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expected 1 space after FUNCTION keyword; 0 found
$create_test('prepend', START_PREPEND, 'barbaz'); | ||
}); | ||
describe('startBufferFunc', function() { | ||
it('starts the output buffering and appends the buffer_stack', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expected 1 space after FUNCTION keyword; 0 found
describe('startBufferFunc', function() { | ||
it('starts the output buffering and appends the buffer_stack', function() { | ||
$args = $this->args; | ||
$callback = function() {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Expected 1 space after FUNCTION keyword; 0 found
- Closing brace must be on a line by itself
$callback = function() {}; | ||
|
||
$cur_level = ob_get_level(); | ||
startBufferFunc(function($passed_args) use ($args, $callback) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expected 1 space after FUNCTION keyword; 0 found
ob_end_clean(); | ||
}); | ||
}); | ||
describe('endFunc', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expected 1 space after FUNCTION keyword; 0 found
}); | ||
}); | ||
describe('endFunc', function() { | ||
it('throws an exception if no buffer_stack have been defined', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expected 1 space after FUNCTION keyword; 0 found
describe('endFunc', function() { | ||
it('throws an exception if no buffer_stack have been defined', function() { | ||
$func = endFunc(); | ||
expect(function() use ($func) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expected 1 space after FUNCTION keyword; 0 found
$func($this->args); | ||
})->throw(FuncException::class, 'Cannot end a section definition because no section has been started.'); | ||
}); | ||
it('throws an exception if the output buffering level does not match the section def', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expected 1 space after FUNCTION keyword; 0 found
}); | ||
it('throws an exception if the output buffering level does not match the section def', function() { | ||
|
||
startBufferFunc(function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expected 1 space after FUNCTION keyword; 0 found
it('throws an exception if the output buffering level does not match the section def', function() { | ||
|
||
startBufferFunc(function() { | ||
return function() {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Expected 1 space after FUNCTION keyword; 0 found
- Closing brace must be on a line by itself
ob_end_clean(); | ||
|
||
$func = endFunc(); | ||
expect(function() use ($func) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expected 1 space after FUNCTION keyword; 0 found
$func($this->args); | ||
})->throw(FuncException::class, 'Output buffering level does not match when section was started.'); | ||
}); | ||
it('cleans the buffer and calls the callback', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expected 1 space after FUNCTION keyword; 0 found
}); | ||
it('cleans the buffer and calls the callback', function() { | ||
$was_called = false; | ||
startBufferFunc(function() use (&$was_called) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expected 1 space after FUNCTION keyword; 0 found
it('cleans the buffer and calls the callback', function() { | ||
$was_called = false; | ||
startBufferFunc(function() use (&$was_called) { | ||
return function() use (&$was_called) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expected 1 space after FUNCTION keyword; 0 found
expect($this->args->template->context['buffer_stack'])->length(0); | ||
}); | ||
}); | ||
xdescribe('insertFunc', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expected 1 space after FUNCTION keyword; 0 found
xdescribe('insertFunc', function() { | ||
it('forks a template and echos the rendered contents'); | ||
}); | ||
xdescribe('escapeFunc', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expected 1 space after FUNCTION keyword; 0 found
xdescribe('escapeFunc', function() { | ||
it('it escapes the content with htmlspecialchars'); | ||
}); | ||
xdescribe('assertArgsFunc', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expected 1 space after FUNCTION keyword; 0 found
it('passes through if there are enough args'); | ||
it('appends null to the args to make up the amount of required and defaulted args'); | ||
}); | ||
xdescribe('aliasNameFunc', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expected 1 space after FUNCTION keyword; 0 found
it('passes through if no aliases are matched'); | ||
it('recursively aliases func names'); | ||
}); | ||
xdescribe('splitByNameFunc', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expected 1 space after FUNCTION keyword; 0 found
it('allows stacks to be invoked by func name'); | ||
it('passes through if no stack was registered per func name'); | ||
}); | ||
xdescribe('platesFunc', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expected 1 space after FUNCTION keyword; 0 found
just simply end the output buffering
new end func and perform the start section
semantics
Signed-off-by: RJ Garcia [email protected]