Doctrine 2 ORM integration for Hawkbit PSR-7 Micro PHP framework.
Hawkbit Doctrine is available on Packagist and can be installed using Composer. This can be done by running the following command or by updating your composer.json
file.
composer require hawkbit/doctrine
composer.json
{
"require": {
"hawkbit/doctrine": "~1.0"
}
}
Be sure to also include your Composer autoload file in your project:
<?php
require __DIR__ . '/vendor/autoload.php';
This project is also available for download as a .zip
file on GitHub. Visit the releases page, select the version you want, and click the "Source code (zip)" download button.
The following versions of PHP are supported by this version.
- PHP 5.5
- PHP 5.6
- PHP 7.0
- PHP 7.1
- HHVM
Setup with an existing application configuration (we refer to 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));
A full configuration is available on DASPRiD/container-interop-doctrine/example/full-config.php. Refer to container-interop-doctrine Documentation for further instructions on factories.
<?php
/** @var \Hawkbit\Doctrine\DoctrineServiceInterface $doctrine */
$doctrine = $app[\Hawkbit\Doctrine\DoctrineServiceInterface::class];
$em = $doctrine->getEntityManager();
// or with from specific connection
$em = $doctrine->getEntityManager('connectionname');
Access doctrine service in controller. Hawbit is inject classes to controllers by default.
<?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');
}
}
Please see CHANGELOG for more information what has changed recently.
$ composer test
Please see CONTRIBUTING for details.
If you discover any security related issues, please email mjls@web.de instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.