vendor/doctrine/orm/lib/Doctrine/ORM/ORMException.php line 144

Open in your IDE?
  1. <?php
  2. /*
  3.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  4.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  5.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  6.  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  7.  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  8.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  9.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  10.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  11.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  12.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  13.  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14.  *
  15.  * This software consists of voluntary contributions made by many individuals
  16.  * and is licensed under the MIT license. For more information, see
  17.  * <http://www.doctrine-project.org>.
  18.  */
  19. namespace Doctrine\ORM;
  20. use Doctrine\Common\Cache\Cache as CacheDriver;
  21. use Exception;
  22. /**
  23.  * Base exception class for all ORM exceptions.
  24.  *
  25.  * @author Roman Borschel <roman@code-factory.org>
  26.  * @since 2.0
  27.  */
  28. class ORMException extends Exception
  29. {
  30.     /**
  31.      * @return ORMException
  32.      */
  33.     public static function missingMappingDriverImpl()
  34.     {
  35.         return new self("It's a requirement to specify a Metadata Driver and pass it ".
  36.             "to Doctrine\\ORM\\Configuration::setMetadataDriverImpl().");
  37.     }
  38.     /**
  39.      * @param string $queryName
  40.      *
  41.      * @return ORMException
  42.      */
  43.     public static function namedQueryNotFound($queryName)
  44.     {
  45.         return new self('Could not find a named query by the name "' $queryName '"');
  46.     }
  47.     /**
  48.      * @param string $nativeQueryName
  49.      *
  50.      * @return ORMException
  51.      */
  52.     public static function namedNativeQueryNotFound($nativeQueryName)
  53.     {
  54.         return new self('Could not find a named native query by the name "' $nativeQueryName '"');
  55.     }
  56.     /**
  57.      * @param object $entity
  58.      * @param object $relatedEntity
  59.      *
  60.      * @return ORMException
  61.      */
  62.     public static function entityMissingForeignAssignedId($entity$relatedEntity)
  63.     {
  64.         return new self(
  65.             "Entity of type " get_class($entity) . " has identity through a foreign entity " get_class($relatedEntity) . ", " .
  66.             "however this entity has no identity itself. You have to call EntityManager#persist() on the related entity " .
  67.             "and make sure that an identifier was generated before trying to persist '" get_class($entity) . "'. In case " .
  68.             "of Post Insert ID Generation (such as MySQL Auto-Increment) this means you have to call " .
  69.             "EntityManager#flush() between both persist operations."
  70.         );
  71.     }
  72.     /**
  73.      * @param object $entity
  74.      * @param string $field
  75.      *
  76.      * @return ORMException
  77.      */
  78.     public static function entityMissingAssignedIdForField($entity$field)
  79.     {
  80.         return new self("Entity of type " get_class($entity) . " is missing an assigned ID for field  '" $field "'. " .
  81.             "The identifier generation strategy for this entity requires the ID field to be populated before ".
  82.             "EntityManager#persist() is called. If you want automatically generated identifiers instead " .
  83.             "you need to adjust the metadata mapping accordingly."
  84.         );
  85.     }
  86.     /**
  87.      * @param string $field
  88.      *
  89.      * @return ORMException
  90.      */
  91.     public static function unrecognizedField($field)
  92.     {
  93.         return new self("Unrecognized field: $field");
  94.     }
  95.     /**
  96.      *
  97.      * @param string $class
  98.      * @param string $association
  99.      * @param string $given
  100.      * @param string $expected
  101.      *
  102.      * @return \Doctrine\ORM\ORMInvalidArgumentException
  103.      */
  104.     public static function unexpectedAssociationValue($class$association$given$expected)
  105.     {
  106.         return new self(sprintf('Found entity of type %s on association %s#%s, but expecting %s'$given$class$association$expected));
  107.     }
  108.     /**
  109.      * @param string $className
  110.      * @param string $field
  111.      *
  112.      * @return ORMException
  113.      */
  114.     public static function invalidOrientation($className$field)
  115.     {
  116.         return new self("Invalid order by orientation specified for " $className "#" $field);
  117.     }
  118.     /**
  119.      * @param string $mode
  120.      *
  121.      * @return ORMException
  122.      */
  123.     public static function invalidFlushMode($mode)
  124.     {
  125.         return new self("'$mode' is an invalid flush mode.");
  126.     }
  127.     /**
  128.      * @return ORMException
  129.      */
  130.     public static function entityManagerClosed()
  131.     {
  132.         return new self("The EntityManager is closed.");
  133.     }
  134.     /**
  135.      * @param string $mode
  136.      *
  137.      * @return ORMException
  138.      */
  139.     public static function invalidHydrationMode($mode)
  140.     {
  141.         return new self("'$mode' is an invalid hydration mode.");
  142.     }
  143.     /**
  144.      * @return ORMException
  145.      */
  146.     public static function mismatchedEventManager()
  147.     {
  148.         return new self("Cannot use different EventManager instances for EntityManager and Connection.");
  149.     }
  150.     /**
  151.      * @param string $methodName
  152.      *
  153.      * @return ORMException
  154.      */
  155.     public static function findByRequiresParameter($methodName)
  156.     {
  157.         return new self("You need to pass a parameter to '".$methodName."'");
  158.     }
  159.     /**
  160.      * @param string $entityName
  161.      * @param string $fieldName
  162.      * @param string $method
  163.      *
  164.      * @return ORMException
  165.      */
  166.     public static function invalidFindByCall($entityName$fieldName$method)
  167.     {
  168.         return new self(
  169.             "Entity '".$entityName."' has no field '".$fieldName."'. ".
  170.             "You can therefore not call '".$method."' on the entities' repository"
  171.         );
  172.     }
  173.     /**
  174.      * @param string $entityName
  175.      * @param string $fieldName
  176.      * @param string $method
  177.      *
  178.      * @return ORMException
  179.      */
  180.     public static function invalidMagicCall($entityName$fieldName$method)
  181.     {
  182.         return new self(
  183.             "Entity '".$entityName."' has no field '".$fieldName."'. ".
  184.             "You can therefore not call '".$method."' on the entities' repository"
  185.         );
  186.     }
  187.     /**
  188.      * @param string $entityName
  189.      * @param string $associationFieldName
  190.      *
  191.      * @return ORMException
  192.      */
  193.     public static function invalidFindByInverseAssociation($entityName$associationFieldName)
  194.     {
  195.         return new self(
  196.             "You cannot search for the association field '".$entityName."#".$associationFieldName."', ".
  197.             "because it is the inverse side of an association. Find methods only work on owning side associations."
  198.         );
  199.     }
  200.     /**
  201.      * @return ORMException
  202.      */
  203.     public static function invalidResultCacheDriver()
  204.     {
  205.         return new self("Invalid result cache driver; it must implement Doctrine\\Common\\Cache\\Cache.");
  206.     }
  207.     /**
  208.      * @return ORMException
  209.      */
  210.     public static function notSupported()
  211.     {
  212.         return new self("This behaviour is (currently) not supported by Doctrine 2");
  213.     }
  214.     /**
  215.      * @return ORMException
  216.      */
  217.     public static function queryCacheNotConfigured()
  218.     {
  219.         return new self('Query Cache is not configured.');
  220.     }
  221.     /**
  222.      * @return ORMException
  223.      */
  224.     public static function metadataCacheNotConfigured()
  225.     {
  226.         return new self('Class Metadata Cache is not configured.');
  227.     }
  228.     /**
  229.      * @param \Doctrine\Common\Cache\Cache $cache
  230.      *
  231.      * @return ORMException
  232.      */
  233.     public static function queryCacheUsesNonPersistentCache(CacheDriver $cache)
  234.     {
  235.         return new self('Query Cache uses a non-persistent cache driver, ' get_class($cache) . '.');
  236.     }
  237.     /**
  238.      * @param \Doctrine\Common\Cache\Cache $cache
  239.      *
  240.      * @return ORMException
  241.      */
  242.     public static function metadataCacheUsesNonPersistentCache(CacheDriver $cache)
  243.     {
  244.         return new self('Metadata Cache uses a non-persistent cache driver, ' get_class($cache) . '.');
  245.     }
  246.     /**
  247.      * @return ORMException
  248.      */
  249.     public static function proxyClassesAlwaysRegenerating()
  250.     {
  251.         return new self('Proxy Classes are always regenerating.');
  252.     }
  253.     /**
  254.      * @param string $entityNamespaceAlias
  255.      *
  256.      * @return ORMException
  257.      */
  258.     public static function unknownEntityNamespace($entityNamespaceAlias)
  259.     {
  260.         return new self(
  261.             "Unknown Entity namespace alias '$entityNamespaceAlias'."
  262.         );
  263.     }
  264.     /**
  265.      * @param string $className
  266.      *
  267.      * @return ORMException
  268.      */
  269.     public static function invalidEntityRepository($className)
  270.     {
  271.         return new self("Invalid repository class '".$className."'. It must be a Doctrine\Common\Persistence\ObjectRepository.");
  272.     }
  273.     /**
  274.      * @param string $className
  275.      * @param string $fieldName
  276.      *
  277.      * @return ORMException
  278.      */
  279.     public static function missingIdentifierField($className$fieldName)
  280.     {
  281.         return new self("The identifier $fieldName is missing for a query of " $className);
  282.     }
  283.     /**
  284.      * @param string $className
  285.      * @param string[] $fieldNames
  286.      *
  287.      * @return ORMException
  288.      */
  289.     public static function unrecognizedIdentifierFields($className$fieldNames)
  290.     {
  291.         return new self(
  292.             "Unrecognized identifier fields: '" implode("', '"$fieldNames) . "' " .
  293.             "are not present on class '" $className "'."
  294.         );
  295.     }
  296.     /**
  297.      * @return ORMException
  298.      */
  299.     public static function cantUseInOperatorOnCompositeKeys()
  300.     {
  301.         return new self("Can't use IN operator on entities that have composite keys.");
  302.     }
  303. }