hawkbit/doctrine

Hawkbit PSR-7 Micro PHP 框架的 Doctrine 2 ORM 集成

dev-master 2016-12-15 09:10 UTC

This package is not auto-updated.

Last update: 2024-09-14 20:14:57 UTC


README

Latest Version on Packagist Software License Build Status Total Downloads Coverage Status

Hawkbit PSR-7 Micro PHP 框架的 Doctrine 2 ORM 集成。

安装

使用 Composer

Hawkbit Doctrine 可在 Packagist 上找到,并可以使用 Composer 安装。可以通过运行以下命令或在您的 composer.json 文件中进行更新来实现。

composer require hawkbit/doctrine

composer.json

{
    "require": {
        "hawkbit/doctrine": "~1.0"
    }
}

确保也将您的 Composer 自动加载文件包含到您的项目中

<?php

require __DIR__ . '/vendor/autoload.php';

下载 .zip 文件

此项目也以 .zip 文件形式在 GitHub 上提供下载。请访问 发布页面,选择您想要的版本,然后点击“源代码(zip)”下载按钮。

要求

此版本支持以下 PHP 版本。

  • PHP 5.5
  • PHP 5.6
  • PHP 7.0
  • PHP 7.1
  • HHVM

设置

使用现有应用程序配置设置(我们指的是 tests/assets/config.php

<?php

use \Hawkbit\Application;
use \Hawkbit\Doctrine\DoctrineService;
use \Hawkbit\Doctrine\DoctrineServiceProvider;

$app = new Application(require_once __DIR__ . '/config.php');

$entityFactoryClass = \ContainerInteropDoctrine\EntityManagerFactory::class;

$doctrineService = new DoctrineService([
   DoctrineService::resolveFactoryAlias($entityFactoryClass) => [$entityFactoryClass]
], $app);

$app->register(new DoctrineServiceProvider($doctrineService));

示例

完整配置

完整的配置在 DASPRiD/container-interop-doctrine/example/full-config.php 中提供。有关工厂的更多信息,请参阅 container-interop-doctrine 文档

Hawkbit 应用程序中的 Doctrine

<?php

/** @var \Hawkbit\Doctrine\DoctrineServiceInterface $doctrine */
$doctrine = $app[\Hawkbit\Doctrine\DoctrineServiceInterface::class];

$em = $doctrine->getEntityManager();

// or with from specific connection
$em = $doctrine->getEntityManager('connectionname');

Hawkbit 控制器中的 Doctrine

在控制器中访问 doctrine 服务。Hawkbit 默认将类注入到控制器中。

<?php

use \Hawkbit\Doctrine\DoctrineServiceInterface;

class MyController{
    
    /**
     * @var \Hawkbit\Doctrine\DoctrineServiceInterface 
     */
    private $doctrine = null;
    
    public function __construct(DoctrineServiceInterface $doctrine){
        $this->doctrine = $doctrine;
    }
    
    public function index(){
        $em = $this->doctrine->getEntityManager();
        
        // or with from specific connection
        $em = $this->doctrine->getEntityManager('connectionname');
    }
}

变更日志

有关最近更改的更多信息,请参阅 CHANGELOG

测试

$ composer test

贡献

有关详细信息,请参阅 CONTRIBUTING

安全

如果您发现任何安全相关的问题,请通过电子邮件 mjls@web.de 而不是使用问题跟踪器。

致谢

许可证

MIT 许可证(MIT)。有关更多信息,请参阅 许可证文件