DoctrineBehaviors
vior 2.3 Released
This PHP library is a collection of traits and interfaces that add behaviors to Doctrine entities and repositories.
It currently handles:
composer require knplabs/doctrine-behaviorsAll you have to do is to define a Doctrine entity:
For some behaviors like tree, you can use repository traits:
<?php
declare(strict_types=1);
namespace AppRepository;
use DoctrineORMEntityRepository;
use KnpDoctrineBehaviorsORMTreeTreeTrait;
final class CategoryRepository extends EntityRepository
{
use TreeTrait;
}Voilà!
You now have a working Category that behaves like.
A PHPStan extension is available and provides the following features:
TranslatableInterface::getTranslations() and TranslatableInterface::getNewTranslations()TranslatableInterface::translate()TranslationInterface::getTranslatable()Include phpstan-extension.neon in your project's PHPStan config:
# phpstan.neon
includes:
- vendor/knplabs/doctrine-behaviors/phpstan-extension.neon1 feature per pull-request
New feature needs tests
Tests and static analysis must pass:
vendor/bin/phpunit
composer fix-cs
composer phpstanThere 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 --devCreate rector.php config:
vendor/bin/rector initAdd Doctrine Behaviors upgrade set to rector.php:
use RectorCoreConfigurationOption;
use SymfonyComponentDependencyInjectionLoaderConfiguratorContainerConfigurator;
use RectorDoctrineSetDoctrineSetList;
return static function (ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->import(DoctrineSetList::DOCTRINE_BEHAVIORS_20);
};Run Rector:
vendor/bin/rector process src