besmartand-pro/doctrine-behaviors

Doctrine 行为特性

安装: 4

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 0

分支: 290

类型:symfony-bundle

1.0.0-rc1 2024-08-02 09:48 UTC

This package is auto-updated.

Last update: 2024-09-02 10:56:15 UTC


README

Downloads

这个PHP库是一组特性和接口,可以为Doctrine实体和存储库添加行为。

目前它处理以下功能

安装

composer require besmartand-pro/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-extension.neon包含到您的项目PHPStan配置中

# 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