PHP code example of devop-core / router

1. Go to this page and download the library: Download devop-core/router 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/ */

    

devop-core / router example snippets

 php

= new DevOp\Core\Router\Router();
$router->get('page1', '/page1/{name:\w+}/{id}', function($request, $response){
    $response->getBody()->write('Hello world!');
    return $response;
});

$uri = (new DevOp\Core\Http\UriFactory())->createUri('/page1/devop/1');
$request = (new \DevOp\Core\Http\ServerRequestFactory())->createServerRequest('GET', $uri);

try {
    /* @var $route \DevOp\Core\Router\Route */
    $route = $router->dispatch($request);
} catch (\DevOp\Core\Router\Exceptions\RouteNotFoundException $ex) {
    var_dump($ex);
} catch (DevOp\Core\Router\Exceptions\RouteIsNotCallableException $ex) {
    var_dump($ex);
}

var_dump($route);