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

Feature/rest support callable #3

Merged
merged 6 commits into from
Jun 5, 2018
Merged

Conversation

DarkSide666
Copy link
Member

  • add support of callable in rest() method
  • fix test engine

@DarkSide666 DarkSide666 requested a review from romaninsh June 5, 2018 11:48
@codecov
Copy link

codecov bot commented Jun 5, 2018

Codecov Report

Merging #3 into develop will decrease coverage by 4.65%.
The diff coverage is 38.46%.

Impacted file tree graph

@@              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
Impacted Files Coverage Δ Complexity Δ
src/Api.php 43.22% <38.46%> (-4.66%) 51 <27> (+11)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 56dab00...3cab3a1. Read the comment docs.

$this->get($pattern, function () use ($model) {
$args = func_get_args();

if (is_callable($model)) {
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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)) {
Copy link
Member

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();
Copy link
Member

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

Copy link
Member Author

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

Copy link
Member

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
Copy link
Member

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.

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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.

@DarkSide666 DarkSide666 merged commit 227f7b1 into develop Jun 5, 2018
@DarkSide666 DarkSide666 deleted the feature/rest-support-callable branch June 5, 2018 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants