MyGit

KnpLabs/DoctrineBehaviors

Fork: 257 Star: 910 (更新于 1970-01-01 00:00:00)

license: MIT

Language: PHP .

Doctrine2 behavior traits that help handling Blameable, Loggable, Sluggable, SoftDeletable, Uuidable, Timestampable, Translatable, Tree behavior

最后发布版本: 2.3.0 ( 2021-08-09 16:40:37)

官方网址 GitHub网址

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

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

最近版本更新:(数据更新于 1970-01-01 00:00:00)

2021-08-09 16:40:37 2.3.0

2021-03-09 06:25:58 2.2.0

2020-01-02 07:46:40 v2.0.0

2018-11-13 18:56:41 1.6.0

2017-10-06 16:55:11 1.5.0

2017-09-20 00:17:39 1.4.1

2016-09-30 14:09:20 1.4.0

2016-03-09 20:10:49 1.3.2

2016-03-09 19:28:22 1.3.1

2016-01-12 16:18:55 1.3.0

主题(topics):

behavior, doctrine, doctrine2, orm, php, trait

KnpLabs/DoctrineBehaviors同语言 PHP最近更新仓库

2024-11-20 23:58:25 laravel/framework

2024-11-20 18:39:23 danielmiessler/SecLists

2024-11-16 21:54:23 w7corp/easywechat

2024-11-16 04:49:03 coollabsio/coolify

2024-11-13 23:19:14 symfony/symfony

2024-11-13 22:53:21 symfony/var-dumper