1. Go to this page and download the library: Download pinkcrab/perique-route library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
class Some_Route extends Route_Controller {
// @al, access to constructor, so allows for full DI.
protected $some_service;
protected function __construct(Service $service){
$this->some_service = $service;
}
// @ $factory->post('/users', [$this->some_service, 'new_user' ]),
// Create your groups using the group builder.
$factory->group_builder('/users/{id}', function( Route_Group $group) : Route_Group {
// Define the GET method.
$group->get([$this->some_service, 'show_user'])
->argument( // Define the argument proprties as per WP API
Integer_Type::on('id')
->validate('is_numeric')
->sanitization('absint')
->
$route = new Route('POST', 'route/path');
$route->namespace('the-thing/v1');
$route->callback(function( WP_REST_Request $request ) {
// Do the things
});
$manager = new Route_Manager(
new WP_Rest_Registrar(),
new Hook_Loader()
);
// Add routes and groups
$manager->from_route(new Route(...));
$manager->from_group(new Route_Group(...));
// Dispatch
$manager->execute();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.