PHP code example of icanboogie / bind-routing

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

    

icanboogie / bind-routing example snippets




namespace App\Presentation\HTTP;

use ICanBoogie\HTTP\Response;
use ICanBoogie\Routing\Attribute\Get;
use ICanBoogie\Routing\Attribute\Post;
use ICanBoogie\Routing\Attribute\Prefix;

#[Prefix(route: '/skills')]
final class SkillController
{
    // This will create a 'GET /skills' route with 'skills:list' action
    #[Get]
    public function list(): Response
    {
        // …
    }

    // This will create a 'GET /skills/:slug' route with 'skills:show' action
    #[Get('/:slug')]
    public function show(string $slug): Response
    {
        // …
    }

    // This will create a 'POST /skills' route with 'skills:create' action
    #[Post]
    public function create(): Response
    {
        // …
    }
}


// app/all/config/routes.php

namespace App;

use ICanBoogie\Binding\Routing\ConfigBuilder;
use ICanBoogie\Routing\CacheStrategy;

return fn(ConfigBuilder $config) => $config
    ->discover_controllers()
    // Meant for production, use CacheStrategy::MEMOIZE in development.
    ->cache_strategy(CacheStrategy::COMPILE);



use ICanBoogie\Binding\Routing\ConfigBuilder;
use ICanBoogie\Routing\RouteBuilder;

return fn(ConfigBuilder $config) => $config
    ->add_controller(ContactController::class, fn(RouteBuilder $r) => $r
        ->get('/contact.html', 'new')
        ->post('/contact.html', 'create'));



namespace ICanBoogie;

/** @var Application $app */

$config = $app->config_for_class(Routing\Config::class);
$routes = $config->routes;