PHP code example of devbr / router

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

    

devbr / router example snippets


Composer 

namespace Config\Devbr;

class Router
{
    function __construct($router)
    {
        $router->respond('get', '/', 'Site\Front::page');
    }
}

/var/www/site/.php/

--- pode variar conforme a configuração do servidor.

/var/www/site/.php/Site/Front/Page.php

$page = new Site\Front\Page;

//Logo abaixo do "namespace":
use Site\Front\Page;
 ....

//Dentro de um método da classe...
$page = new Page;



//Carregando o autoloader do Composer
uter)->run();



//Carregando o autoloader do Composer
w Devbr\Router(false))->run();

//For example, only --¬
echo '<b>Controller:</b> '.$router->getController();

//Or ...
echo '<pre>'.print_r($router, true).'</pre>';

namespace Config\Devbr;

class Router
{
    function __construct($router)
    {
        $router->setNamespaceCliPrefix('Cli');
        $router-> ... //demais configurações
json
...
    "autoload": {
        "Config\\": {"": ".php/Config/"}
    }
...
json
...
    "autoload": {
        "psr-4": {"": ".php/"}
     }
...    
shell
php index.php Main
shell
/var/www/.php/Cli/Tests.php
 php index.php Tests::action par1 par2 
 php index.php Tests