PHP code example of meraki / route

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

    

meraki / route example snippets



Meraki\Route\Collection;
use Meraki\Route\Mapper;
use Meraki\Route\Matcher;
use Meraki\Route\MatchResult;

// any psr7 and psr11 compliant library will work
use Laminas\Diactoros\ServerRequestFactory;

$map = new Mapper(new Collection());

$map->get('/', new ShowHomepage());
$map->get('/contact', new ShowContactForm());
$map->post('/contact', new SendContactForm());

$map->get('/users/:id', new DisplayEditUserForm())
	->name('display.user.profile')
	->constrain(':id', Constraint::digit());

$map->get('/users/:id');

$matcher = new Matcher($map->getRules());
$result = $match->match(ServerRequestFactory::fromGlobals());

if ($result->isSuccessful()) {
	// handle a successful match
} else {
	// handle a failed match 404,405,406,etc.
}