Whilst small files can be uploaded to forum posts, if you have a custom theme or module to contribute please add it on the "Add-ons" page.

TOPIC: Module authors: new requests/responses

Module authors: new requests/responses 2 months 6 days ago #1

  • fisharebest
  • fisharebest's Avatar
  • Offline
  • Administrator
  • Posts: 11102
I have just submitted a code change that is likely to affect many custom modules.

I have replaced the Symfony HttpFoundation requests and responses with PSR-7 requests and responses.

By using PSR-7, we can be compatible with almost every other major application and framework.
It also means that we will also be able to use a routing package to give us "pretty URLs".

There should be plenty of examples in the code. Here are the main changes.

1) You should type-hint ServerRequestInterface and ResponseInterface - instead of the Symfony Request/Response/RedirectResponse classes.

2) There are two helper functions to create responses.
Use these instead of "new Response()" and "new RedirectResponse()".
response($content, $status = 200, $headers = [])
redirect($url, $status = 302);

3) Symony merged the GET and POST parameters. e.g.
$foo = $request->get('foo'); // could be from GET or POST

With PSR-7, you need to request GET and POST variables separately.
$foo = $request->getQueryParams()['foo']; // GET
$bar = $request->getParsedBody()['bar']; // POST

If the parameter is optional, you can specify defaults like this:
$generations = $request->getQueryParams()['generations'] ?? 4;

NOTE: there is a temporary compatibility function in place. $request->get() will continue to work for a few more weeks until I migrate the rest of the code to the new syntax.

If you have any questions or problems, just ask. I am happy to create more example code to demonstrate how the various functions work.
Greg Roach - This email address is being protected from spambots. You need JavaScript enabled to view it. - fisharebest.webtrees.net
The administrator has disabled public write access.

Module authors: new requests/responses 2 months 4 days ago #2

  • xmlf
  • xmlf's Avatar
  • Offline
  • New
  • Posts: 37
I am very much looking forward to seeing pseudo-static URLs as early as possible, which is great.
The administrator has disabled public write access.

Module authors: new requests/responses 1 month 4 weeks ago #3

  • UksusoFF
  • UksusoFF's Avatar
  • Offline
  • Junior
  • Posts: 116
This changes for 2.0 version?
The administrator has disabled public write access.

Module authors: new requests/responses 1 month 4 weeks ago #4

  • fisharebest
  • fisharebest's Avatar
  • Offline
  • Administrator
  • Posts: 11102
> This changes for 2.0 version?

This = PSR-7 requests/responses? Yes.

This = Pretty URLs? Maybe.
Greg Roach - This email address is being protected from spambots. You need JavaScript enabled to view it. - fisharebest.webtrees.net
The administrator has disabled public write access.

Module authors: new requests/responses 1 month 4 weeks ago #5

  • xmlf
  • xmlf's Avatar
  • Offline
  • New
  • Posts: 37
I am very much looking forward to implementing pseudo-static functions as soon as possible, whether using CDN or search engines Is very helpful.
Thank you very much!
Last Edit: 1 month 4 weeks ago by xmlf.
The administrator has disabled public write access.
Powered by Kunena Forum