2009-10-28 13:31:47 +03:00
|
|
|
<?php
|
2010-04-26 15:02:30 +04:00
|
|
|
/*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* This software consists of voluntary contributions made by many individuals
|
2012-05-26 16:37:00 +04:00
|
|
|
* and is licensed under the MIT license. For more information, see
|
2010-04-26 15:02:30 +04:00
|
|
|
* <http://www.doctrine-project.org>.
|
|
|
|
*/
|
2009-10-28 13:31:47 +03:00
|
|
|
|
|
|
|
namespace Doctrine\ORM;
|
|
|
|
|
2014-11-11 10:31:36 +03:00
|
|
|
use Doctrine\Common\Cache\Cache as CacheDriver;
|
2010-05-11 01:51:56 +04:00
|
|
|
use Exception;
|
|
|
|
|
2009-12-18 16:20:22 +03:00
|
|
|
/**
|
|
|
|
* Base exception class for all ORM exceptions.
|
2010-02-24 05:25:09 +03:00
|
|
|
*
|
2009-12-18 16:20:22 +03:00
|
|
|
* @author Roman Borschel <roman@code-factory.org>
|
|
|
|
* @since 2.0
|
|
|
|
*/
|
2010-05-11 01:51:56 +04:00
|
|
|
class ORMException extends Exception
|
2009-10-28 13:31:47 +03:00
|
|
|
{
|
2012-12-01 20:28:06 +04:00
|
|
|
/**
|
|
|
|
* @return ORMException
|
|
|
|
*/
|
2010-04-10 19:35:18 +04:00
|
|
|
public static function missingMappingDriverImpl()
|
|
|
|
{
|
|
|
|
return new self("It's a requirement to specify a Metadata Driver and pass it ".
|
2012-07-08 16:58:06 +04:00
|
|
|
"to Doctrine\\ORM\\Configuration::setMetadataDriverImpl().");
|
|
|
|
}
|
|
|
|
|
2012-12-01 20:28:06 +04:00
|
|
|
/**
|
|
|
|
* @param string $queryName
|
|
|
|
*
|
|
|
|
* @return ORMException
|
|
|
|
*/
|
2012-07-08 16:58:06 +04:00
|
|
|
public static function namedQueryNotFound($queryName)
|
|
|
|
{
|
|
|
|
return new self('Could not find a named query by the name "' . $queryName . '"');
|
|
|
|
}
|
|
|
|
|
2012-12-01 20:28:06 +04:00
|
|
|
/**
|
|
|
|
* @param string $nativeQueryName
|
|
|
|
*
|
|
|
|
* @return ORMException
|
|
|
|
*/
|
2012-07-08 16:58:06 +04:00
|
|
|
public static function namedNativeQueryNotFound($nativeQueryName)
|
|
|
|
{
|
|
|
|
return new self('Could not find a named native query by the name "' . $nativeQueryName . '"');
|
2010-04-10 19:35:18 +04:00
|
|
|
}
|
2011-09-29 11:31:06 +04:00
|
|
|
|
2012-12-01 20:28:06 +04:00
|
|
|
/**
|
|
|
|
* @param object $entity
|
|
|
|
* @param object $relatedEntity
|
|
|
|
*
|
|
|
|
* @return ORMException
|
|
|
|
*/
|
2011-06-05 14:54:29 +04:00
|
|
|
public static function entityMissingForeignAssignedId($entity, $relatedEntity)
|
|
|
|
{
|
|
|
|
return new self(
|
2011-06-16 01:15:46 +04:00
|
|
|
"Entity of type " . get_class($entity) . " has identity through a foreign entity " . get_class($relatedEntity) . ", " .
|
2011-07-26 11:59:21 +04:00
|
|
|
"however this entity has no identity itself. You have to call EntityManager#persist() on the related entity " .
|
2011-07-26 12:03:23 +04:00
|
|
|
"and make sure that an identifier was generated before trying to persist '" . get_class($entity) . "'. In case " .
|
2014-11-12 12:10:06 +03:00
|
|
|
"of Post Insert ID Generation (such as MySQL Auto-Increment) this means you have to call " .
|
2011-06-05 14:54:29 +04:00
|
|
|
"EntityManager#flush() between both persist operations."
|
|
|
|
);
|
|
|
|
}
|
2010-04-10 19:35:18 +04:00
|
|
|
|
2012-12-01 20:28:06 +04:00
|
|
|
/**
|
|
|
|
* @param object $entity
|
|
|
|
* @param string $field
|
|
|
|
*
|
|
|
|
* @return ORMException
|
|
|
|
*/
|
2011-09-29 11:31:06 +04:00
|
|
|
public static function entityMissingAssignedIdForField($entity, $field)
|
|
|
|
{
|
|
|
|
return new self("Entity of type " . get_class($entity) . " is missing an assigned ID for field '" . $field . "'. " .
|
|
|
|
"The identifier generation strategy for this entity requires the ID field to be populated before ".
|
|
|
|
"EntityManager#persist() is called. If you want automatically generated identifiers instead " .
|
2011-06-05 14:54:29 +04:00
|
|
|
"you need to adjust the metadata mapping accordingly."
|
|
|
|
);
|
2009-10-28 13:31:47 +03:00
|
|
|
}
|
2012-07-08 16:58:06 +04:00
|
|
|
|
2012-12-01 20:28:06 +04:00
|
|
|
/**
|
|
|
|
* @param string $field
|
|
|
|
*
|
|
|
|
* @return ORMException
|
|
|
|
*/
|
2009-10-28 18:32:55 +03:00
|
|
|
public static function unrecognizedField($field)
|
|
|
|
{
|
|
|
|
return new self("Unrecognized field: $field");
|
|
|
|
}
|
2010-02-24 05:25:09 +03:00
|
|
|
|
2013-02-14 02:42:13 +04:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param string $class
|
|
|
|
* @param string $association
|
|
|
|
* @param string $given
|
|
|
|
* @param string $expected
|
|
|
|
*
|
|
|
|
* @return \Doctrine\ORM\ORMInvalidArgumentException
|
|
|
|
*/
|
2013-10-08 02:53:32 +04:00
|
|
|
public static function unexpectedAssociationValue($class, $association, $given, $expected)
|
2013-02-14 02:42:13 +04:00
|
|
|
{
|
|
|
|
return new self(sprintf('Found entity of type %s on association %s#%s, but expecting %s', $given, $class, $association, $expected));
|
|
|
|
}
|
|
|
|
|
2011-11-21 18:04:14 +04:00
|
|
|
/**
|
|
|
|
* @param string $className
|
|
|
|
* @param string $field
|
2012-12-01 20:28:06 +04:00
|
|
|
*
|
|
|
|
* @return ORMException
|
2011-11-21 18:04:14 +04:00
|
|
|
*/
|
|
|
|
public static function invalidOrientation($className, $field)
|
|
|
|
{
|
|
|
|
return new self("Invalid order by orientation specified for " . $className . "#" . $field);
|
|
|
|
}
|
|
|
|
|
2012-12-01 20:28:06 +04:00
|
|
|
/**
|
|
|
|
* @param string $mode
|
|
|
|
*
|
|
|
|
* @return ORMException
|
|
|
|
*/
|
2009-12-18 16:20:22 +03:00
|
|
|
public static function invalidFlushMode($mode)
|
|
|
|
{
|
|
|
|
return new self("'$mode' is an invalid flush mode.");
|
|
|
|
}
|
2010-02-24 05:25:09 +03:00
|
|
|
|
2012-12-01 20:28:06 +04:00
|
|
|
/**
|
|
|
|
* @return ORMException
|
|
|
|
*/
|
2009-12-18 16:20:22 +03:00
|
|
|
public static function entityManagerClosed()
|
|
|
|
{
|
|
|
|
return new self("The EntityManager is closed.");
|
|
|
|
}
|
2010-02-24 05:25:09 +03:00
|
|
|
|
2012-12-01 20:28:06 +04:00
|
|
|
/**
|
|
|
|
* @param string $mode
|
|
|
|
*
|
|
|
|
* @return ORMException
|
|
|
|
*/
|
2010-01-30 00:36:05 +03:00
|
|
|
public static function invalidHydrationMode($mode)
|
|
|
|
{
|
|
|
|
return new self("'$mode' is an invalid hydration mode.");
|
|
|
|
}
|
2010-02-24 05:25:09 +03:00
|
|
|
|
2012-12-01 20:28:06 +04:00
|
|
|
/**
|
|
|
|
* @return ORMException
|
|
|
|
*/
|
2010-01-30 00:36:05 +03:00
|
|
|
public static function mismatchedEventManager()
|
|
|
|
{
|
|
|
|
return new self("Cannot use different EventManager instances for EntityManager and Connection.");
|
|
|
|
}
|
2010-02-24 05:25:09 +03:00
|
|
|
|
2012-12-01 20:28:06 +04:00
|
|
|
/**
|
|
|
|
* @param string $methodName
|
|
|
|
*
|
|
|
|
* @return ORMException
|
|
|
|
*/
|
2010-03-03 04:30:00 +03:00
|
|
|
public static function findByRequiresParameter($methodName)
|
|
|
|
{
|
2010-02-24 05:25:09 +03:00
|
|
|
return new self("You need to pass a parameter to '".$methodName."'");
|
|
|
|
}
|
|
|
|
|
2012-12-01 20:28:06 +04:00
|
|
|
/**
|
|
|
|
* @param string $entityName
|
|
|
|
* @param string $fieldName
|
|
|
|
* @param string $method
|
|
|
|
*
|
|
|
|
* @return ORMException
|
|
|
|
*/
|
2010-03-03 04:30:00 +03:00
|
|
|
public static function invalidFindByCall($entityName, $fieldName, $method)
|
|
|
|
{
|
2010-02-24 05:25:09 +03:00
|
|
|
return new self(
|
|
|
|
"Entity '".$entityName."' has no field '".$fieldName."'. ".
|
|
|
|
"You can therefore not call '".$method."' on the entities' repository"
|
|
|
|
);
|
|
|
|
}
|
2010-03-03 04:30:00 +03:00
|
|
|
|
2012-12-01 20:28:06 +04:00
|
|
|
/**
|
|
|
|
* @param string $entityName
|
|
|
|
* @param string $associationFieldName
|
|
|
|
*
|
|
|
|
* @return ORMException
|
|
|
|
*/
|
2010-09-28 00:13:14 +04:00
|
|
|
public static function invalidFindByInverseAssociation($entityName, $associationFieldName)
|
|
|
|
{
|
|
|
|
return new self(
|
|
|
|
"You cannot search for the association field '".$entityName."#".$associationFieldName."', ".
|
|
|
|
"because it is the inverse side of an association. Find methods only work on owning side associations."
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-12-01 20:28:06 +04:00
|
|
|
/**
|
|
|
|
* @return ORMException
|
|
|
|
*/
|
|
|
|
public static function invalidResultCacheDriver()
|
|
|
|
{
|
2012-07-08 16:58:06 +04:00
|
|
|
return new self("Invalid result cache driver; it must implement Doctrine\\Common\\Cache\\Cache.");
|
2010-03-05 19:35:00 +03:00
|
|
|
}
|
|
|
|
|
2012-12-01 20:28:06 +04:00
|
|
|
/**
|
|
|
|
* @return ORMException
|
|
|
|
*/
|
|
|
|
public static function notSupported()
|
|
|
|
{
|
2010-03-05 19:35:00 +03:00
|
|
|
return new self("This behaviour is (currently) not supported by Doctrine 2");
|
|
|
|
}
|
|
|
|
|
2012-12-01 20:28:06 +04:00
|
|
|
/**
|
|
|
|
* @return ORMException
|
|
|
|
*/
|
2010-03-03 04:30:00 +03:00
|
|
|
public static function queryCacheNotConfigured()
|
|
|
|
{
|
|
|
|
return new self('Query Cache is not configured.');
|
|
|
|
}
|
|
|
|
|
2012-12-01 20:28:06 +04:00
|
|
|
/**
|
|
|
|
* @return ORMException
|
|
|
|
*/
|
2010-03-03 04:30:00 +03:00
|
|
|
public static function metadataCacheNotConfigured()
|
|
|
|
{
|
|
|
|
return new self('Class Metadata Cache is not configured.');
|
|
|
|
}
|
|
|
|
|
2014-11-08 17:05:56 +03:00
|
|
|
/**
|
2014-11-11 10:31:36 +03:00
|
|
|
* @param \Doctrine\Common\Cache\Cache $cache
|
2014-12-19 22:18:45 +03:00
|
|
|
*
|
|
|
|
* @return ORMException
|
|
|
|
*/
|
|
|
|
public static function queryCacheUsesNonPersistentCache(CacheDriver $cache)
|
|
|
|
{
|
|
|
|
return new self('Query Cache uses a non-persistent cache driver, ' . get_class($cache) . '.');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param \Doctrine\Common\Cache\Cache $cache
|
2014-11-11 09:35:52 +03:00
|
|
|
*
|
2014-11-08 17:05:56 +03:00
|
|
|
* @return ORMException
|
|
|
|
*/
|
2014-11-11 10:31:36 +03:00
|
|
|
public static function metadataCacheUsesNonPersistentCache(CacheDriver $cache)
|
2014-11-08 17:05:56 +03:00
|
|
|
{
|
2014-11-11 09:35:52 +03:00
|
|
|
return new self('Metadata Cache uses a non-persistent cache driver, ' . get_class($cache) . '.');
|
2014-11-08 17:05:56 +03:00
|
|
|
}
|
|
|
|
|
2012-12-01 20:28:06 +04:00
|
|
|
/**
|
|
|
|
* @return ORMException
|
|
|
|
*/
|
2010-03-03 04:30:00 +03:00
|
|
|
public static function proxyClassesAlwaysRegenerating()
|
|
|
|
{
|
|
|
|
return new self('Proxy Classes are always regenerating.');
|
|
|
|
}
|
|
|
|
|
2012-12-01 20:28:06 +04:00
|
|
|
/**
|
|
|
|
* @param string $entityNamespaceAlias
|
|
|
|
*
|
|
|
|
* @return ORMException
|
|
|
|
*/
|
2010-03-03 04:30:00 +03:00
|
|
|
public static function unknownEntityNamespace($entityNamespaceAlias)
|
|
|
|
{
|
|
|
|
return new self(
|
|
|
|
"Unknown Entity namespace alias '$entityNamespaceAlias'."
|
|
|
|
);
|
|
|
|
}
|
2011-09-29 11:31:06 +04:00
|
|
|
|
2012-12-01 20:28:06 +04:00
|
|
|
/**
|
|
|
|
* @param string $className
|
|
|
|
*
|
|
|
|
* @return ORMException
|
|
|
|
*/
|
2011-09-29 11:31:06 +04:00
|
|
|
public static function invalidEntityRepository($className)
|
2011-09-09 00:21:06 +04:00
|
|
|
{
|
2012-07-26 23:50:51 +04:00
|
|
|
return new self("Invalid repository class '".$className."'. It must be a Doctrine\Common\Persistence\ObjectRepository.");
|
2013-02-14 02:42:13 +04:00
|
|
|
}
|
|
|
|
|
2012-12-01 20:28:06 +04:00
|
|
|
/**
|
|
|
|
* @param string $className
|
|
|
|
* @param string $fieldName
|
|
|
|
*
|
|
|
|
* @return ORMException
|
|
|
|
*/
|
2011-12-02 00:18:39 +04:00
|
|
|
public static function missingIdentifierField($className, $fieldName)
|
|
|
|
{
|
|
|
|
return new self("The identifier $fieldName is missing for a query of " . $className);
|
|
|
|
}
|
2012-07-05 23:52:40 +04:00
|
|
|
|
2014-03-23 12:58:31 +04:00
|
|
|
/**
|
|
|
|
* @param string $className
|
|
|
|
* @param string $fieldName
|
|
|
|
*
|
|
|
|
* @return ORMException
|
|
|
|
*/
|
|
|
|
public static function unrecognizedIdentifierFields($className, $fieldNames)
|
|
|
|
{
|
|
|
|
return new self(
|
|
|
|
"Unrecognized identifier fields: '" . implode("', '", $fieldNames) . "' " .
|
|
|
|
"are not present on class '" . $className . "'."
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-12-01 20:28:06 +04:00
|
|
|
/**
|
|
|
|
* @param string $functionName
|
|
|
|
*
|
|
|
|
* @return ORMException
|
|
|
|
*/
|
2012-07-05 23:52:40 +04:00
|
|
|
public static function overwriteInternalDQLFunctionNotAllowed($functionName)
|
|
|
|
{
|
|
|
|
return new self("It is not allowed to overwrite internal function '$functionName' in the DQL parser through user-defined functions.");
|
|
|
|
}
|
2015-01-19 01:20:47 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return ORMException
|
|
|
|
*/
|
|
|
|
public static function cantUseInOperatorOnCompositeKeys()
|
|
|
|
{
|
|
|
|
return new self("Can't use IN operator on entities that have composite keys.");
|
|
|
|
}
|
2009-10-28 13:31:47 +03:00
|
|
|
}
|