1. Go to this page and download the library: Download wpmvc/routing 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/ */
wpmvc / routing example snippets
/**
* Define an object or a value in the container.
*
* @param string $name Entry name
* @param mixed $value Value, define objects
*/
public function set(string $name, $value) {}
/**
* Returns an entry of the container by its name.
*
* @template T
* @param string|class-string<T> $name Entry name or a class name.
*
* @return mixed|T
*/
public function get($name) {}
/**
* Call the given function using the given parameters.
*
* Missing parameters will be resolved from the container.
*
* @param callable $callable Function to call.
*
* @return mixed Result of the function.
*/
public function call($callable) {}
namespace MyPlugin\Providers;
use MyPlugin\Container;
use WpMVC\Routing\Providers\RouteServiceProvider as WpMVCRouteServiceProvider;
class RouteServiceProvider extends WpMVCRouteServiceProvider {
public function boot() {
/**
* Set Di Container
*/
parent::$container = new Container;
/**
* OR you use PHP-Container
* Uses https://php-di.org/doc/getting-started.html
*/
// parent::$container = new DI\Container();
/**
* Set
add_action('init', function() {
$route_service_provider = new \MyPlugin\Providers\RouteServiceProvider;
$route_service_provider->boot();
});
use WpMVC\Routing\Route;
use WpMVC\Routing\Response;
use WP_REST_Request;
defined('ABSPATH') || exit;
Route::get('user', function(WP_REST_Request $wp_rest_request) {
return Response::send(['ID' => 1, 'name' => 'john']);
});