Popularity
6.5
Growing
Activity
6.8
Growing
823
53
240

Description

This PHP >=5.4 library is a collection of traits and interfaces that add behaviors to Doctrine2 entities and repositories.

It currently handles: blameable filterable geocodable joinable loggable sluggable softDeletable sortable timestampable translatable tree

Programming language: PHP
License: MIT License
Tags: Database     ORM     MySQL     SQL     Tree     Symfony     Bundle     Doctrine2     Behaviors     Translatable     Timestampable     Blameable     Filterable     Softdeletable    
Latest version: v2.0.8

Doctrine2 Behaviors alternatives and similar libraries

Based on the "Database" category.
Alternatively, view Doctrine2 Behaviors alternatives based on common mentions on social networks and blogs.

Do you think we are missing an alternative of Doctrine2 Behaviors or a related project?

Add another 'Database' Library

README

Doctrine Behaviors

Downloads

This PHP library is a collection of traits and interfaces that add behaviors to Doctrine entities and repositories.

It currently handles:

Install

composer require knplabs/doctrine-behaviors

Usage

All you have to do is to define a Doctrine entity:

  • implemented interface
  • add a trait

For some behaviors like tree, you can use repository traits:

<?php

declare(strict_types=1);

namespace App\Repository;

use Doctrine\ORM\EntityRepository;
use Knp\DoctrineBehaviors\ORM\Tree\TreeTrait;

final class CategoryRepository extends EntityRepository
{
    use TreeTrait;
}

Voilà!

You now have a working Category that behaves like.

PHPStan

A PHPStan extension is available and provides the following features:

  • Provides correct return type for TranslatableInterface::getTranslations() and TranslatableInterface::getNewTranslations()
  • Provides correct return type for TranslatableInterface::translate()
  • Provides correct return type for TranslationInterface::getTranslatable()

Include phpstan-extension.neon in your project's PHPStan config:

# phpstan.neon
includes:
    - vendor/knplabs/doctrine-behaviors/phpstan-extension.neon

3 Steps to Contribute

  • 1 feature per pull-request
  • New feature needs tests
  • Tests and static analysis must pass:

    vendor/bin/phpunit
    composer fix-cs
    composer phpstan
    

Upgrade 1.x to 2

There have been many changes between 1 and 2, but don't worry. This package uses Rector, that handles upgrade for you.

composer require rector/rector --dev
vendor/bin/rector process src --config vendor/rector/rector/config/set/doctrine-behaviors-20.yaml