-
Notifications
You must be signed in to change notification settings - Fork 12
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
Feature/rest support callable #3
Conversation
DarkSide666
commented
Jun 5, 2018
- add support of callable in rest() method
- fix test engine
Codecov Report
@@ Coverage Diff @@
## develop #3 +/- ##
=============================================
- Coverage 47.87% 43.22% -4.66%
- Complexity 40 51 +11
=============================================
Files 1 1
Lines 94 118 +24
=============================================
+ Hits 45 51 +6
- Misses 49 67 +18
Continue to review full report at Codecov.
|
$this->get($pattern, function () use ($model) { | ||
$args = func_get_args(); | ||
|
||
if (is_callable($model)) { |
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.
wouldn't that be handled by $this->get() ? perhaps it should be?
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.
by get() no, but probably could be done somehow in match() method.
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.
yeah, that would be great.
$args = func_get_args(); | ||
$id = array_pop($args); // pop last element of args array, it's :id | ||
|
||
if (is_callable($model)) { |
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.
same as above.
$this->get($pattern.'/:id', function ($id) use ($model) { | ||
// GET :id - one record | ||
$this->get($pattern.'/:id', function () use ($model) { | ||
$args = func_get_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.
use ...$args , it's php 7.2 :D
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.
let's not drop php 7.1 support for now
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.
ok.
// DELETE :id - delete one record | ||
$this->delete($pattern.'/:id', function () use ($model) { | ||
$args = func_get_args(); | ||
$id = array_pop($args); // pop last element of args array, it's :id |
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.
lets use $args['id'] , because order my be messed up.
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.
you'd have to amend the callback function format.
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.
order will not be messed up because this :id is last argument added to $vars array (in match() method). Name of arguments in pattern doesn't matter - only order of them matters.
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.
i still prefer if it's a named array, i think it's better long-term.