amyboyd/symfony-router-validation

此包已被废弃,不再维护。未建议替代包。
此包最新版本(1.0.0)没有可用的许可证信息。

检查您的 Symfony 路由是否有效的服务和命令

1.0.0 2016-06-11 20:48 UTC

This package is not auto-updated.

Last update: 2023-10-13 00:48:00 UTC


README

此库提供了一个服务和命令,用于检查您的路由配置中的路由是否有效。

安装

将包添加到依赖中

composer require amyboyd/symfony-router-validation

将这些行添加到您的服务配置中(例如在 services.ymlconfig.yml 中)

services:
    amyboyd.command.router_validate_command:
        class: AmyBoyd\SymfonyStuff\RouterValidation\RouterValidationCommand
        tags:
            -  { name: console.command }

    amyboyd.router_validation:
        class: AmyBoyd\SymfonyStuff\RouterValidation\RouterValidationService
        arguments:
            controllerNameParser: '@controller_name_converter'
            container: '@service_container'

从命令行检查您的路由是否有效

  • 在 Symfony 2.* 中,运行 app/console router:validate
  • 在 Symfony 3.* 中,运行 bin/console router:validate

贡献

为本地开发设置环境

git clone git@github.com:amyboyd/symfony-router-validation.git
cd symfony-router-validation
bin/composer-install

要验证您的安装是否正常工作,请运行测试

bin/test
bin/run-validate-command

测试将在多个版本的 Symfony 上运行(目前为 2.5、2.8、3.0 和 3.1)。

示例输出

3 valid routes
6 invalid routes
app_invalid_controller_because_bundle_does_not_exist - Bundle "InvalidBundle" (from the _controller value "InvalidBundle:Default:index") does not exist, or is it not enabled
app_invalid_controller_because_of_trailing_action - Method "indexActionAction" does not exist in class "AppBundle\Controller\DefaultController".
app_invalid_controller_because_class_does_not_exist - The _controller value "AppBundle:InvalidClass:index" maps to a "AppBundle\Controller\InvalidClassController" class, but this class was not found. Create this class or check the spelling of the class and its namespace.
app_invalid_service_because_service_doesnt_exist - You have requested a non-existent service "app.invalid_controller_service". Did you mean this: "app.controller_service"?
app_invalid_service_because_method_doesnt_exist - Method "invalidMethodAction" does not exist in class "AppBundle\Controller\DefaultController".
app_invalid_missing_controller - _controller property is not set.
2 routes are in a format not supported by this command  - Please report the details at https://github.com/amyboyd/symfony-router-validation/issues
app_invalid_route_format - Route format "blabla!£%" is not supported by this tool
app_invalid_route_format_2 - Route format "AppBundleDefault@" is not supported by this tool

如何在持续集成测试或 Git 预提交钩子中使用

如果所有路由都有效,命令返回退出码 0,如果存在无效路由,则返回 1。您可以在持续集成测试或 Git 预提交钩子中使用它,如下所示

app/console router:validate # or bin/console in Symfony 3
if [[ $? != '0' ]]; then
    exit 1
fi