当前位置: 首页>>代码示例>>PHP>>正文


PHP ORM\ORMException类代码示例

本文整理汇总了PHP中Doctrine\ORM\ORMException的典型用法代码示例。如果您正苦于以下问题:PHP ORMException类的具体用法?PHP ORMException怎么用?PHP ORMException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ORMException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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());
 }
开发者ID:minchal,项目名称:vero,代码行数:28,代码来源:EntityManager.php

示例2: generate

 /**
  * Returns the identifier assigned to the given entity.
  *
  * @param object $entity
  * @return mixed
  * @override
  */
 public function generate(EntityManager $em, $entity)
 {
     $class = $em->getClassMetadata(get_class($entity));
     $identifier = array();
     if ($class->isIdentifierComposite) {
         $idFields = $class->getIdentifierFieldNames();
         foreach ($idFields as $idField) {
             $value = $class->getReflectionProperty($idField)->getValue($entity);
             if (isset($value)) {
                 if (is_object($value)) {
                     // NOTE: Single Columns as associated identifiers only allowed - this constraint it is enforced.
                     $identifier[$idField] = current($em->getUnitOfWork()->getEntityIdentifier($value));
                 } else {
                     $identifier[$idField] = $value;
                 }
             } else {
                 throw ORMException::entityMissingAssignedId($entity);
             }
         }
     } else {
         $idField = $class->identifier[0];
         $value = $class->reflFields[$idField]->getValue($entity);
         if (isset($value)) {
             if (is_object($value)) {
                 // NOTE: Single Columns as associated identifiers only allowed - this constraint it is enforced.
                 $identifier[$idField] = current($em->getUnitOfWork()->getEntityIdentifier($value));
             } else {
                 $identifier[$idField] = $value;
             }
         } else {
             throw ORMException::entityMissingAssignedId($entity);
         }
     }
     return $identifier;
 }
开发者ID:faridos,项目名称:ServerGroveLiveChat,代码行数:42,代码来源:AssignedGenerator.php

示例3: generate

 /**
  * Returns the identifier assigned to the given entity.
  *
  * @param object $entity
  * @return mixed
  * @override
  */
 public function generate(EntityManager $em, $entity)
 {
     $class = $em->getClassMetadata(get_class($entity));
     $identifier = array();
     if ($class->isIdentifierComposite) {
         $idFields = $class->getIdentifierFieldNames();
         foreach ($idFields as $idField) {
             $value = $class->getReflectionProperty($idField)->getValue($entity);
             if (isset($value)) {
                 $identifier[$idField] = $value;
             } else {
                 throw ORMException::entityMissingAssignedId($entity);
             }
         }
     } else {
         $idField = $class->identifier[0];
         $value = $class->reflFields[$idField]->getValue($entity);
         if (isset($value)) {
             $identifier[$idField] = $value;
         } else {
             throw ORMException::entityMissingAssignedId($entity);
         }
     }
     return $identifier;
 }
开发者ID:EstebanFuentealba,项目名称:PHPCodeCreator,代码行数:32,代码来源:AssignedGenerator.php

示例4: __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());
 }
开发者ID:athemcms,项目名称:netis,代码行数:70,代码来源:EntityManager.php

示例5: 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());
 }
开发者ID:GerDner,项目名称:luck-docker,代码行数:19,代码来源:ModelManager.php

示例6: getAliasNamespace

 /**
  * Resolves a registered namespace alias to the full namespace.
  *
  * This method looks for the alias in all registered entity managers.
  *
  * @see \Doctrine\ORM\Configuration::getEntityNamespace
  * @param string $alias The alias
  * @throws \Doctrine\ORM\ORMException
  * @return string The full namespace
  */
 public function getAliasNamespace($alias)
 {
     foreach (array_keys($this->getManagers()) as $name) {
         try {
             return $this->getManager($name)->getConfiguration()->getEntityNamespace($alias);
         } catch (ORMException $e) {
         }
     }
     throw ORMException::unknownEntityNamespace($alias);
 }
开发者ID:kdyby,项目名称:doctrine,代码行数:20,代码来源:Registry.php

示例7: getAliasNamespace

 /**
  * {@inheritdoc}
  */
 public function getAliasNamespace($alias)
 {
     /** @var EntityManager $entityManager */
     foreach ([$this->entityManager] as $entityManager) {
         try {
             return $entityManager->getConfiguration()->getEntityNamespace($alias);
         } catch (ORMException $e) {
         }
     }
     throw ORMException::unknownEntityNamespace($alias);
 }
开发者ID:sinergi,项目名称:sage50,代码行数:14,代码来源:Doctrine.php

示例8: getAliasNamespace

 /**
  * Resolves a registered namespace alias to the full namespace.
  *
  * This method looks for the alias in all registered object managers.
  *
  * @param string $alias The alias.
  * @return string The full namespace.
  * @throws ORMException
  */
 public function getAliasNamespace($alias)
 {
     foreach (array_keys($this->getManagers()) as $name) {
         try {
             if (($em = $this->getManager($name)) instanceof EntityManager) {
                 return $em->getConfiguration()->getEntityNamespace($alias);
             }
         } catch (ORMException $e) {
             // If any exception is throw when attempting to retrieve then have our custom one thrown
         }
     }
     throw ORMException::unknownEntityNamespace($alias);
 }
开发者ID:jdrich,项目名称:drest,代码行数:22,代码来源:EntityManagerRegistry.php

示例9: 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());
 }
开发者ID:xamin123,项目名称:platform,代码行数:16,代码来源:OroEntityManager.php

示例10: generate

 /**
  * Returns the identifier assigned to the given entity.
  *
  * {@inheritDoc}
  *
  * @throws \Doctrine\ORM\ORMException
  */
 public function generate(EntityManager $em, $entity)
 {
     $class = $em->getClassMetadata(get_class($entity));
     $idFields = $class->getIdentifierFieldNames();
     $identifier = array();
     foreach ($idFields as $idField) {
         $value = $class->getFieldValue($entity, $idField);
         if (!isset($value)) {
             throw ORMException::entityMissingAssignedIdForField($entity, $idField);
         }
         if (isset($class->associationMappings[$idField])) {
             // NOTE: Single Columns as associated identifiers only allowed - this constraint it is enforced.
             $value = $em->getUnitOfWork()->getSingleIdentifierValue($value);
         }
         $identifier[$idField] = $value;
     }
     return $identifier;
 }
开发者ID:karvannan-thi,项目名称:doctrine2,代码行数:25,代码来源:AssignedGenerator.php

示例11: 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());
 }
开发者ID:steevanb,项目名称:doctrine-stats,代码行数:29,代码来源:EntityManager.php

示例12: 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());
 }
开发者ID:jirinapravnik,项目名称:common,代码行数:30,代码来源:EntityManager.php

示例13: getSelectConditionStatementColumnSQL

    /**
     * Builds the left-hand-side of a where condition statement.
     *
     * @param string     $field
     * @param array|null $assoc
     *
     * @return string
     *
     * @throws \Doctrine\ORM\ORMException
     */
    protected function getSelectConditionStatementColumnSQL($field, $assoc = null)
    {
        if (isset($this->class->columnNames[$field])) {
            $className = (isset($this->class->fieldMappings[$field]['inherited']))
                ? $this->class->fieldMappings[$field]['inherited']
                : $this->class->name;

            return $this->getSQLTableAlias($className) . '.' . $this->quoteStrategy->getColumnName($field, $this->class, $this->platform);
        }

        if (isset($this->class->associationMappings[$field])) {

            if ( ! $this->class->associationMappings[$field]['isOwningSide']) {
                throw ORMException::invalidFindByInverseAssociation($this->class->name, $field);
            }

            $joinColumn = $this->class->associationMappings[$field]['joinColumns'][0];
            $className  = (isset($this->class->associationMappings[$field]['inherited']))
                ? $this->class->associationMappings[$field]['inherited']
                : $this->class->name;

            return $this->getSQLTableAlias($className) . '.' . $this->quoteStrategy->getJoinColumnName($joinColumn, $this->class, $this->platform);
        }

        if ($assoc !== null && strpos($field, " ") === false && strpos($field, "(") === false) {
            // very careless developers could potentially open up this normally hidden api for userland attacks,
            // therefore checking for spaces and function calls which are not allowed.

            // found a join column condition, not really a "field"
            return $field;
        }

        throw ORMException::unrecognizedField($field);
    }
开发者ID:nattaphat,项目名称:hgis,代码行数:44,代码来源:BasicEntityPersister.php

示例14: _getCollectionOrderBySQL

 /**
  * Generate ORDER BY SQL snippet for ordered collections.
  * 
  * @param array $orderBy
  * @param string $baseTableAlias
  * @return string
  */
 protected function _getCollectionOrderBySQL(array $orderBy, $baseTableAlias)
 {
     $orderBySql = '';
     foreach ($orderBy as $fieldName => $orientation) {
         if (!isset($this->_class->fieldMappings[$fieldName])) {
             ORMException::unrecognizedField($fieldName);
         }
         $tableAlias = isset($this->_class->fieldMappings[$fieldName]['inherited']) ? $this->_getSQLTableAlias($this->_em->getClassMetadata($this->_class->fieldMappings[$fieldName]['inherited'])) : $baseTableAlias;
         $columnName = $this->_class->getQuotedColumnName($fieldName, $this->_platform);
         if ($orderBySql != '') {
             $orderBySql .= ', ';
         } else {
             $orderBySql = ' ORDER BY ';
         }
         $orderBySql .= $tableAlias . '.' . $columnName . ' ' . $orientation;
     }
     return $orderBySql;
 }
开发者ID:poulikov,项目名称:readlater,代码行数:25,代码来源:StandardEntityPersister.php

示例15: getSelectConditionStatementColumnSQL

 /**
  * Builds the left-hand-side of a where condition statement.
  *
  * @param string     $field
  * @param array|null $assoc
  *
  * @return string[]
  *
  * @throws \Doctrine\ORM\ORMException
  */
 private function getSelectConditionStatementColumnSQL($field, $assoc = null)
 {
     if (isset($this->class->columnNames[$field])) {
         $className = isset($this->class->fieldMappings[$field]['inherited']) ? $this->class->fieldMappings[$field]['inherited'] : $this->class->name;
         return array($this->getSQLTableAlias($className) . '.' . $this->quoteStrategy->getColumnName($field, $this->class, $this->platform));
     }
     if (isset($this->class->associationMappings[$field])) {
         $association = $this->class->associationMappings[$field];
         // Many-To-Many requires join table check for joinColumn
         $columns = array();
         $class = $this->class;
         if ($association['type'] === ClassMetadata::MANY_TO_MANY) {
             if (!$association['isOwningSide']) {
                 $association = $assoc;
             }
             $joinTableName = $this->quoteStrategy->getJoinTableName($association, $class, $this->platform);
             $joinColumns = $assoc['isOwningSide'] ? $association['joinTable']['joinColumns'] : $association['joinTable']['inverseJoinColumns'];
             foreach ($joinColumns as $joinColumn) {
                 $columns[] = $joinTableName . '.' . $this->quoteStrategy->getJoinColumnName($joinColumn, $class, $this->platform);
             }
         } else {
             if (!$association['isOwningSide']) {
                 throw ORMException::invalidFindByInverseAssociation($this->class->name, $field);
             }
             $className = isset($association['inherited']) ? $association['inherited'] : $this->class->name;
             foreach ($association['joinColumns'] as $joinColumn) {
                 $columns[] = $this->getSQLTableAlias($className) . '.' . $this->quoteStrategy->getJoinColumnName($joinColumn, $this->class, $this->platform);
             }
         }
         return $columns;
     }
     if ($assoc !== null && strpos($field, " ") === false && strpos($field, "(") === false) {
         // very careless developers could potentially open up this normally hidden api for userland attacks,
         // therefore checking for spaces and function calls which are not allowed.
         // found a join column condition, not really a "field"
         return array($field);
     }
     throw ORMException::unrecognizedField($field);
 }
开发者ID:BusinessCookies,项目名称:CoffeeMachineProject,代码行数:49,代码来源:BasicEntityPersister.php


注:本文中的Doctrine\ORM\ORMException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。