icanboogie/bind-routing 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

icanboogie/bind-routing

最新稳定版本:5.0

Composer 安装命令:

composer require icanboogie/bind-routing

包简介

Binds icanboogie/routing to ICanBoogie.

README 文档

README

Release Code Coverage Downloads

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.

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.

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.

<?php

namespace App\Presentation\HTTP

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

#[Route('/skills')]
final SkillController extends ControllerAbstract
{
    // 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:

<?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.

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.

<?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.

The following example demonstrates how ArticleControler is configured to handle the actions articles:show and articles:list.

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:

<?php

namespace ICanBoogie;

/** @var Application $app */

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

Continuous Integration

The project is continuously tested by GitHub actions.

Tests Static Analysis Code Style

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.

Contributing

See CONTRIBUTING for details.

统计信息

  • 总下载量: 3.91k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 3
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2015-02-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固