2017 © Pedro Peláez
 

library bind-routing

Binds icanboogie/routing to ICanBoogie.

image

icanboogie/bind-routing

Binds icanboogie/routing to ICanBoogie.

  • Sunday, March 18, 2018
  • by olvlvl
  • Repository
  • 1 Watchers
  • 0 Stars
  • 2,507 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 8 Versions
  • 0 % Grown

The README.md

bind-routing

Release Code Coverage Downloads, (*1)

The icanboogie/bind-routing package binds ICanBoogie/Routing to ICanBoogie. It provides infrastructure to configure routes and responders, a trait to get URLs from objects, and commands to list routes and actions., (*2)

Installation

composer require icanboogie/bind-routing

Defining routes using attributes

The easiest way to define routes is to use attributes such as Route or Get to tag your controller and actions. Using any of these tags triggers the registration of the controller as a service (if it is not already registered), and the tagging with action_responder and action_alias., (*3)

The following example demonstrates how the Route attribute can be used at the class level to specify a prefix for all the actions of a controller. The Get and [Post][] attributes are used to tag actions. If left undefined, the action is inferred from the controller class and the method name., (*4)

<?php

namespace App\Presentation\HTTP

use ICanBoogie\Accessor\AccessorTrait;use ICanBoogie\Binding\Routing\Attribute\Get;use ICanBoogie\Binding\Routing\Attribute\Route;use ICanBoogie\Routing\ControllerAbstract;

#[Route('/skills')]
final SkillController extends ControllerAbstract
{
    use AccessorTrait;

    // This will create a 'GET /skills' route with 'skills:list' action
    #[Get]
    private function list(): void
    {
        // …
    }

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

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

Use the use_attributes() method to configure the builder using attributes:, (*5)

<?php
// app/all/config/routes.php

namespace App;

use ICanBoogie\Binding\Routing\ConfigBuilder;

return fn(ConfigBuilder $config) => $config->use_attributes();

Defining routes using configuration fragments

Alternatively, you can configure routes manually using routes configuration fragments, but you will have to register the service and tag it with action_responder and action_alias., (*6)

The following example demonstrates how to define routes, resource routes. The pattern of the articles:show route is overridden to use year, month and slug., (*7)

<?php

// config/routes.php

namespace App;

use ICanBoogie\Binding\Routing\ConfigBuilder;
use ICanBoogie\Routing\RouteMaker;

return fn(ConfigBuilder $config) => $config
    ->route('/', 'page:home')
    ->resource('articles', new Make\Options(
        basics: [
            RouteMaker::ACTION_SHOW => new Make\Basics('/articles/:year-:month-:slug.html')
        ]
    ));

Matching routes with controllers

Routes have no idea of the controller to use, to match a route with a controller, you need to tag the controller with the actions that it supports., (*8)

The following example demonstrates how ArticleControler is configured to handle the actions articles:show and articles:list., (*9)

services:
  _defaults:
    autowire: true

  App\Presentation\HTTP\Controller\ArticleController:
      shared: false
      tags:
      - { name: action_responder }
      - { name: action_alias, action: 'articles:list' }
      - { name: action_alias, action: 'articles:show' }

Getting route configuration

The following code demonstrates how to obtain a route provider from the routes configuration:, (*10)

<?php

namespace ICanBoogie;

/** @var Application $app */

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

Continuous Integration

The project is continuously tested by GitHub actions., (*11)

Tests Static Analysis Code Style, (*12)

Code of Conduct

This project adheres to a Contributor Code of Conduct. By participating in this project and its community, you're expected to uphold this code., (*13)

Contributing

See CONTRIBUTING for details., (*14)

The Versions

18/03 2018

5.0.x-dev

5.0.9999999.9999999-dev https://icanboogie.org/

Binds icanboogie/routing to ICanBoogie.

  Sources   Download

BSD-3-Clause

The Requires

 

routing icanboogie

18/03 2018

4.0.x-dev

4.0.9999999.9999999-dev https://icanboogie.org/

Binds icanboogie/routing to ICanBoogie.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

routing icanboogie

18/03 2018

dev-master

9999999-dev https://icanboogie.org/

Binds icanboogie/routing to ICanBoogie.

  Sources   Download

BSD-3-Clause

The Requires

 

routing icanboogie

18/03 2018

v4.0.0

4.0.0.0 https://icanboogie.org/

Binds icanboogie/routing to ICanBoogie.

  Sources   Download

BSD-3-Clause

The Requires

 

routing icanboogie

03/01 2016

v2.6.0

2.6.0.0 http://icanboogie.org/

Binds icanboogie/routing to ICanBoogie.

  Sources   Download

BSD-3-Clause

The Requires

 

routing icanboogie

02/01 2016

v3.0.0

3.0.0.0 http://icanboogie.org/

Binds icanboogie/routing to ICanBoogie.

  Sources   Download

BSD-3-Clause

The Requires

 

routing icanboogie

25/10 2015

dev-pattern-warmup

dev-pattern-warmup http://icanboogie.org/

Binds icanboogie/routing to ICanBoogie.

  Sources   Download

BSD-3-Clause

The Requires

 

routing icanboogie

01/03 2015

v0.1.0

0.1.0.0 http://icanboogie.org/

Binds Routing to ICanBoogie.

  Sources   Download

BSD-3-Clause

The Requires

 

routing icanboogie