定制 lamansky/doctrine 二次开发

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

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

lamansky/doctrine

Composer 安装命令:

composer require lamansky/doctrine

包简介

A collection of classes useful in almost any project that uses the Doctrine ORM.

README 文档

README

A collection of utility classes for the Doctrine ORM (Object Relational Mapper).

Installation

With Composer installed on your computer and initialized for your project, run this command in your project’s root directory:

composer require lamansky/doctrine

Requires PHP 7.4 or above.

You don’t need to install Doctrine2 separately. It will be bundled with this package.

Classes

The library contains two classes that are useful for almost any Doctrine project: ProjectEntityManager and UTCDateTimeType.

ProjectEntityManager

An abstract EntityManagerDecorator that automatically namespaces your Entity class names. To use, first create a class for your project that extends ProjectEntityManager and defines the class namespace prefixes:

<?php
namespace MyProject\Doctrine;
use Lamansky\Doctrine\ProjectEntityManager;

class EntityManager extends ProjectEntityManager {
    protected function getEntityNamespacePrefix () : string {
        return 'MyProject\Model\Entity\\';
    }

    protected function getProxyNamespacePrefix () : string {
        return 'MyProject\Model\Proxy\\';
    }
}

Then, initialize your entity manager like this:

<?php
use MyProject\Doctrine\EntityManager;

global $em;

$em = new EntityManager(
    DB_HOST,
    DB_USER,
    DB_PASS,
    DB_NAME,
    IS_DEV_ENV, // This should be true or false.
    __DIR__ . '/Model/Entity', // This is the path to your Entity class files directory.
    __DIR__ . '/Model/Proxy' // This is the directory path in which generated Proxy class files should be stored.
);

UTCDateTimeType

Ensures that all datetimes are converted to the UTC timezone when being stored in the database and are converted back to the server’s local timezone when being retrieved. Returns Carbon objects instead of built-in DateTime objects.

Just use this code to override the built-in datetime types:

<?php
use Doctrine\DBAL\Types\Type;

Type::overrideType('datetime', 'Lamansky\Doctrine\UTCDateTimeType');
Type::overrideType('datetimetz', 'Lamansky\Doctrine\UTCDateTimeType');

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-08-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固