mrynarzewski/dictionary-bundle 问题修复 & 功能扩展

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

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

mrynarzewski/dictionary-bundle

Composer 安装命令:

composer require mrynarzewski/dictionary-bundle

包简介

Symfony bundle for managing reusable dictionaries and dictionary items.

README 文档

README

Reusable Symfony bundle for storing business dictionaries and dictionary items in Doctrine.

What was recently changed

  • minimum PHP requirement raised to ^8.2
  • dependency constraints tightened for Symfony 6.4/7.x and Doctrine
  • Doctrine mapping migrated to PHP attributes
  • custom validator fixed to validate dictionary item values correctly
  • Docker-based development environment added

Package scope

The bundle provides:

  • Dictionary and DictionaryItem Doctrine entities
  • repositories for querying dictionary items
  • services for creating and updating dictionaries and items
  • BelongToDictionary validator for checking whether a scalar value exists in a given dictionary
  • DictionaryItemType form type

Deletion is intentionally blocked by the services, so the bundle treats dictionaries as reference data.

Installation in a Symfony project

  1. Install the bundle with Composer. Choose one of the following options:

Standard Composer installation:

composer require mrynarzewski/dictionary-bundle

Local development with a Composer path repository:

{
  "repositories": [
    {
      "type": "path",
      "url": "../symfony-dictionary-bundle"
    }
  ]
}

Then require the package:

composer require mrynarzewski/dictionary-bundle:*
  1. Register the bundle in config/bundles.php if Symfony Flex does not do it automatically:
<?php

return [
    Mrynarzewski\DictionaryBundle\MrynarzewskiDictionaryBundle::class => ['all' => true],
];
  1. Add Doctrine mapping for the bundle entities in config/packages/doctrine.yaml:
doctrine:
  orm:
    mappings:
      MrynarzewskiDictionaryBundle:
        is_bundle: false
        type: attribute
        dir: '%kernel.project_dir%/vendor/mrynarzewski/dictionary-bundle/Entity'
        prefix: 'Mrynarzewski\DictionaryBundle\Entity'
        alias: MrynarzewskiDictionaryBundle
  1. If your application does not use Doctrine migrations yet, install the Symfony integration:
composer require doctrine/doctrine-migrations-bundle
  1. Run the migrations. The bundle ships its own migration and registers its migrations path automatically when doctrine/doctrine-migrations-bundle is installed:
php bin/console doctrine:migrations:migrate

Using the bundle

The bundle exposes two Doctrine entities:

  • Mrynarzewski\DictionaryBundle\Entity\Dictionary
  • Mrynarzewski\DictionaryBundle\Entity\DictionaryItem

It also exposes two main services through their interfaces:

  • Mrynarzewski\DictionaryBundle\Service\DictionaryServiceInterface
  • Mrynarzewski\DictionaryBundle\Service\DictionaryItemServiceInterface

Creating dictionaries and items

<?php

namespace App\Service;

use Mrynarzewski\DictionaryBundle\Repository\DictionaryRepository;
use Mrynarzewski\DictionaryBundle\Service\DictionaryItemServiceInterface;
use Mrynarzewski\DictionaryBundle\Service\DictionaryServiceInterface;

final class SeedDictionaryService
{
    public function __construct(
        private readonly DictionaryServiceInterface $dictionaryService,
        private readonly DictionaryItemServiceInterface $dictionaryItemService,
        private readonly DictionaryRepository $dictionaryRepository,
    ) {
    }

    public function seed(): void
    {
        $dictionary = $this->dictionaryRepository->find('country');

        if ($dictionary === null) {
            $dictionary = $this->dictionaryService->create('country', 'Countries');
        }

        $this->dictionaryItemService->create($dictionary, 'PL', 'Poland');
        $this->dictionaryItemService->create($dictionary, 'DE', 'Germany');
    }
}

Querying items

Use DictionaryRepository to fetch a dictionary and DictionaryItemRepository to fetch or validate items:

$dictionary = $dictionaryRepository->find('country');
$items = $dictionaryItemRepository->getItemsFromDictionary($dictionary);
$exists = $dictionaryItemRepository->existsInDictionaryByItem($dictionary, 'PL');

Validating a field against a dictionary

The bundle includes the BelongToDictionary constraint, which lets you validate a scalar value against an existing dictionary:

<?php

namespace App\Dto;

use Mrynarzewski\DictionaryBundle\Constraints\BelongToDictionary;

final class AddressDto
{
    #[BelongToDictionary(dictionary: 'country')]
    public ?string $countryCode = null;
}

Form type

The bundle includes a simple DictionaryItemType form type for DictionaryItem entities:

$form = $this->createForm(\Mrynarzewski\DictionaryBundle\Form\DictionaryItemType::class, $dictionaryItem);

Notes

  • Dictionary::id is a string identifier, for example country or currency.
  • The bundle stores data in the dictionary and dictionary_item tables.
  • Each DictionaryItem is unique within a dictionary by the pair (dictionary_id, item).
  • The services intentionally do not support deletion, so dictionaries should be treated as reference data.

Local development with Docker

Build and start the PHP container:

docker compose up -d --build

Install dependencies inside the container:

docker compose exec app composer install

Run a quick syntax check:

docker compose exec app find . -path ./vendor -prune -o -name '*.php' -print0 | xargs -0 -n1 php -l

Open a shell in the container:

docker compose exec app bash

Notes on compatibility

The bundle now targets modern Symfony applications while keeping a practical compatibility window:

  • PHP ^8.2
  • Symfony ^6.4 || ^7.0
  • Doctrine ORM ^2.17 || ^3.0

The provided Docker image runs PHP 8.4, so you can validate the bundle on a newer runtime even though the library itself supports PHP 8.2+.

mrynarzewski/dictionary-bundle 适用场景与选型建议

mrynarzewski/dictionary-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 46 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 05 月 28 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「symfony」 「bundle」 「doctrine」 「dictionary」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 mrynarzewski/dictionary-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 mrynarzewski/dictionary-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 mrynarzewski/dictionary-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-05-28