knplabs / doctrine-behaviors
Doctrine 行为特性
2.6.2
2022-08-06 10:40 UTC
Requires
- php: >=8.0
- doctrine/common: ^3.3
- doctrine/dbal: ^3.3
- doctrine/doctrine-bundle: ^2.6
- doctrine/orm: ^2.12
- doctrine/persistence: ^2.5|^3.0
- nette/utils: ^3.2
- ramsey/uuid: ^4.2
- symfony/cache: ^5.4|^6.0
- symfony/dependency-injection: ^5.4|^6.0
- symfony/framework-bundle: ^5.4|^6.0
- symfony/http-kernel: ^5.4|^6.0
- symfony/security-core: ^5.4|^6.0
- symfony/string: ^5.4|^6.0
- symfony/translation-contracts: ^2.4|^3.0
Requires (Dev)
- ext-pdo_mysql: *
- ext-pdo_pgsql: *
- ext-pdo_sqlite: *
- doctrine/annotations: ^1.13
- php-parallel-lint/php-parallel-lint: ^1.3
- phpstan/extension-installer: ^1.1
- phpstan/phpstan: ^1.7.10
- phpstan/phpstan-doctrine: ^1.3
- phpstan/phpstan-phpunit: ^1.1
- phpunit/phpunit: ^9.5
- psr/log: ^1.1
- rector/rector: ^0.13.4
- symplify/easy-ci: ^10.2.9
- symplify/easy-coding-standard: ^10.2.9
- symplify/package-builder: ^10.2.9
- symplify/phpstan-extensions: ^10.2.9
- symplify/phpstan-rules: ^10.2.9
- dev-master
- 2.6.2
- 2.6.1
- 2.6.0
- 2.5.0
- 2.4.0
- 2.3.3
- 2.3.2
- 2.3.1
- 2.3.0
- 2.2.0
- 2.1.0
- v2.0.8
- v2.0.7
- v2.0.6
- v2.0.5
- v2.0.4
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0.0
- v2.0.0-beta1
- v2.0.0-alpha4
- v2.0.0-alpha3
- v2.0.0-alpha2
- v2.0.0-alpha1
- 1.6.1
- 1.6.0
- 1.5.0
- 1.4.1
- 1.4.0
- 1.3.2
- 1.3.1
- 1.3.0
- 1.2.0
- 1.1.1
- v1.1.0
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- dev-remove-hardcoded-translatable-referencedColumnName
- dev-php-mrn-rector-demo
This package is auto-updated.
Last update: 2024-09-06 15:43:29 UTC
README
这个PHP库是一系列特性和接口的集合,可以为Doctrine实体和仓库添加行为。
它目前处理以下行为
安装
composer require knplabs/doctrine-behaviors
使用
你所要做的就是定义一个Doctrine实体
- 实现接口
- 添加一个特性
对于一些行为,如树形结构,你可以使用仓库特性
<?php declare(strict_types=1); namespace App\Repository; use Doctrine\ORM\EntityRepository; use Knp\DoctrineBehaviors\ORM\Tree\TreeTrait; final class CategoryRepository extends EntityRepository { use TreeTrait; }
好了!
你现在有一个工作正常的 Category
,其行为像。
PHPStan
一个PHPStan扩展可用,并提供以下功能
- 为
TranslatableInterface::getTranslations()
和TranslatableInterface::getNewTranslations()
提供正确的返回类型 - 为
TranslatableInterface::translate()
提供正确的返回类型 - 为
TranslationInterface::getTranslatable()
提供正确的返回类型
在项目的PHPStan配置中包含 phpstan-extension.neon
# phpstan.neon includes: - vendor/knplabs/doctrine-behaviors/phpstan-extension.neon
贡献的3步
-
每个pull-request一个功能
-
新功能需要测试
-
测试和静态分析 必须通过
vendor/bin/phpunit composer fix-cs composer phpstan
将1.x升级到2
1和2之间有很多变化,但不用担心。这个包使用了 Rector,它会为你处理升级。
composer require rector/rector --dev
创建 rector.php
配置
vendor/bin/rector init
将Doctrine Behaviors升级集添加到 rector.php
use Rector\Core\Configuration\Option; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; use Rector\Doctrine\Set\DoctrineSetList; return static function (ContainerConfigurator $containerConfigurator): void { $containerConfigurator->import(DoctrineSetList::DOCTRINE_BEHAVIORS_20); };
运行Rector
vendor/bin/rector process src