besmartand-pro / doctrine-behaviors
Doctrine Behavior Traits
Installs: 4
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 299
Type:symfony-bundle
Requires
- php: >=8.0
- doctrine/common: ^3.3
- doctrine/dbal: ^3.0 | ^4.0
- doctrine/doctrine-bundle: ^2.6
- doctrine/orm: ^3.0
- doctrine/persistence: ^2.5|^3.0
- nette/utils: 4.*
- ramsey/uuid: ^4.2
- symfony/cache: ^6 | ^7
- symfony/dependency-injection: ^6 | ^7
- symfony/framework-bundle: ^6 | ^7
- symfony/http-kernel: ^6 | ^7
- symfony/security-bundle: ^6 | ^7
- symfony/security-core: ^6 | ^7
- symfony/string: ^6 | ^7
- symfony/translation-contracts: ^2.4|^3.0
Requires (Dev)
- ext-pdo_mysql: *
- ext-pdo_pgsql: *
- ext-pdo_sqlite: *
- doctrine/annotations: ^2.0
- php-parallel-lint/php-parallel-lint: ^1.4.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan: ^1.11.8
- phpstan/phpstan-doctrine: ^1.3
- phpstan/phpstan-phpunit: ^1.1
- phpunit/phpunit: ^9.5
- psr/log: ^1.1
- rector/rector: ^0.13.4
- roave/security-advisories: dev-latest
- symplify/easy-ci: ^10.2.9
- symplify/easy-coding-standard: ^12.3.4
- symplify/phpstan-extensions: ^11.4.3
- symplify/phpstan-rules: ^13.0.0
This package is auto-updated.
Last update: 2024-11-02 11:24:15 UTC
README
This PHP library is a collection of traits and interfaces that add behaviors to Doctrine entities and repositories.
It currently handles:
Install
composer require besmartand-pro/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()
andTranslatableInterface::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
Create rector.php
config:
vendor/bin/rector init
Add Doctrine Behaviors upgrade set to rector.php
:
use Rector\Core\Configuration\Option; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; use Rector\Doctrine\Set\DoctrineSetList; return static function (ContainerConfigurator $containerConfigurator): void { $containerConfigurator->import(DoctrineSetList::DOCTRINE_BEHAVIORS_20); };
Run Rector:
vendor/bin/rector process src