You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.6 KiB
PHP
57 lines
1.6 KiB
PHP
<?php
|
|
|
|
|
|
namespace BitCommunism\Doctrine;
|
|
|
|
|
|
use Doctrine\Common\EventManager;
|
|
use Doctrine\DBAL\Connection;
|
|
use Doctrine\ORM\Configuration;
|
|
use Doctrine\ORM\EntityManager;
|
|
use Doctrine\ORM\ORMException;
|
|
|
|
class DefaultEntityManager extends EntityManager implements EntityManagerLike
|
|
{
|
|
protected $name;
|
|
|
|
/**
|
|
* DefaultEntityManager constructor.
|
|
* @param string $name
|
|
* @param Connection $conn
|
|
* @param Configuration $config
|
|
* @param EventManager $eventManager
|
|
*/
|
|
protected function __construct(Connection $conn, Configuration $config, EventManager $eventManager, string $name = null)
|
|
{
|
|
parent::__construct($conn, $config, $eventManager);
|
|
$this->name = $name;
|
|
}
|
|
|
|
/**
|
|
* @param string $name
|
|
* @param Configuration $connection
|
|
* @param Configuration $config
|
|
* @param EventManager|null $eventManager
|
|
* @return EntityManager|static
|
|
* @throws ORMException
|
|
*/
|
|
public static function create($connection, Configuration $config, EventManager $eventManager = null, string $name = null)
|
|
{
|
|
if (!$config->getMetadataDriverImpl()) {
|
|
throw ORMException::missingMappingDriverImpl();
|
|
}
|
|
|
|
$connection = static::createConnection($connection, $config, $eventManager);
|
|
|
|
return new static($connection, $config, $connection->getEventManager(), $name);
|
|
}
|
|
|
|
public function getEntityManager(string $name): DefaultEntityManager
|
|
{
|
|
if ($name !== $this->name) {
|
|
throw new \RuntimeException("This DefaultEntityManager instance only has em with the name '{$name}'");
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
} |