Base structures for Doctrine-based projects

Maintainers

Package info

bitbucket.org/magmasoftwareengineering/doctrine-base

Issues

pkg:composer/magmasoftwareengineering/doctrine-base

Statistics

Installs: 1

Dependents: 1

Suggesters: 0

3.3.2 2026-05-20 12:10 UTC

This package is auto-updated.

Last update: 2026-05-20 13:16:57 UTC


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