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

[NFR] Micro: Response handler #12452

Closed
wants to merge 1 commit into
base: 3.1.x
from

Conversation

Projects
6 participants
@Doehl
Copy link
Contributor

Doehl commented Dec 3, 2016

  • Type: new feature

In raising this pull request, I confirm the following (please check boxes):

  • I have read and understood the Contributing Guidelines?
  • I have checked that another pull request for this purpose does not exist.
  • I wrote some tests for this PR.

Small description of change:

What:
Adds the possibility to create a response handler, that will handle the
response instead of the default hard coded micro handler.

Why:
Before the reponse format had to be coded into every route.
Now is it possible to create a custom rosponse handler, that will format
the data in custom created function.

Changes to phalcon/mvc/micro.zep

  • Added protected class variable _responseHandler
    The custom response handler

  • Added public function response
    Appends a response handler

  • Change to public function handle
    Check if a response handler has been appended.
    If yes, run the response handler.
    If no, run the same code as before this PR.

Unit test

Adds a response handler, and check if it has been called.

How to use

$app->setResponseHandler(function () use ($app) {

    // Gets the client response, that has been returned from executed route
    $return = $app->getReturnedValue();

    // Put controller return array item data
    $return = array('data' => $return);

    // Set reponse Content-Type to json
    header('Content-Type: application/json');

    // Print json response string
    echo json_encode($return);
});
@Jurigag

This comment has been minimized.

Copy link
Member

Jurigag commented Dec 3, 2016

Squash commits please.

@sergeyklay sergeyklay added this to the 3.1.0 milestone Dec 3, 2016

@sergeyklay sergeyklay changed the title [3.1.x] feat(Micro): Response handler [NFR] Micro: Response handler Dec 3, 2016

@Doehl

This comment has been minimized.

Copy link
Contributor Author

Doehl commented Dec 3, 2016

The commits has been squashed.

@sergeyklay

This comment has been minimized.

Copy link
Member

sergeyklay commented Dec 11, 2016

@Doehl Could you please rebase

@Doehl

This comment has been minimized.

Copy link
Contributor Author

Doehl commented Dec 12, 2016

Rebase done

* @param callable handler
* @return \Phalcon\Mvc\Micro
*/
public function response(handler) -> <Micro>

This comment has been minimized.

@sergeyklay

sergeyklay Dec 12, 2016

Member

I would like that this method was named setResponseHandler

This comment has been minimized.

@Doehl

Doehl Dec 12, 2016

Author Contributor

I did try to keep it the same as "after", "before" and "finish" functions.
But if that is how we should name function, I will of course change it.

* Appends a custom 'reponse' handler to be called insted of the default reponse handler
*
* @param callable handler
* @return \Phalcon\Mvc\Micro

This comment has been minimized.

@sergeyklay

sergeyklay Dec 12, 2016

Member

the @return not needed here

This comment has been minimized.

@Doehl

Doehl Dec 12, 2016

Author Contributor

Remove it I will.

throw new Exception("Response handler is not callable or is not defined");
}

call_user_func(this->_responseHandler);

This comment has been minimized.

@sergeyklay

sergeyklay Dec 12, 2016

Member

How about let returnedValue = call_user_func(this->_responseHandler);

@Doehl

This comment has been minimized.

Copy link
Contributor Author

Doehl commented Dec 12, 2016

All the changes has been made.

feat(Micro): Response handler
What:
Adds the possibility to create a response handler, that will handle the
response instead of the default hard coded micro handler.

Why:
Before the reponse format had to be coded into every route.
Now is it possible to create a custom rosponse handler, that will format
the data in custom created function.

unit(Micro): Test micro response handler

What:
Test if the custom micro response handler, is being called.

changelog(Micro): Response handler

Add micro response handler feature to changelog.

@sergeyklay sergeyklay modified the milestones: 3.1.0, 3.2.0 Mar 2, 2017

@sergeyklay sergeyklay force-pushed the phalcon:3.1.x branch from 928502b to b0a7493 Mar 9, 2017

@sergeyklay sergeyklay force-pushed the phalcon:3.1.x branch from f115731 to c7de98d Mar 21, 2017

@sergeyklay sergeyklay force-pushed the phalcon:3.1.x branch 11 times, most recently from de31f9a to 74effe9 Apr 2, 2017

@sergeyklay sergeyklay force-pushed the phalcon:3.1.x branch 3 times, most recently from 4d3c73f to 6ef079c Apr 5, 2017

@sjinks sjinks closed this Apr 26, 2017

@sjinks sjinks reopened this Apr 26, 2017

@sergeyklay

This comment has been minimized.

Copy link
Member

sergeyklay commented Apr 26, 2017

@sergeyklay sergeyklay modified the milestones: 3.2.0, 4.0.0 Jun 18, 2017

@niden

This comment has been minimized.

Copy link
Member

niden commented Oct 17, 2018

@Doehl Would you be so kind as to rebase this to the 3.4.x branch and also issue one more for the 4.0.x branch?

Thanks for the work!

@Doehl

This comment has been minimized.

Copy link
Contributor Author

Doehl commented Nov 17, 2018

Hi niden,

Sorry for the late response.
I do not use the phalcon framework at the moment, and does no longer have access to the setup on where I had the phalcon environment running. Because of change on job.

I would love to help, but do no longer have access to an environment where I can easily help with this PR any longer.

@niden

This comment has been minimized.

Copy link
Member

niden commented Nov 23, 2018

@Doehl Not a problem. I can just "move" your work to a different branch so that you can get credit for this work :)

Thank you again and whenever you have the time we would welcome your contributions.

@niden niden added this to In progress in 4.0 Release Nov 29, 2018

CameronHall added a commit to CameronHall/cphalcon that referenced this pull request Dec 4, 2018

[NF] Micro: Response handler phalcon#12452
What:
Adds the possibility to create a response handler, that will handle the
response instead of the default hard coded micro handler.

Why:
Before the reponse format had to be coded into every route.
Now is it possible to create a custom rosponse handler, that will format
the data in custom created function.

unit(Micro): Test micro response handler

What:
Test if the custom micro response handler, is being called.

changelog(Micro): Response handler

Add micro response handler feature to changelog.

CameronHall added a commit to CameronHall/cphalcon that referenced this pull request Dec 4, 2018

[NF] Micro: Response handler phalcon#12452
What:
Adds the possibility to create a response handler, that will handle the
response instead of the default hard coded micro handler.

Why:
Before the reponse format had to be coded into every route.
Now is it possible to create a custom rosponse handler, that will format
the data in custom created function.

unit(Micro): Test micro response handler

What:
Test if the custom micro response handler, is being called.

changelog(Micro): Response handler

Add micro response handler feature to changelog.

@CameronHall CameronHall referenced this pull request Dec 4, 2018

Merged

[NF] Micro: Response handler PR #12452 #13629

3 of 3 tasks complete

CameronHall added a commit to CameronHall/cphalcon that referenced this pull request Dec 4, 2018

[NF] Micro: Response handler phalcon#12452
What:
Adds the possibility to create a response handler, that will handle the
response instead of the default hard coded micro handler.

Why:
Before the reponse format had to be coded into every route.
Now is it possible to create a custom rosponse handler, that will format
the data in custom created function.

unit(Micro): Test micro response handler

What:
Test if the custom micro response handler, is being called.

changelog(Micro): Response handler

Add micro response handler feature to changelog.

CameronHall added a commit to CameronHall/cphalcon that referenced this pull request Dec 7, 2018

[NF] Micro: Response handler phalcon#12452
Co-authored-by: Cameron Hall <me@chall.id.au>

What:
Adds the possibility to create a response handler, that will handle the
response instead of the default hard coded micro handler.

Why:
Before the reponse format had to be coded into every route.
Now is it possible to create a custom rosponse handler, that will format
the data in custom created function.

unit(Micro): Test micro response handler

What:
Test if the custom micro response handler, is being called.

changelog(Micro): Response handler

Add micro response handler feature to changelog.

CameronHall added a commit to CameronHall/cphalcon that referenced this pull request Dec 8, 2018

[NF] Micro: Response handler phalcon#12452
Co-authored-by: Cameron Hall <me@chall.id.au>

What:
Adds the possibility to create a response handler, that will handle the
response instead of the default hard coded micro handler.

Why:
Before the reponse format had to be coded into every route.
Now is it possible to create a custom rosponse handler, that will format
the data in custom created function.

unit(Micro): Test micro response handler

What:
Test if the custom micro response handler, is being called.

changelog(Micro): Response handler

Add micro response handler feature to changelog.
@niden

This comment has been minimized.

Copy link
Member

niden commented Dec 8, 2018

This has been resolved with a new PR #13629

Thank you @Doehl

@niden niden closed this Dec 8, 2018

niden added a commit that referenced this pull request Dec 8, 2018

[NF] Micro: Response handler #12452
Co-authored-by: Cameron Hall <me@chall.id.au>

What:
Adds the possibility to create a response handler, that will handle the
response instead of the default hard coded micro handler.

Why:
Before the reponse format had to be coded into every route.
Now is it possible to create a custom rosponse handler, that will format
the data in custom created function.

unit(Micro): Test micro response handler

What:
Test if the custom micro response handler, is being called.

changelog(Micro): Response handler

Add micro response handler feature to changelog.

@niden niden moved this from In progress to Done in 4.0 Release Dec 8, 2018

niden added a commit to niden/cphalcon that referenced this pull request Dec 8, 2018

[4.0.x] - Merge remote-tracking branch 'upstream/4.0.x' into 4.0.x
* upstream/4.0.x:
  [NF] Micro: Response handler phalcon#12452
  Added Codecov token [skip appveyor]

niden added a commit to niden/cphalcon that referenced this pull request Dec 8, 2018

[phalcon#12098] - Merge branch '4.0.x' into T12098-remove-deprecated-…
…code

* 4.0.x:
  [4.0.x] - Removed obsolete tests; Added docblocks
  [NF] Micro: Response handler phalcon#12452
  Added Codecov token [skip appveyor]

CameronHall added a commit to CameronHall/cphalcon that referenced this pull request Dec 8, 2018

[NF] Micro: Response handler phalcon#12452
Co-authored-by: Cameron Hall <me@chall.id.au>

What:
Adds the possibility to create a response handler, that will handle the
response instead of the default hard coded micro handler.

Why:
Before the reponse format had to be coded into every route.
Now is it possible to create a custom rosponse handler, that will format
the data in custom created function.

unit(Micro): Test micro response handler

What:
Test if the custom micro response handler, is being called.

changelog(Micro): Response handler

Add micro response handler feature to changelog.

niden added a commit that referenced this pull request Dec 9, 2018

Merge branch 'alexbusu-scope-sql-col-aliases' into 4.0.x
* alexbusu-scope-sql-col-aliases: (48 commits)
  CLI parameters now work like MVC parameters.
  Fixed Security Tests segmentation fault
  Added retainer for current session token in order to be able to validate fields after regenerating the token. Added string casting to userToken.
  Update di.zep
  Scope SQL Column Aliases (on nesting level)
  [NF] Micro: Response handler #12452
  Added Codecov token [skip appveyor]
  [#13438] - Added docblock
  [#13438] - Fixed tabs
  [#13438] - Updated the CHANGELOG
  [#13438] - More corrections to the interface
  [#13438] - Corrected interface
  [#13438] - Work on the Factory; Wrote more tests for it
  [#13438] - Correction to the syslog adapter; Added more tests
  [#13438] - Renamed blackhole adapter to noop. Added tests
  [#13438] - PHPCS
  [#13438] - Minor corrections to the adapter; Added more tests
  [#13438] - Work on the syslog adapter
  [#13438] - Renamed the base folder for the tests
  [#13438] - Removed logger file adapter; consolidated it in stream. Adjusted tests; Added syslog tests
  ...
@gspgsp

This comment has been minimized.

Copy link

gspgsp commented Dec 28, 2018

2018/12/28 10:37:48 [error] 14931#0: *18 FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught BadMethodCallException: Wrong number of parameters in /www/wechat-api/app/bootstrap/bootstrap.php:13

my bootstrap.php code is:

handle(); #this is line 13 , i don't konw why ,befor in php5.6 phalcon version 3, there is no problem ,today i use php7.2 and the phalcon version is also update to 4.0
@niden

This comment has been minimized.

Copy link
Member

niden commented Dec 28, 2018

@gspgsp Please have a look at this blog post for a list of things that changed:

https://blog.phalconphp.com/post/upgrading-to-v4-alpha-1

Something you are using in your bootstrap file has changed and now you need to adjust your parameters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment