承接 rdx/laravelcollective-annotations 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

rdx/laravelcollective-annotations

Composer 安装命令:

composer require rdx/laravelcollective-annotations

包简介

Route Annotations for The Laravel Framework.

README 文档

README

This is a laravelcollective/annotations drop-in replacement

To use this package instead of laravelcollective/annotations as a perfect drop-in replacement, do this in your project:

  1. composer require rdx/laravelcollective-annotations
  2. if your project explicitly required annotations: composer remove laravelcollective/annotations

This will install rdx/laravelcollective-annotations and pretend it IS laravelcollective/annotations, and all other packages will believe laravelcollective/annotations is installed, because Composer is awesome.

UPGRADE to 9.0 (PHP Attributes instead of doctrine/annotations)

  1. Download and set up rector/rector, see config below.
  2. Add rule Collective\Annotations\Rector\AnnotationsToAttributesRector to Rector set.
  3. Run Rector with debug enabled, see command below.
  4. Manually fix skipped conversions due to complicated annotation syntax, see complicated example below.
  5. Run your cs fixer to import all FQCN, see php-cs-fixer rule below.
  6. Remove $useAttributes from your AnnotationsServiceProvider, because that doesn't exist anymore.

Example Rector config

return RectorConfig::configure()
	->withPaths([
		__DIR__ . '/app/Http/Controllers',
	])
	->withRules([
		AnnotationsToAttributesRector::class,
	])
;

Run Rector command

vendor/bin/rector process -v --debug --no-diffs app/Http/

This will print all analyzed files, and potential errors, and might include WARNING lines for skipped methods, like:

  WARNING: getPhaseDownload contains unconverted {} properties

Too complicated annotation

@Get("/some/{thing}/download.{ext}", as="thing.download", where={"ext"="json|pdf|xlsx"})

The path isn't a problem, nor the as=, but the where= contains another inner structure, and that won't be converted correctly, so they're broken now, so you have to fix those right after.

php-cs-fixer rule

I assume you have php-cs-fixer set up. Add this rule temporarily:

[
	'fully_qualified_strict_types' => [
		'import_symbols' => true,
		'phpdoc_tags' => [],
	],
]

and run fix only for the Controllers dir:

vendor/bin/php-cs-fixer fix app/Http/Controllers/

This will convert all the Rector added FQCN to imports, but only those, only in the Controllers dir.

If php-cs-fixer skips files and complains about "errors reported during linting", the Rector rule isn't good enough, and something is broken:

Files that were not fixed due to errors reported during linting before fixing:
   1) /var/www/myproject/app/Http/Controllers/MyController.php

You'll have to fix those manually.

统计信息

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

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 72
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-08-10

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固