small fixes

master v1.0.0
eater 7 years ago
parent 90a2f5594d
commit cb2ade897d
Signed by: eater
GPG Key ID: AD2560A0F84F0759

@ -22,25 +22,6 @@ return array_merge(
'doctrine.debug' => get('debug'), 'doctrine.debug' => get('debug'),
'doctrine.single-connection' => false, 'doctrine.single-connection' => false,
'doctrine.connections' => add([
'default',
'example',
]),
'doctrine.connection.default' => get('doctrine.connection'),
'doctrine.entity-paths.default' => get('doctrine.entity-paths'),
'doctrine.entity-paths' => add([
string('{basedir}/src/Entity')
]),
'doctrine.connection' => add([
'driver' => 'pdo_mysql',
'hostname' => 'localhost',
'password' => '',
'user' => 'root',
]),
'em' => get(EntityManager::class), 'em' => get(EntityManager::class),
EntityManager::class => factory(function (Container $c) { EntityManager::class => factory(function (Container $c) {
@ -65,8 +46,15 @@ return array_merge(
'entity-paths' => realpath(__DIR__ . '/../src/Entity') 'entity-paths' => realpath(__DIR__ . '/../src/Entity')
], ],
'default' => [ 'default' => [
'connection' => get('doctrine.connection'), 'connection' => add([
'entity-paths' => get('doctrine.entity-paths'), 'driver' => 'pdo_mysql',
'hostname' => 'localhost',
'password' => '',
'user' => 'root',
]),
'entity-paths' => add([
string('{basedir}/src/Entity')
]),
] ]
]) ])
); );

@ -5,6 +5,8 @@ namespace BitCommunism\Doctrine;
use DI\Container; use DI\Container;
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
use Doctrine\Common\Persistence\ObjectRepository;
use Doctrine\ORM\Tools\Setup; use Doctrine\ORM\Tools\Setup;
class ContextAwareEntityManager implements EntityManager class ContextAwareEntityManager implements EntityManager
@ -70,6 +72,10 @@ class ContextAwareEntityManager implements EntityManager
$entityPaths = $this->container->get($fullEntityPathKey); $entityPaths = $this->container->get($fullEntityPathKey);
if (!is_array($entityPaths)) {
$entityPaths = [$entityPaths];
}
foreach ($entityPaths as $entityPath) { foreach ($entityPaths as $entityPath) {
$this->entityManagerPathMap[$entityPath] = $name; $this->entityManagerPathMap[$entityPath] = $name;
} }
@ -246,12 +252,12 @@ class ContextAwareEntityManager implements EntityManager
} }
} }
public function getRepository($className) public function getRepository($className): ObjectRepository
{ {
return $this->getEntityManagerForClass($className)->getRepository($className); return $this->getEntityManagerForClass($className)->getRepository($className);
} }
public function getClassMetadata($className) public function getClassMetadata($className): ClassMetadata
{ {
return $this->getEntityManagerForClass($className)->getClassMetadata($className); return $this->getEntityManagerForClass($className)->getClassMetadata($className);
} }
@ -261,7 +267,7 @@ class ContextAwareEntityManager implements EntityManager
return $this->getEntityManagerForObject($object)->initializeObject($object); return $this->getEntityManagerForObject($object)->initializeObject($object);
} }
public function contains($object) public function contains($object): bool
{ {
return $this->getEntityManagerForObject($object)->contains($object); return $this->getEntityManagerForObject($object)->contains($object);
} }

@ -4,6 +4,9 @@
namespace BitCommunism\Doctrine; namespace BitCommunism\Doctrine;
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
use Doctrine\Common\Persistence\ObjectRepository;
interface EntityManager interface EntityManager
{ {
public function getResponsibleEntityManager(string $name): DefaultEntityManager; public function getResponsibleEntityManager(string $name): DefaultEntityManager;

@ -13,14 +13,16 @@ if (!function_exists(__NAMESPACE__ . '\\connections')) {
function connections($connections) { function connections($connections) {
$connectionNames = []; $connectionNames = [];
$entityPaths = []; $containerDef = [];
$connectionInfos = [];
foreach ($connections as $name => $connection) { foreach ($connections as $name => $connection) {
$connectionNames[] = $name; $connectionNames[] = $name;
$entityPaths['doctrine.entity-paths.' . $name] = $connection['entity-paths'] instanceof EntryReference ? $connection['entity-paths'] : add($connection['entity-paths'] ?? []); $entityPathsObject = $connection['entity-paths'];
$entityPaths['doctrine.connection.' . $name] = $connection['connection'] instanceof EntryReference ? $connection['connection'] : add($connection['connection'] ?? []); $connectionObject = $connection['connection'];
$containerDef['doctrine.entity-paths.' . $name] = $entityPathsObject;
$containerDef['doctrine.connection.' . $name] = $connectionObject;
} }
@ -28,8 +30,7 @@ if (!function_exists(__NAMESPACE__ . '\\connections')) {
[ [
'doctrine.connections' => add($connectionNames), 'doctrine.connections' => add($connectionNames),
], ],
$entityPaths, $containerDef
$connectionInfos
); );
} }
} }
Loading…
Cancel
Save