定制 magmasoftwareengineering/doctrine-base 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

magmasoftwareengineering/doctrine-base

Composer 安装命令:

composer require magmasoftwareengineering/doctrine-base

包简介

Base structures for Doctrine-based projects

README 文档

README

Version: 3.x | PHP: >=8.3 | License: MIT

Overview

The Doctrine Base Library (magmasoftwareengineering/doctrine-base) builds upon the Base Library to provide Doctrine ORM/DBAL integration, entity mapping, transformation utilities, and repository patterns for database-driven applications.

This library is the middle layer in the Magma Software Engineering library hierarchy, designed for projects requiring persistent storage and entity management.

Key Features

Entity Management

  • AbstractEntity - Base class with common entity functionality
  • AbstractBaseEntity - Extended base with additional utilities
  • SettingEntity - Pre-built entity for application settings storage
  • StatusAwareTrait / StatusAwareInterface - Add status tracking to entities

Repository Pattern

  • AbstractRepository - Base repository with common query operations
  • RepositoryFactory - Dynamic repository generation
  • SettingRepository - Specialized repository for application settings
  • DoctrineHydratorAwareRepositoryInterface - Hydrator integration

Data Transformation

  • AbstractTransformer - Base transformer for entity-to-DTO conversions
  • EntityTransformerService - Service for managing multiple transformers
  • TransformableInterface - Mark entities as transformable

Database Types

  • TimestampType - Custom Doctrine DBAL type for timestamp fields
  • TinyintType - Custom Doctrine DBAL type for tinyint fields

Services

  • AbstractService - Base service class with dependency injection
  • DoctrineAwareServiceInterface - Services that need entity manager access

Dependencies

magmasoftwareengineering/base: ^3.1 || ^4.0  (Foundation library)
doctrine/dbal: ^3.10                          (Database abstraction)
doctrine/doctrine-laminas-hydrator: ^3.7      (Entity hydration)
doctrine/migrations: ^3.9                     (Database migrations)
doctrine/orm: ^3.6                            (Object-relational mapping)
gedmo/doctrine-extensions: ^3.21              (Behaviour extensions: slugs, timestamps, etc.)
league/fractal: ^0.20 || ^0.21                (Data transformation)

Installation

composer require magmasoftwareengineering/doctrine-base:^3.0

Requires:

composer require magmasoftwareengineering/base:^3.0

Usage Examples

Creating an Entity

use MagmaSoftwareEngineering\DoctrineBase\Entity\AbstractBaseEntity;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
#[ORM\Table(name: 'users')]
class User extends AbstractBaseEntity {
    #[ORM\Column(type: 'string')]
    private string $email;

    #[ORM\Column(type: 'string')]
    private string $name;

    // Getters and setters...
}

Creating a Repository

use MagmaSoftwareEngineering\DoctrineBase\Repository\AbstractRepository;
use Doctrine\ORM\Mapping\ClassMetadata;

class UserRepository extends AbstractRepository {
    public function __construct(EntityManagerInterface $em) {
        parent::__construct($em, $em->getClassMetadata(User::class));
    }

    public function findActiveUsers() {
        return $this->findBy(['status' => 'active']);
    }
}

Entity Transformation

use MagmaSoftwareEngineering\DoctrineBase\Transformer\AbstractTransformer;

class UserTransformer extends AbstractTransformer {
    public function transform(User $user) {
        return [
            'id' => $user->getId(),
            'email' => $user->getEmail(),
            'name' => $user->getName(),
        ];
    }
}

Service Layer

use MagmaSoftwareEngineering\DoctrineBase\Service\AbstractService;

class UserService extends AbstractService {
    public function createUser(string $email, string $name): User {
        $user = new User();
        $user->setEmail($email);
        $user->setName($name);
        $this->em->persist($user);
        $this->em->flush();
        return $user;
    }
}

Architecture

This library provides:

  1. Persistence Layer - Entity management through Doctrine ORM
  2. Data Access Patterns - Repository and Service abstractions
  3. Data Transformation - Entity-to-DTO conversion
  4. Database Extensions - Custom types and behaviors (timestamps, slugs, etc. via Gedmo)

Dependency Chain

magmasoftwareengineering/base
    ↓
magmasoftwareengineering/doctrine-base
    ↓
magmasoftwareengineering/slim-base

Related Libraries

LibraryPurposeWhen to Use
Base LibraryCore utilities, logging, DIAll projects - use as foundation
Doctrine BaseORM entities, repositoriesDatabase-driven applications
Slim Base LibrarySlim 4 HTTP framework integrationWeb applications with Slim 4

Next Steps

  • Building a web application? → Slim Base Library (includes Doctrine Base)
  • Need API scaffolding? Check the slim-skeleton-api project for examples
  • Looking for batch processing? Use AbstractCommand from Base Library

Support & Contributing

For issues or contributions, please contact the maintainer:

  • Jeremy Coates - hello@phpcodemonkey.me.uk

License

MIT License - See LICENSE file for details

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-05-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固