承接 letkode/entity-traits-bundle 相关项目开发

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

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

letkode/entity-traits-bundle

Composer 安装命令:

composer require letkode/entity-traits-bundle

包简介

Doctrine entity traits, value objects, DTOs and DQL utilities for Symfony applications

README 文档

README

Doctrine entity traits, repository traits, value objects, DTOs and DQL utilities for Symfony applications.

Installation

composer require letkode/entity-traits-bundle

Symfony Flex will register the bundle automatically. If not using Flex, add it manually:

// config/bundles.php
return [
    Letkode\EntityTraitsBundle\LetkodeEntityTraitsBundle::class => ['all' => true],
];

The bundle automatically registers the TRANSLATE_FIELD_VALUE Doctrine DQL function via PrependExtensionInterface.

Entity Traits

UuidTrait

Adds a uuid column (UUIDv7) with a PostgreSQL uuidv7() default. The UuidGeneratorSubscriber ensures PHP-side generation before persist so Gedmo Loggable captures the value.

use Letkode\EntityTraitsBundle\Trait\Entity\UuidTrait;

#[ORM\Entity]
class Product
{
    use UuidTrait;
}

HasTranslationsTrait

Adds a translations jsonb column for multi-locale field values.

$entity->setTranslation('es', 'name', 'Producto');
$entity->getTranslation('es', 'name'); // 'Producto'

ParameterTrait

Adds a parameters jsonb column with recursive merge support.

$entity->setParameter('color', 'red');
$entity->getParameter('color'); // 'red'
$entity->setParameters(['size' => 'L'], force: false); // recursive merge

ObjectTrackNullableTrait / ObjectTrackRequiredTrait

Adds objectClass and objectId columns to track which object a record belongs to. Use the nullable variant when the relation is optional.

Repository Traits

BaseRepositoryTrait

$repo->save($entity);
$repo->remove($entity);
$repo->findByUuid($uuid);           // returns T|null
$repo->findOrFailByUuid($uuid);     // throws EntityNotFoundException
$repo->paginate($qb, $tableQuery, sortable: ['name'], searchable: ['name', 'email']);

TranslatableRepositoryTrait

$this->addTranslatedOrderBy($qb, 'p', 'name', $locale, 'ASC');
$this->addTranslatedSearch($qb, 'p', 'name', $searchTerm, $locale);

DTOs

TableQueryRequest

$query = TableQueryRequest::fromArray($request->query->all());
// $query->page, $query->perPage, $query->q, $query->sort, $query->dir

PaginatedResult

// Returned by BaseRepositoryTrait::paginate()
$result->data;       // array of entities
$result->total;      // int
$result->page;       // int
$result->perPage;    // int
$result->totalPages; // int (computed)

Value Objects

All value objects are final readonly, normalize on construction and throw ValueObjectException on invalid input.

Class Validates
Email Valid email, lowercased
Phone E.164-compatible (strips spaces/dashes)
Slug Lowercase, [a-z0-9-], 2–255 chars
Username [a-zA-Z0-9_.-], 3–50 chars
$email = new Email('  USER@Example.COM  '); // 'user@example.com'
$slug  = new Slug('My Product Name');        // 'my-product-name'

DQL Function

TRANSLATE_FIELD_VALUE(column, 'field', :locale) maps to jsonb_extract_path_text(column, locale, field).

Useful for ordering and filtering on translated values stored in a jsonb translations column.

Requirements

  • PHP ^8.4
  • Symfony ^7.0 || ^8.0
  • doctrine/orm ^3.0
  • doctrine/bundle ^2.0
  • gedmo/doctrine-extensions ^3.0
  • letkode/common-bundle ^1.0

License

MIT — see LICENSE.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-19

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固