PHP code example of kuria / router

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

    

kuria / router example snippets



   

   use Kuria\Router\Context;
   use Kuria\Router\Result\Match;
   use Kuria\Router\Result\MethodNotAllowed;
   use Kuria\Router\Route\RouteCollector;
   use Kuria\Router\Router


   

   use Kuria\RequestInfo\RequestInfo;
   use Kuria\Router\Context;
   use Kuria\Router\Result\Match;
   use Kuria\Router\Result\MethodNotAllowed;
   use Kuria\Router\Route\RouteCollector;
   use Kuria\Router\Router


   

   use Kuria\Router\Route\RouteCollector;
   use Kuria\Router\Router


   

   use Kuria\Router\Route\RouteCollector;
   use Kuria\Router\Router


   

   use Kuria\Router\Route\RouteCollector;
   use Kuria\Router\Router


   

   $router->defineRoutes(function (RouteCollector $c) {
       // $c->add() returns a RouteBuilder
       $c->add('user_profile_page')
           ->methods(['GET', 'POST'])
           ->scheme('https')
           ->host('{username}.example.com')
           ->port(8080)
           ->path('/{page}')
           ->defaults(['page' => 'home'])
           ->


   

   use Kuria\Cache\Cache;
   use Kuria\Cache\Driver\Filesystem\FilesystemDriver;
   use Kuria\Router\Route\RouteCollector;
   use Kuria\Router\Router


   

   use Kuria\Router\Result\Match;
   use Kuria\Router\Router


   

   use Kuria\Router\Result\MethodNotAllowed


   

   use Kuria\Router\Result\NotFound


   

   var_dump(
       $router->generate('user_register')->build(),
       $router->generate('user_profile', ['username' => 'bob', 'extra' => 'example'])->build()
   )


   

   var_dump(
       $router->generate('index')->buildAbsolute(),
       $router->generate('page', ['name' => 'contact'])->buildAbsolute()
   )


   

   use Kuria\Router\Context