Open utterances-bot opened 5 years ago
I’d love to see some simple pseudo code implementing even a hello world. The article seems nicely written.
@alturic -- I'm not sure I follow. A simple hello world could be as simple as returning a string of 'Hello World!
' from an action. Because the responders handle converting it to a response, the magic is mostly in having a responder set up that will match a string and create a response from it. The hiraeth-php/routing
package has a handful of responders (some complete, some not) that handle basic data types like this, including a one to convert arrays to JSON, for example, see:
Ha, 100% correct on the string being returned in the action. I did mean an example of the most basic ADR pseudo code. I suppose even then there might not be a point as without a container and all it wouldn’t really implement DI or anything like that.
I did appreciate the article, and suppose basic “working examples” would be silly as people who know how to implement it just could.
I always liked the simplicity of ADR but never really could wire together all of the basic niceties (reeuest,response,routing,DB et al) to make it work without just using a full-blown framework.
@alturic -- Well, the framework is operational. Not all features are complete, but you're welcome to test what is complete and documented just click the "Documentation" link at the top of the site and start from the beginning. Unfortunately, I don't have the Responders page done yet on the docs... but the StringResponder
and JSONResponder
are registered by default, and most pages up to Actions have content.
As for overall pseudocode, not sure code is the best, but here's what the basic framework lifecycle looks likes:
index.php
and passed to registered PSR-15 Request Handler Interface -- for hiraeth/bootstrap
I use Harmony.match()
, then converts the target to a callback using __invoke()
.match()
, then converts the result to a response using __invoke()
.I should add, although adapters were originally written to handle particular routers' possible targets... in theory it could examine the target for patterns. Nothing would, for example, prevent you from writing an adapter that allowed you to route to a URL and proxy the request / response from that URL. Maybe I'll do a blog article on that some time.
Abstracted Routing with Action Domain Responder - Hiraeth PHP Nano Framework
https://hiraeth.dev/blog/1-abstracted-routing-with-adr