jtc-solutions/core
最新稳定版本:v1.1.0
Composer 安装命令:
composer require jtc-solutions/core
包简介
Core bundle for every application in JTC that follows standard processes.
README 文档
README
This bundle provides a foundational set of services, base classes, and conventions used as a "skeleton" for most PHP Symfony projects developed at JTC Solutions. It aims to streamline development by offering reusable components for common tasks like CRUD operations, exception handling, and API documentation.
Installation
-
Require the bundle using Composer:
composer require jtc-solutions/core-bundle
-
Enable the Bundle: Add the bundle to your
config/bundles.phpfile:<?php return [ // ... other bundles JtcSolutions\Core\JtcSolutionsCoreBundle::class => ['all' => true], ];
Usage
-
Entities:
- Your application entities should implement
JtcSolutions\Core\Entity\IEntity. - Use
Ramsey\Uuid\UuidInterfacefor primary identifiers.
- Your application entities should implement
-
Repositories:
- Implement
JtcSolutions\Core\Repository\IEntityRepository. - Extend
JtcSolutions\Core\Repository\BaseRepository.
- Implement
-
Services:
- Implement
JtcSolutions\Core\Service\IEntityServicefor entities requiring CRUD operations. - Extend
JtcSolutions\Core\Service\BaseEntityServiceto leverage built-in logic for handling creation, updates, and deletion via abstract methods (mapDataAndCallCreate,mapDataAndCallUpdate,delete). - Inject the corresponding repository into your service.
- Implement
-
Controllers:
- Extend
JtcSolutions\Core\Controller\BaseControllerfor AbstractController from Symfony, with the possibility of future improvements. - For controllers handling standard entity CRUD, extend
JtcSolutions\Core\Controller\BaseEntityCRUDController. Inject the correspondingIEntityService. This base controller provides protected methods (handleCreate,handleUpdate,handleDelete) that validate request DTOs and call the service.
- Extend
-
Request Data Transfer Objects (DTOs):
- For request bodies used in create/update operations handled by
BaseEntityCRUDController/BaseEntityService, implementJtcSolutions\Core\Dto\IEntityRequestBody. - Use Symfony's Validator component constraints on your DTO properties.
- For request bodies used in create/update operations handled by
-
Exception Handling & Translations:
- The
ExceptionListeneris enabled by default and will catch exceptions. - It automatically converts
TranslatableExceptiontypes and standard HTTP exceptions intoErrorRequestJsonResponse. - Provide translations for the exception keys in the configured translation domain (default:
exceptions). Keys follow the patterncore.<type>.title,core.<type>.messagefor standard HTTP errors andcustom.<translation_code>.title,custom.<translation_code>.messageforTranslatableExceptiontypes. Example translation file (translations/exceptions.en.yaml):core.not_found.title: 'Resource Not Found' core.not_found.message: 'The requested resource could not be found.' custom.entity_not_found.title: 'Entity Not Found' custom.entity_not_found.message: 'The specific item you were looking for does not exist.' custom.entity_already_exists.title: 'Conflict' custom.entity_already_exists.message: 'An item with the provided details already exists.' # ... add other translations
- The
-
Parameter Resolvers:
- Entity Resolver: If enabled (default), controller actions can directly type-hint arguments with an
IEntityimplementation (e.g.,public function show(Product $product)). If a route parameter{product}exists, the resolver will fetch theProductusing its repository'sfind()method. - UUID Resolver: If enabled (default), controller actions can type-hint arguments with
UuidInterface(e.g.,public function list(UuidInterface $categoryId)). The resolver will attempt to create aUuidobject from a query parameter with the same name (?categoryId=...).
- Entity Resolver: If enabled (default), controller actions can directly type-hint arguments with an
Configuration
Configure the bundle under the jtc_solutions_core key in your config/packages/jtc_solutions_core.yaml (or any other config file).
# config/packages/jtc_solutions_core.yaml jtc_solutions_core: # Parameter Resolver Configuration param_resolvers: uuid_resolver: # Enable/disable the UuidQueryParamResolver (default: true) enable: true entity_resolver: # Enable/disable the EntityParamResolver (default: true) enable: true # Listener Configuration listeners: exception_listener: # Enable/disable the ExceptionListener (default: true) enable: true # Set the translation domain for exception messages (default: 'exceptions') translation_domain: 'exceptions' # OpenAPI / NelmioApiDocBundle Integration open_api: property_describers: uuid_interface_property_describer: # Enable/disable the describer for UuidInterface (default: true) enable: true
统计信息
- 总下载量: 3.66k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: proprietary
- 更新时间: 2025-04-18