Theory is when you know everything but nothing works.
Practice is when everything works but no one knows why.
Here we combine theory and practice: nothing works and no one knows why.Unknown
Library wraps sunrise/http-router library for now. Plan is to create a context aware router that will be able to handle both REST and AJAX requests. This router will then be globally usable in the DI system which we're planning to implement.
By default - library does nothing. It needs at least one controller for it to initialize.
When you register a controller (or multiple controllers) - the following flow is executed:
XWP\Ajax_Server::instance()function is called which will register the initialiation onplugins_loaded(priority:PHP_INT_MAX)- Class will check for existence of
xwp_ajax_slugoption and set it towp-ajaxif it doesn't exist (this will flush the rewrite rules) - Class will add the
xwp_ajaxquery var to the list of query vars. - Singleton will create and instance of
Request_Dispatcheronparse_requestaction if the query var is present.
- Defines the standard PHP constants (
DOING_AJAX,WP_ADMIN) - Initializes router
- On
parse_request:10action dispatcher will initialize the controller classes and their decorators - Controller decorator wraps the controller and forwards the response to a
Response_Handlerwhich creates aPSR-7response object - Response object is then sent to the client
We're still working on the documentation. But you can check the NestJS documentation for the basics. We're trying to mimic the way NestJS handles things.