本文整理汇总了PHP中Doctrine\ORM\ORMException::mismatchedEventManager方法的典型用法代码示例。如果您正苦于以下问题:PHP ORMException::mismatchedEventManager方法的具体用法?PHP ORMException::mismatchedEventManager怎么用?PHP ORMException::mismatchedEventManager使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\ORMException
的用法示例。
在下文中一共展示了ORMException::mismatchedEventManager方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
/**
* {@inheritdoc}
*/
public static function create($conn, Configuration $config, EventManager $eventManager = null)
{
if (!$config->getMetadataDriverImpl()) {
throw ORMException::missingMappingDriverImpl();
}
switch (true) {
case is_array($conn):
if (!$eventManager) {
$eventManager = new EventManager();
}
if (isset($conn['prefix']) && $conn['prefix']) {
$eventManager->addEventListener(Events::loadClassMetadata, new TablePrefix($conn['prefix']));
}
$conn = \Doctrine\DBAL\DriverManager::getConnection($conn, $config, $eventManager);
break;
case $conn instanceof Connection:
if ($eventManager !== null && $conn->getEventManager() !== $eventManager) {
throw ORMException::mismatchedEventManager();
}
break;
default:
throw new \InvalidArgumentException("Invalid argument: " . $conn);
}
return new self($conn, $config, $conn->getEventManager());
}
示例2: __construct
/**
* @param string|mixed|\ $dsn
* @param array $options
*
* @return AdapterInterface
*
* @link http://docs.doctrine-project.org/en/2.0.x/reference/configuration.html
* @link http://docs.doctrine-project.org/en/latest/reference/tools.html
* @link https://github.com/itmcd/StormIgniter/blob/master/app/libraries/DoctrineDb.php
* @link http://framework.zend.com/manual/2.2/en/user-guide/database-and-models.html
* @link http://piotrdeszynski.com/zend-framework-2-and-doctrine-2-integration.html
* @link http://www.jasongrimes.org/2012/01/using-doctrine-2-in-zend-framework-2/#toc-update-the-album-controller-to-use-doctrine-instead-of-zend_db
* @link http://framework.zend.com/manual/2.2/en/user-guide/database-and-models.html
*/
public function __construct($conn, $options = array())
{
$isDev = Environment::isDev();
// @see Doctrine\ORM\EntityManager#create()
$config = ArrayUtils::arrayMergeRecursiveRight($options, array('cache' => $isDev ? new Cache\ArrayCache() : new Cache\ApcCache(), 'queryCache' => $isDev ? new Cache\ArrayCache() : new Cache\ApcCache(), 'modelsProxiesPath' => getcwd() . '/cache/ModelProxies'));
// create Configuration object
if (is_array($options)) {
$config = $this->renderConfig($options);
if (!$config->getMetadataDriverImpl()) {
throw ORMException::missingMappingDriverImpl();
}
}
// test EventManager object
$eventManager = empty($options['eventManager']) ? new EventManager() : $options['eventManager'];
switch (true) {
case $conn instanceof \PDO:
$conn = array('driver' => 'pdo_' . $conn->getAttribute(\PDO::ATTR_DRIVER_NAME), 'pdo' => $conn);
$conn = \Doctrine\DBAL\DriverManager::getConnection($conn, $config, $eventManager);
break;
case is_string($conn):
if (($pos = strpos($conn, ':')) !== false) {
$driver = substr($conn, 0, $pos);
// @TODO: must implement like this, but for now throws an error about not knowing the database
// if ($driver !== 'oci8') {
// $conn = array(
// 'driver' => 'pdo_' . $driver,
// 'pdo' => new \PDO($conn),
// );
// } else {
// $conn = $this->mapDsnToDoctrine($conn);
// }
// ^ by dragosc@itmcd.ro / temporary replacement untill we discover why \PDO doesn't work
$dsn = new Dsn($conn);
$conn = $this->mapDsnToDoctrine($dsn->parse());
if ($driver !== 'oci8') {
$conn['driver'] = 'pdo_' . $conn['driver'];
}
// ^ END
}
$conn = \Doctrine\DBAL\DriverManager::getConnection($conn, $config, $eventManager);
break;
case is_array($conn):
$conn = \Doctrine\DBAL\DriverManager::getConnection($conn, $config, $eventManager);
break;
case $conn instanceof Connection:
if ($eventManager !== null && $conn->getEventManager() !== null) {
throw ORMException::mismatchedEventManager();
}
break;
default:
throw new AthemException\InvalidArgument("Invalid argument: " . json_encode($conn));
}
// parent constructor
// @see Doctrine\ORM\EntityManager#__construct()
parent::__construct($conn, $config, $conn->getEventManager());
}
示例3: createInstance
/**
* Factory method to create EntityManager instances.
*
* @param Connection $conn
* @param Configuration $config
* @param EventManager $eventManager
* @throws \Doctrine\ORM\ORMException
* @return ModelManager
*/
public static function createInstance(Connection $conn, Configuration $config, EventManager $eventManager = null)
{
if (!$config->getMetadataDriverImpl()) {
throw ORMException::missingMappingDriverImpl();
}
if ($eventManager !== null && $conn->getEventManager() !== $eventManager) {
throw ORMException::mismatchedEventManager();
}
return new self($conn, $config, $conn->getEventManager());
}
示例4: create
public static function create($conn, Configuration $config, EventManager $eventManager = null)
{
if (!$config->getMetadataDriverImpl()) {
throw ORMException::missingMappingDriverImpl();
}
if (is_array($conn)) {
$conn = \Doctrine\DBAL\DriverManager::getConnection($conn, $config, $eventManager ?: new EventManager());
} elseif ($conn instanceof Connection) {
if ($eventManager !== null && $conn->getEventManager() !== $eventManager) {
throw ORMException::mismatchedEventManager();
}
} else {
throw new \InvalidArgumentException("Invalid argument: " . $conn);
}
return new OroEntityManager($conn, $config, $conn->getEventManager());
}
示例5: create
/**
* Copied from Doctrine\ORM\EntityManager, cause return use new EntityManager() instead of new static()
*
* @param mixed $conn
* @param Configuration $config
* @param EventManager|null $eventManager
* @return EntityManager
* @throws ORMException
* @throws \Doctrine\DBAL\DBALException
*/
public static function create($conn, Configuration $config, EventManager $eventManager = null)
{
if (!$config->getMetadataDriverImpl()) {
throw ORMException::missingMappingDriverImpl();
}
switch (true) {
case is_array($conn):
$conn = \Doctrine\DBAL\DriverManager::getConnection($conn, $config, $eventManager ?: new EventManager());
break;
case $conn instanceof Connection:
if ($eventManager !== null && $conn->getEventManager() !== $eventManager) {
throw ORMException::mismatchedEventManager();
}
break;
default:
throw new \InvalidArgumentException("Invalid argument: " . $conn);
}
return new static($conn, $config, $conn->getEventManager());
}
示例6: create
/**
* Factory method to create EntityManager instances.
*
* @param \Doctrine\DBAL\Connection|array $conn
* @param \Doctrine\ORM\Configuration $config
* @param \Doctrine\Common\EventManager $eventManager
* @throws \Doctrine\ORM\ORMException
* @throws InvalidArgumentException
* @throws \Doctrine\ORM\ORMException
* @return EntityManager
*/
public static function create($conn, Doctrine\ORM\Configuration $config, Doctrine\Common\EventManager $eventManager = NULL)
{
if (!$config->getMetadataDriverImpl()) {
throw ORMException::missingMappingDriverImpl();
}
switch (TRUE) {
case is_array($conn):
$conn = DriverManager::getConnection($conn, $config, $eventManager ?: new Doctrine\Common\EventManager());
break;
case $conn instanceof Doctrine\DBAL\Connection:
if ($eventManager !== NULL && $conn->getEventManager() !== $eventManager) {
throw ORMException::mismatchedEventManager();
}
break;
default:
throw new InvalidArgumentException("Invalid connection");
}
return new EntityManager($conn, $config, $conn->getEventManager());
}
示例7: createConnection
/**
* Factory method to create Connection instances.
*
* @param array|Connection $connection An array with the connection parameters or an existing Connection instance.
* @param Configuration $config The Configuration instance to use.
* @param EventManager $eventManager The EventManager instance to use.
*
* @return Connection
*
* @throws \InvalidArgumentException
* @throws ORMException
*/
protected static function createConnection($connection, Configuration $config, EventManager $eventManager = null)
{
if (is_array($connection)) {
return DriverManager::getConnection($connection, $config, $eventManager ?: new EventManager());
}
if (!$connection instanceof Connection) {
throw new \InvalidArgumentException(sprintf('Invalid $connection argument of type %s given%s.', is_object($connection) ? get_class($connection) : gettype($connection), is_object($connection) ? '' : ': "' . $connection . '"'));
}
if ($eventManager !== null && $connection->getEventManager() !== $eventManager) {
throw ORMException::mismatchedEventManager();
}
return $connection;
}
示例8: createConnection
/**
* Factory method to create Connection instances.
*
* @param array|Connection $connection An array with the connection parameters or an existing Connection instance.
* @param Configuration $config The Configuration instance to use.
* @param EventManager $eventManager The EventManager instance to use.
*
* @return Connection
*
* @throws \InvalidArgumentException
* @throws ORMException
*/
protected static function createConnection($connection, Configuration $config, EventManager $eventManager = null)
{
if (is_array($connection)) {
return DriverManager::getConnection($connection, $config, $eventManager ?: new EventManager());
}
if (!$connection instanceof Connection) {
throw new \InvalidArgumentException("Invalid argument: " . $connection);
}
if ($eventManager !== null && $connection->getEventManager() !== $eventManager) {
throw ORMException::mismatchedEventManager();
}
return $connection;
}