PHP code example of weew / router-entities-resolver

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

    

weew / router-entities-resolver example snippets


$router = new Router(new Container());
$resolver = new EntitiesResolver($router);

$resolver
    ->resolve('user', UserRepository::class)
    ->resolve('role', RoleRepository::class);

$router->get('api/v1/users/{user}', function(User $user) {
    // entitiy will be injected instead of a user id
});

// or

$route = $router->match(HttpRequestMethod::GET, new Url('api/v1/users/1'));
$user = $route->getParameter('user');