定制 setono/doctrine-orm-trait 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

setono/doctrine-orm-trait

最新稳定版本:v1.2.0

Composer 安装命令:

composer require setono/doctrine-orm-trait

包简介

A very simple library that offers a trait to get the object manager and repository for a given class

README 文档

README

Latest Version Software License Build Status Code Coverage Mutation testing

If you are like and me and usually don't inject entity managers directly, but inject the manager registry instead then this little library will come in handy.

Installation

composer require setono/doctrine-orm-trait

Usage

<?php
use Doctrine\Persistence\ManagerRegistry;
use Setono\Doctrine\ORMTrait;

final class YourClass
{
    /**
     * Include this trait to use the getManager() and getRepository() methods below
     */
    use ORMTrait;
    
    public function __construct(ManagerRegistry $managerRegistry)
    {
        $this->managerRegistry = $managerRegistry;
    }
    
    public function someMethod(): void
    {
        /**
         * $entity<T> is an entity managed by Doctrine or a class-string representing an entity managed by Doctrine
         */
        $entity = ;
        
        /** @var \Doctrine\ORM\EntityRepository<T> $repository */
        $repository = $this->getRepository($entity);
        
        /** @var \Doctrine\ORM\EntityManagerInterface $manager */
        $manager = $this->getManager($entity);
        
        // or do the following to get the default entity manager
        /** @var \Doctrine\ORM\EntityManagerInterface $manager */
        $manager = $this->getManager();
        
        $manager->persist($entity);
        $manager->flush();
    }
}

统计信息

  • 总下载量: 59.14k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 19
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-04-16