2017 © Pedro Peláez
 

library doctrine-extensions

Useful doctrine hooks.

image

core23/doctrine-extensions

Useful doctrine hooks.

  • Sunday, July 15, 2018
  • by core23
  • Repository
  • 0 Watchers
  • 0 Stars
  • 154 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 18 % Grown

The README.md

Doctrine Extensions

Latest Stable Version Latest Unstable Version License, (*1)

Total Downloads Monthly Downloads Daily Downloads, (*2)

Continuous Integration Code Coverage, (*3)

This library provides adds some useful doctrine hooks., (*4)

Installation

Open a command console, enter your project directory and execute the following command to download the latest stable version of this library:, (*5)

composer require nucleos/doctrine-extensions

Usage

Confirmable entities

If you need entities that needs to be confirmed, just implement the Nucleos\Doctrine\Model\Confirmable in your entity class., (*6)

If you don't need the symfony framework, you need to register the Nucleos\Doctrine\EventListener\ORM\ConfirmableListener., (*7)

Deleteable entities

If you need entities that should be soft deleted, just implement the Nucleos\Doctrine\Model\Deletable in your entity class., (*8)

If you don't need the symfony framework, you need to register the Nucleos\Doctrine\EventListener\ORM\DeletableListener., (*9)

Lifecyle aware enties

If you need lifecyle information (creation / update date), just implement the Nucleos\Doctrine\Model\LifecycleAware in your entity class., (*10)

If you don't need the symfony framework, you need to register the Nucleos\Doctrine\EventListener\ORM\LifecycleDateListener., (*11)

Position aware entities

If you need sortable entities, just implement the Nucleos\Doctrine\Model\PositionAware in your entity class., (*12)

If you don't need the symfony framework, you need to register the Nucleos\Doctrine\EventListener\ORM\SortableListener., (*13)

Unique active entities

If you need entities that should only have one active state, just implement the Nucleos\Doctrine\Model\UniqueActiveAware in your entity class., (*14)

If you don't need the symfony framework, you need to register the Nucleos\Doctrine\EventListener\ORM\UniqueActiveListener., (*15)

Table prefix

If you need a prefix for all of you application tables and sequences, you could use the TablePrefixEventListener. If the table name does already start with the defined prefix, it will be ignored., (*16)

If you don't need the symfony framework, you need to register the Nucleos\Doctrine\EventListener\ORM\TablePrefixEventListener., (*17)

Migration usage

  1. Update your id column from integer to guid., (*18)

  2. Create a new migration:, (*19)

// src/Migrations/Version123.php
<?php

namespace Application\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
use Nucleos\Doctrine\Migration\IdToUuidMigration;

class Version123 extends AbstractMigration
{
    private IdToUuidMigration $idToUuidMigration;

    public function __construct(Connection $connection, LoggerInterface $logger)
    {
        parent::__construct($connection, $logger);

        $this->idToUuidMigration = new IdToUuidMigration($this->connection, $logger);
    }


    public function postUp(Schema $schema): void
    {
        $this->idToUuidMigration->migrate('my_table_name');
    }
}

Symfony usage

If you want to use this library inside symfony, you can use a bridge., (*20)

Enable the Bundle

Then, enable the bundle by adding it to the list of registered bundles in config/bundles.php file of your project:, (*21)

// config/bundles.php

return [
    // ...
    Nucleos\Doctrine\Bridge\Symfony\Bundle\NucleosDoctrineBundle::class => ['all' => true],
];

Configure the Bundle

Create a configuration file called nucleos_doctrine.yaml:, (*22)

# config/packages/nucleos_doctrine.yaml

nucleos_doctrine:
    table:
        prefix: 'acme_'

License

This library is under the MIT license., (*23)

The Versions