tbn / getter-trait-bundle
3.00
2024-07-03 18:43 UTC
Requires
- php: ^8.2
- phpdocumentor/reflection-docblock: ^5.4.1
- phpdocumentor/type-resolver: ^1.4
- symfony/framework-bundle: ^7.1
- symfony/property-info: ^7.1
- symfony/string: ^7.1
Requires (Dev)
- doctrine/collections: ^2.1
- nyholm/symfony-bundle-test: ^3.0
- phpunit/phpunit: ^10.3
- symfony/uid: ^7.1
This package is auto-updated.
Last update: 2024-09-03 19:22:34 UTC
README
生成 trait 内部 getter 和 setter 的 Symfony Bundle。
为什么?基本的 getter 并不能提供关于类的信息。
类因为没有任何“业务”原因而变得很长。
只有重新定义的方法才能识别出具有业务目的的方法。
安装
composer require --dev "tbn/getter-trait-bundle"
在 config/bundles.php
文件中,将 bundle 添加到开发环境
return [ ... tbn\GetterTraitBundle\GetterTraitBundle::class => ['dev' => true,], ];
使用
将 GetSetTrait
属性添加到您的类中
use tbn\GetterTraitBundle\Attributes\GetSetTrait; // add this line #[GetSetTrait] // add this line class MyClass { private String $name; }
运行 ./bin/console generate:getter:traits
命令
将在同一文件夹中自动生成一个新文件,包含 MyClass
类的 getter 和 setter。
当属性被修改或添加时,您必须重新运行命令以更新 traits。
使用生成的 trait。
#[GetSetTrait] class MyClass { use MyClassTrait; // add this line private String $name; }
我需要重新定义方法
只需将生成的代码复制粘贴到您的类中,并根据您的需要进行更新。