nighten/doctrine-check 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

nighten/doctrine-check

最新稳定版本:0.7.0

Composer 安装命令:

composer require --dev nighten/doctrine-check

包简介

Provides check for doctrine type mapping

README 文档

README

Tool for check doctrine entity field mapping with php types.

Install

composer require nighten/doctrine-check --dev

Running

Create a doctrine-check-config.php in your root directory and modify:

Need to add doctrine object manager to config. Example for Symfony project:

use App\Kernel;
use Nighten\DoctrineCheck\Config\DoctrineCheckConfig;
use Symfony\Component\Dotenv\Dotenv;

require __DIR__ . '/vendor/autoload.php';

return function (DoctrineCheckConfig $config): void {
    (new Dotenv())->bootEnv(__DIR__ . '/.env');
    $kernel = new Kernel($_SERVER['APP_ENV'], (bool)$_SERVER['APP_DEBUG']);
    $kernel->boot();

    $config->addObjectManager($kernel->getContainer()->get('doctrine')->getManager());
};

Then run check:

vendor/bin/doctrine-check types

The list of checks:

Simple types such as int, string, bool, datetime and so on. Check match type and nullable

Example:

#[ORM\Column(type: 'string', nullable: true)]
private ?string $code;

#[ORM\Column(type: 'integer', nullable: false, enumType: Type::class)]
private Type $type;

#[ORM\Column(type: 'boolean', nullable: false)]
private bool $deleted = false;

#[ORM\Column(type: 'datetime_immutable', nullable: true)]
private ?DateTimeImmutable $updatedAt = null;

Association mapping ManyToOne:

Example:

#[
    ORM\ManyToOne(targetEntity: User::class),
    ORM\JoinColumn(nullable: false),
]
private User $user;

Embedded mapping:

Types and nulls in the embeddable class are checked.

Types and null are checked in the main class

Example:

#[Embeddable]
class Address
{
    #[ORM\Column(type: 'string', nullable: true)]
    private ?string $code;
}

class User
{
    #[Embedded(class: Address::class)]
    private Address $address;
    ...
}

Configuration

Add additional type mappings:

use Symfony\Component\Uid\UuidV1;
use Symfony\Component\Uid\UuidV4;
use Symfony\Component\Uid\UuidV7;

//...

return function (DoctrineCheckConfig $config): void {
    //...
    $config->addTypeMapping('uuid', UuidV1::class);
    $config->addTypeMapping('uuid', UuidV4::class);
    $config->addTypeMapping('uuid', UuidV7::class);
};

Add specific entity classes:

The checker will check only the specified classes

use App\Entity\EntityClass;
use Nighten\DoctrineCheck\Type;

//...

return function (DoctrineCheckConfig $config): void {
    //...
    $config->addEntityClass(EntityClass::class);
};

Ignore some entity classes:

The checker will check all classes except those specified

use App\Entity\EntityClass;
use Nighten\DoctrineCheck\Type;

//...

return function (DoctrineCheckConfig $config): void {
    //...
    $config->addExcludedEntityClasses(EntityClass::class);
};

Add error ignores:

The checker will skip the specified errors

use App\Entity\EntityClass;
use Nighten\DoctrineCheck\Type;

//...

return function (DoctrineCheckConfig $config): void {
    //...
    $config->addIgnore(EntityClass::class, 'name', ErrorType::TYPE_WRONG_NULLABLE);
};

统计信息

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

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-06-07