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.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),
EntityManager::class => factory(function (Container $c) {
@ -65,8 +46,15 @@ return array_merge(
'entity-paths' => realpath(__DIR__ . '/../src/Entity')
],
'default' => [
'connection' => get('doctrine.connection'),
'entity-paths' => get('doctrine.entity-paths'),
'connection' => add([
'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 Doctrine\Common\Persistence\Mapping\ClassMetadata;
use Doctrine\Common\Persistence\ObjectRepository;
use Doctrine\ORM\Tools\Setup;
class ContextAwareEntityManager implements EntityManager
@ -70,6 +72,10 @@ class ContextAwareEntityManager implements EntityManager
$entityPaths = $this->container->get($fullEntityPathKey);
if (!is_array($entityPaths)) {
$entityPaths = [$entityPaths];
}
foreach ($entityPaths as $entityPath) {
$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);
}
public function getClassMetadata($className)
public function getClassMetadata($className): ClassMetadata
{
return $this->getEntityManagerForClass($className)->getClassMetadata($className);
}
@ -261,7 +267,7 @@ class ContextAwareEntityManager implements EntityManager
return $this->getEntityManagerForObject($object)->initializeObject($object);
}
public function contains($object)
public function contains($object): bool
{
return $this->getEntityManagerForObject($object)->contains($object);
}

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

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