insidesuki/doctrine-manager 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

insidesuki/doctrine-manager

最新稳定版本:0.2.1

Composer 安装命令:

composer require insidesuki/doctrine-manager

包简介

Doctrine manager

README 文档

README

Simple doctrine manager for repositories. Only support for XMLMapping.

EntityRepository is completely isolated to avoid coupling to doctrine.

Usage

  • Create an abstract class that extends from Insidesuki\DoctrineManager\AbstractDoctrineRepository:
use Insidesuki\DoctrineManager\AbstractDoctrineRepository;

abstract class ExampleRepository extends AbstractDoctrineRepository
{

    /**
    * @param string $entity  entity to manage
    * @throws ORMException
    * Uses a settings php array
    */
    public function __construct(string $entity)
    {
        $settings = require __DIR__ . '/../config/db_settings.php';
        parent::__construct($entity, $settings['db_test']);
    }

    /**
    * XML mapping
    * @return string
    */
    protected static function mapping(): string
    {
        return __DIR__ . '/../Mappings';
    }
}
  • Each entity repository must extend from ExampleRepository
  • By overloading the constructor, the entity that will manage the repository is specified.

     class EstadoDoctrineRepository extends ExampleRepository 
     {
    
      public function __construct()
      {
         parent::__construct(Entity::class);
      }
    
    public function findById(int $id): ?Entity
    {
       return $this->find($id);
    }

   /**
    * @throws \Doctrine\ORM\OptimisticLockException
    * @throws \Doctrine\ORM\ORMException
    */
    public function store(Entity $entity): Entity
     {
       $this->save($entity);
       return $entity;
     }
  }

DB Settings example

  • Array php

    <?php
      // /config/db_settings
    return [
            'db_test' => [
              'driver' => 'pdo_mysql',
              'host' => 'any_host',
              'port' => '3306',
              'dbname' => 'db_name',
              'user' => 'db_user',
              'password' => 'db_pass'
          ]
    ];
    
  • Or use .env files, whatever you like (*Recommended)

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-02-15