drkp/doctrine-metadata-configuration-factory
Composer 安装命令:
composer require drkp/doctrine-metadata-configuration-factory
包简介
Factory class to create Doctrine 2 ORM Configuration instances.
README 文档
README
Factory class to create Doctrine 2 ORM Configuration instances.
Provides simple way to decide what kind of mapping you prefer in your project.
Instalation
composer require drkp/doctrine-metadata-configuration-factory
Simple Usage:
<?php
$mapping = [
"dbal" => [
'driver' => 'pdo_sqlite',
'path' => __DIR__ . '/../../../data/db.sqlite'
],
"mappings" => [
[
"type" => "annotation",
"namespace" => "Some\\Namespace",
"path" => "/path/to/mapping/dir",
],
],
];
$config = new \DRKP\ZF3Doctrine\MetadataConfigurationFactory(
$mapping['mappings'],
$mapping['mappings'][0]['type']
);
$entityManager = \Doctrine\ORM\EntityManager::create(
$mapping['dbal'],
$config->make()
);
$repository = $entityManager->getRepository(\Some\Namespace::class);
Advanced usage
Multiple Entity Managers and multiple mapping types
<?php
use DRKP\ZF3Doctrine\MetadataConfigurationFactory;
use Doctrine\ORM\EntityManager;
$mapping = [
"dbal" => [
'driver' => 'pdo_sqlite',
'path' => __DIR__ . '/../../../data/db.sqlite'
],
"dbal1" => [
'host' => '127.0.0.1',
'port' => '3306',
'dbname' => '{db}',
'user' => '{user}',
'password' => '{pass}',
'charset' => 'utf8'
],
"mappings" => [
[
"type" => "annotation",
"namespace" => "Some\\Namespace",
"path" => "/path/to/mapping/dir",
],
[
"type" => "yaml",
"namespace" => "Some\\Other\\Namespace",
"path" => "/path/to/other/mapping/dir",
],
],
];
$config = new MetadataConfigurationFactory(
$mapping['mappings'],
$mapping['mappings'][0]['type']
);
$defaultEntityManager = EntityManager::create(
$mapping['dbal'],
$config->make()
);
$config1 = new MetadataConfigurationFactory(
$mapping['mappings'],
'yaml'
);
$secondaryEntityManager = EntityManager::create(
$mapping['dbal1'],
$config1->make()
);
$repository = $defaultEntityManager->getRepository(\Some\Namespace::class);
$secondaryRepository = $secondaryEntityManager->getRepository(\Some\Other\Namespace::class);
统计信息
- 总下载量: 30
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-08-31