Przeglądaj źródła

changed the exceptions by following best practices

gediminasm 14 lat temu
rodzic
commit
51d9959184
28 zmienionych plików z 155 dodań i 348 usunięć
  1. 24 0
      lib/Gedmo/Exception.php
  2. 19 0
      lib/Gedmo/Exception/InvalidArgumentException.php
  3. 19 0
      lib/Gedmo/Exception/RuntimeException.php
  4. 19 0
      lib/Gedmo/Exception/UnexpectedValueException.php
  5. 1 1
      lib/Gedmo/Mapping/Driver/Chain.php
  6. 1 2
      lib/Gedmo/Mapping/Driver/File.php
  7. 0 35
      lib/Gedmo/Mapping/DriverException.php
  8. 1 1
      lib/Gedmo/Mapping/ExtensionMetadataFactory.php
  9. 0 25
      lib/Gedmo/Sluggable/Exception.php
  10. 7 7
      lib/Gedmo/Sluggable/Mapping/Driver/Annotation.php
  11. 5 5
      lib/Gedmo/Sluggable/Mapping/Driver/Yaml.php
  12. 0 35
      lib/Gedmo/Sluggable/Mapping/MappingException.php
  13. 1 1
      lib/Gedmo/Sluggable/SluggableListener.php
  14. 0 20
      lib/Gedmo/Timestampable/Exception.php
  15. 5 5
      lib/Gedmo/Timestampable/Mapping/Driver/Annotation.php
  16. 4 4
      lib/Gedmo/Timestampable/Mapping/Driver/Yaml.php
  17. 0 35
      lib/Gedmo/Timestampable/Mapping/MappingException.php
  18. 1 1
      lib/Gedmo/Timestampable/TimestampableListener.php
  19. 0 35
      lib/Gedmo/Translatable/Exception.php
  20. 6 6
      lib/Gedmo/Translatable/Mapping/Driver/Annotation.php
  21. 3 3
      lib/Gedmo/Translatable/Mapping/Driver/Yaml.php
  22. 0 35
      lib/Gedmo/Translatable/Mapping/MappingException.php
  23. 10 13
      lib/Gedmo/Translatable/TranslationListener.php
  24. 0 17
      lib/Gedmo/Tree/Exception.php
  25. 9 9
      lib/Gedmo/Tree/Mapping/Driver/Annotation.php
  26. 6 6
      lib/Gedmo/Tree/Mapping/Driver/Yaml.php
  27. 0 35
      lib/Gedmo/Tree/Mapping/MappingException.php
  28. 14 12
      lib/Gedmo/Tree/Repository/TreeNodeRepository.php

+ 24 - 0
lib/Gedmo/Exception.php

@@ -0,0 +1,24 @@
+<?php
+
+namespace Gedmo;
+
+/**
+ * Common package exception interface to allow
+ * users of caching only this package specific
+ * exceptions thrown
+ * 
+ * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
+ * @package Gedmo
+ * @subpackage Exception
+ * @link http://www.gediminasm.org
+ * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
+ */
+interface Exception
+{
+    /**
+     * Following best practices for PHP5.3 package exceptions.
+     * All exceptions thrown in this package will have to implement this interface
+     * 
+     * @link http://wiki.php.net/pear/rfc/pear2_exception_policy
+     */
+}

+ 19 - 0
lib/Gedmo/Exception/InvalidArgumentException.php

@@ -0,0 +1,19 @@
+<?php
+
+namespace Gedmo\Exception;
+
+use Gedmo\Exception;
+
+/**
+ * InvalidArgumentException
+ * 
+ * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
+ * @package Gedmo.Exception
+ * @subpackage InvalidArgumentException
+ * @link http://www.gediminasm.org
+ * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
+ */
+class InvalidArgumentException 
+    extends \InvalidArgumentException
+    implements Exception
+{}

+ 19 - 0
lib/Gedmo/Exception/RuntimeException.php

@@ -0,0 +1,19 @@
+<?php
+
+namespace Gedmo\Exception;
+
+use Gedmo\Exception;
+
+/**
+ * RuntimeException
+ * 
+ * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
+ * @package Gedmo.Exception
+ * @subpackage RuntimeException
+ * @link http://www.gediminasm.org
+ * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
+ */
+class RuntimeException 
+    extends \RuntimeException
+    implements Exception
+{}

+ 19 - 0
lib/Gedmo/Exception/UnexpectedValueException.php

@@ -0,0 +1,19 @@
+<?php
+
+namespace Gedmo\Exception;
+
+use Gedmo\Exception;
+
+/**
+ * UnexpectedValueException
+ * 
+ * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
+ * @package Gedmo.Exception
+ * @subpackage UnexpectedValueException
+ * @link http://www.gediminasm.org
+ * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
+ */
+class UnexpectedValueException 
+    extends \UnexpectedValueException
+    implements Exception
+{}

+ 1 - 1
lib/Gedmo/Mapping/Driver/Chain.php

@@ -62,6 +62,6 @@ class Chain implements Driver
                 return;
             }
         }
-        throw \Gedmo\Mapping\DriverException::invalidEntity($meta->name);
+        throw new \Gedmo\Exception\UnexpectedValueException('Class ' . $meta->name . ' is not a valid entity or mapped super class.');
     }
 }

+ 1 - 2
lib/Gedmo/Mapping/Driver/File.php

@@ -77,7 +77,6 @@ abstract class File
                 return $path . DIRECTORY_SEPARATOR . $fileName;
             }
         }
-
-        throw \Gedmo\Mapping\DriverException::mappingFileNotFound($fileName, $className);
+        throw new \Gedmo\Exception\UnexpectedValueException("No mapping file found named '$fileName' for class '$className'.");
     }
 }

+ 0 - 35
lib/Gedmo/Mapping/DriverException.php

@@ -1,35 +0,0 @@
-<?php
-
-namespace Gedmo\Mapping;
-
-/**
- * The mapping exception list extension driver mapping
- * 
- * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
- * @package Gedmo.Mapping
- * @subpackage DriverException
- * @link http://www.gediminasm.org
- * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
- */
-class DriverException extends \Exception
-{   
-    static public function annotationDriverNotFound($driverClassName)
-    {
-        return new self("Extension annotation driver: ({$driverClassName}) was not found.");
-    }
-    
-    static public function invalidEntity($className)
-    {
-        return new self('Class ' . $className . ' is not a valid entity or mapped super class.');
-    }
-    
-    static public function mappingFileNotFound($fileName, $className)
-    {
-        return new self("No mapping file found named '$fileName' for class '$className'.");
-    }
-    
-    static public function extensionDriverNotSupported($driverClassName, $driverName)
-    {
-        return new self("Driver: ({$driverName}) currently is not supported for extension metadata parsing. Failed to initialize: {$driverClassName}");
-    }
-}

+ 1 - 1
lib/Gedmo/Mapping/ExtensionMetadataFactory.php

@@ -119,7 +119,7 @@ class ExtensionMetadataFactory
                 // @TODO: implement XML driver also
                 $driverClassName = $this->_extensionNamespace . '\Mapping\Driver\Annotation';
                 if (!class_exists($driverClassName)) {
-                    throw DriverException::extensionDriverNotSupported($driverClassName, $driverName);
+                    throw new \Gedmo\Exception\RuntimeException("Failed to fallback to annotation driver: ({$driverClassName}), extension driver was not found.");
                 }
             }
             $driver = new $driverClassName();

+ 0 - 25
lib/Gedmo/Sluggable/Exception.php

@@ -1,25 +0,0 @@
-<?php
-
-namespace Gedmo\Sluggable;
-
-/**
- * The exception list for Sluggable behavior
- * 
- * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
- * @package Gedmo.Sluggable
- * @subpackage Exception
- * @link http://www.gediminasm.org
- * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
- */
-class Exception extends \Exception
-{
-    static public function slugIsEmpty()
-    {
-        return new self("Sluggable: was unable to find any non empty sluggable fields, make sure they have something at least.");
-    }
-    
-    static public function slugFieldIsUnique($slugField)
-    {
-        return new self("Sluggable: cannot support unique slug field '{$slugField}' during concurent updates, make an index on it.");
-    }
-}

+ 7 - 7
lib/Gedmo/Sluggable/Mapping/Driver/Annotation.php

@@ -5,7 +5,7 @@ namespace Gedmo\Sluggable\Mapping\Driver;
 use Gedmo\Mapping\Driver,
     Doctrine\Common\Annotations\AnnotationReader,
     Doctrine\ORM\Mapping\ClassMetadataInfo,
-    Gedmo\Sluggable\Mapping\MappingException;
+    Gedmo\Exception\InvalidArgumentException;
 
 /**
  * This is an annotation mapping driver for Sluggable
@@ -47,7 +47,7 @@ class Annotation implements Driver
     public function validateFullMetadata(ClassMetadataInfo $meta, array $config)
     {
         if ($config && !isset($config['fields'])) {
-            throw MappingException::noFieldsToSlug($meta->name);
+            throw new InvalidArgumentException("Unable to find any sluggable fields specified for Sluggable entity - {$meta->name}");
         }
     }
     
@@ -72,10 +72,10 @@ class Annotation implements Driver
             if ($sluggable = $reader->getPropertyAnnotation($property, self::ANNOTATION_SLUGGABLE)) {
                 $field = $property->getName();
                 if (!$meta->hasField($field)) {
-                    throw MappingException::fieldMustBeMapped($field, $meta->name);
+                    throw new InvalidArgumentException("Unable to find sluggable [{$field}] as mapped property in entity - {$meta->name}");
                 }
                 if (!$this->_isValidField($meta, $field)) {
-                    throw MappingException::notValidFieldType($field, $meta->name);
+                    throw new InvalidArgumentException("Cannot slug field - [{$field}] type is not valid and must be 'string' in class - {$meta->name}");
                 }
                 $config['fields'][] = $field;
             }
@@ -83,13 +83,13 @@ class Annotation implements Driver
             if ($slug = $reader->getPropertyAnnotation($property, self::ANNOTATION_SLUG)) {
                 $field = $property->getName();
                 if (!$meta->hasField($field)) {
-                    throw MappingException::slugFieldMustBeMapped($field, $meta->name);
+                    throw new InvalidArgumentException("Unable to find slug [{$field}] as mapped property in entity - {$meta->name}");
                 }
                 if (!$this->_isValidField($meta, $field)) {
-                    throw MappingException::notValidFieldType($field, $meta->name);
+                    throw new InvalidArgumentException("Cannot use field - [{$field}] for slug storage, type is not valid and must be 'string' in class - {$meta->name}");
                 } 
                 if (isset($config['slug'])) {
-                    throw MappingException::slugFieldIsDuplicate($field, $meta->name);
+                    throw new InvalidArgumentException("There cannot be two slug fields: [{$slugField}] and [{$config['slug']}], in class - {$meta->name}.");
                 }
                 
                 $config['slug'] = $field;

+ 5 - 5
lib/Gedmo/Sluggable/Mapping/Driver/Yaml.php

@@ -5,7 +5,7 @@ namespace Gedmo\Sluggable\Mapping\Driver;
 use Gedmo\Mapping\Driver\File,
     Gedmo\Mapping\Driver,
     Doctrine\ORM\Mapping\ClassMetadataInfo,
-    Gedmo\Sluggable\Mapping\MappingException;
+    Gedmo\Exception\InvalidArgumentException;
 
 /**
  * This is a yaml mapping driver for Sluggable
@@ -42,7 +42,7 @@ class Yaml extends File implements Driver
     public function validateFullMetadata(ClassMetadataInfo $meta, array $config)
     {
         if ($config && !isset($config['fields'])) {
-            throw MappingException::noFieldsToSlug($meta->name);
+            throw new InvalidArgumentException("Unable to find any sluggable fields specified for Sluggable entity - {$meta->name}");
         }
     }
     
@@ -58,16 +58,16 @@ class Yaml extends File implements Driver
                 if (isset($fieldMapping['gedmo'])) {
                     if (in_array('sluggable', $fieldMapping['gedmo'])) {
                         if (!$this->_isValidField($meta, $field)) {
-                            throw MappingException::notValidFieldType($field, $meta->name);
+                            throw new InvalidArgumentException("Cannot slug field - [{$field}] type is not valid and must be 'string' in class - {$meta->name}");
                         }
                         $config['fields'][] = $field;
                     } elseif (isset($fieldMapping['gedmo']['slug']) || in_array('slug', $fieldMapping['gedmo'])) {
                         $slug = $fieldMapping['gedmo']['slug'];
                         if (!$this->_isValidField($meta, $field)) {
-                            throw MappingException::notValidFieldType($field, $meta->name);
+                            throw new InvalidArgumentException("Cannot use field - [{$field}] for slug storage, type is not valid and must be 'string' in class - {$meta->name}");
                         } 
                         if (isset($config['slug'])) {
-                            throw MappingException::slugFieldIsDuplicate($field, $meta->name);
+                            throw new InvalidArgumentException("There cannot be two slug fields: [{$slugField}] and [{$config['slug']}], in class - {$meta->name}.");
                         }
                         
                         $config['slug'] = $field;

+ 0 - 35
lib/Gedmo/Sluggable/Mapping/MappingException.php

@@ -1,35 +0,0 @@
-<?php
-
-namespace Gedmo\Sluggable\Mapping;
-
-/**
- * The mapping exception list for Sluggable behavior
- * 
- * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
- * @package Gedmo.Sluggable.Mapping
- * @subpackage MappingException
- * @link http://www.gediminasm.org
- * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
- */
-class MappingException extends \Exception
-{
-    static public function fieldMustBeMapped($field, $class)
-    {
-        return new self("Sluggable: was unable to find [{$field}] as mapped property in entity - {$class}");
-    }
-    
-    static public function noFieldsToSlug($class)
-    {
-        return new self("Sluggable: was unable to find sluggable fields specified for Sluggable entity - {$class}");
-    }
-    
-    static public function slugFieldIsDuplicate($slugField, $class)
-    {
-        return new self("Sluggable: there cannot be two slug fields '{$slugField}' in class - {$class}.");
-    }
-    
-    static public function notValidFieldType($field, $class)
-    {
-        return new self("Sluggable: cannot slug field - [{$field}] type is not valid and must be 'string' in class - {$class}");
-    }
-}

+ 1 - 1
lib/Gedmo/Sluggable/SluggableListener.php

@@ -120,7 +120,7 @@ class SluggableListener extends MappedEventSubscriber implements EventSubscriber
         }
         
         if (!strlen(trim($slug))) {
-            throw Exception::slugIsEmpty();
+            throw new \Gedmo\Exception\UnexpectedValueException('Unable to find any non empty sluggable fields, make sure they have something at least.');
         }
         
         // build the slug

+ 0 - 20
lib/Gedmo/Timestampable/Exception.php

@@ -1,20 +0,0 @@
-<?php
-
-namespace Gedmo\Timestampable;
-
-/**
- * The exception list for Timestampable behavior
- * 
- * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
- * @package Gedmo.Timestampable
- * @subpackage Exception
- * @link http://www.gediminasm.org
- * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
- */
-class Exception extends \Exception
-{
-    static public function objectExpected($field, $class)
-    {
-        return new self("Timestampable: field - [{$field}] is expected to be object in class - {$class}");
-    }
-}

+ 5 - 5
lib/Gedmo/Timestampable/Mapping/Driver/Annotation.php

@@ -5,7 +5,7 @@ namespace Gedmo\Timestampable\Mapping\Driver;
 use Gedmo\Mapping\Driver,
     Doctrine\Common\Annotations\AnnotationReader,
     Doctrine\ORM\Mapping\ClassMetadataInfo,
-    Gedmo\Timestampable\Mapping\MappingException;
+    Gedmo\Exception\InvalidArgumentException;
 
 /**
  * This is an annotation mapping driver for Timestampable
@@ -65,17 +65,17 @@ class Annotation implements Driver
             if ($timestampable = $reader->getPropertyAnnotation($property, self::ANNOTATION_TIMESTAMPABLE)) {
                 $field = $property->getName();
                 if (!$meta->hasField($field)) {
-                    throw MappingException::fieldMustBeMapped($field, $meta->name);
+                    throw new InvalidArgumentException("Unable to find timestampable [{$field}] as mapped property in entity - {$meta->name}");
                 }
                 if (!$this->_isValidField($meta, $field)) {
-                    throw MappingException::notValidFieldType($field, $meta->name);
+                    throw new InvalidArgumentException("Field - [{$field}] type is not valid and must be 'date', 'datetime' or 'time' in class - {$meta->name}");
                 }
                 if (!in_array($timestampable->on, array('update', 'create', 'change'))) {
-                    throw MappingException::triggerTypeInvalid($field, $meta->name);
+                    throw new InvalidArgumentException("Field - [{$field}] trigger 'on' is not one of [update, create, change] in class - {$meta->name}");
                 }
                 if ($timestampable->on == 'change') {
                     if (!isset($timestampable->field) || !isset($timestampable->value)) {
-                        throw MappingException::parametersMissing($field, $meta->name);
+                        throw new InvalidArgumentException("Missing parameters on property - {$field}, field and value must be set on [change] trigger in class - {$meta->name}");
                     }
                     $field = array(
                         'field' => $field,

+ 4 - 4
lib/Gedmo/Timestampable/Mapping/Driver/Yaml.php

@@ -5,7 +5,7 @@ namespace Gedmo\Timestampable\Mapping\Driver;
 use Gedmo\Mapping\Driver\File,
     Gedmo\Mapping\Driver,
     Doctrine\ORM\Mapping\ClassMetadataInfo,
-    Gedmo\Timestampable\Mapping\MappingException;
+    Gedmo\Exception\InvalidArgumentException;
 
 /**
  * This is a yaml mapping driver for Timestampable
@@ -58,15 +58,15 @@ class Yaml extends File implements Driver
                 if (isset($fieldMapping['gedmo']['timestampable'])) {
                     $mappingProperty = $fieldMapping['gedmo']['timestampable'];
                     if (!$this->_isValidField($meta, $field)) {
-                        throw MappingException::notValidFieldType($field, $meta->name);
+                        throw new InvalidArgumentException("Field - [{$field}] type is not valid and must be 'date', 'datetime' or 'time' in class - {$meta->name}");
                     }
                     if (!isset($mappingProperty['on']) || !in_array($mappingProperty['on'], array('update', 'create', 'change'))) {
-                        throw MappingException::triggerTypeInvalid($field, $meta->name);
+                        throw new InvalidArgumentException("Field - [{$field}] trigger 'on' is not one of [update, create, change] in class - {$meta->name}");
                     }
                     
                     if ($mappingProperty['on'] == 'change') {
                         if (!isset($mappingProperty['field']) || !isset($mappingProperty['value'])) {
-                            throw MappingException::parametersMissing($field, $meta->name);
+                            throw new InvalidArgumentException("Missing parameters on property - {$field}, field and value must be set on [change] trigger in class - {$meta->name}");
                         }
                         $field = array(
                             'field' => $field,

+ 0 - 35
lib/Gedmo/Timestampable/Mapping/MappingException.php

@@ -1,35 +0,0 @@
-<?php
-
-namespace Gedmo\Timestampable\Mapping;
-
-/**
- * The mapping exception list for Timestampable behavior
- * 
- * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
- * @package Gedmo.Timestampable.Mapping
- * @subpackage MappingException
- * @link http://www.gediminasm.org
- * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
- */
-class MappingException extends \Exception
-{
-    static public function notValidFieldType($field, $class)
-    {
-        return new self("Timestampable: field - [{$field}] type is not valid date or time field in class - {$class}");
-    }
-    
-    static public function triggerTypeInvalid($field, $class)
-    {
-        return new self("Timestampable: field - [{$field}] trigger 'on' is not one of [update, create, change] in class - {$class}");
-    }
-    
-    static public function parametersMissing($field, $class)
-    {
-        return new self("Timestampable: missing parameters on property - {$field}, field and value must be set on [change] trigger in class - {$class}");
-    }
-    
-    static public function fieldMustBeMapped($field, $class)
-    {
-        return new self("Timestampable: was unable to find [{$field}] as mapped property in entity - {$class}");
-    }
-}

+ 1 - 1
lib/Gedmo/Timestampable/TimestampableListener.php

@@ -85,7 +85,7 @@ class TimestampableListener extends MappedEventSubscriber implements EventSubscr
                             if (isset($trackedChild)) {
                                 $object = $changes[1];
                                 if (!is_object($object)) {
-                                    throw Exception::objectExpected($tracked, $meta->name);
+                                    throw new \Gedmo\Exception\UnexpectedValueException("Field - [{$field}] is expected to be object in class - {$meta->name}");
                                 }
                                 $objectMeta = $em->getClassMetadata(get_class($object));
                                 $value = $objectMeta->getReflectionProperty($trackedChild)

+ 0 - 35
lib/Gedmo/Translatable/Exception.php

@@ -1,35 +0,0 @@
-<?php
-
-namespace Gedmo\Translatable;
-
-/**
- * The exception list for Translatable behavior
- * 
- * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
- * @package Gedmo.Translatable
- * @subpackage Exception
- * @link http://www.gediminasm.org
- * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
- */
-class Exception extends \Exception
-{
-    static public function undefinedLocale()
-    {
-        return new self("Translatable: locale or language cannot be empty and must be set in Translatable\Listener or in the entity");
-    }
-
-    static public function singleIdentifierRequired($entityClass)
-    {
-        return new self("Translatable: only a single identifier column is required for the Translatable extension, entity: {$entityClass}.");
-    }
-    
-    static public function entityMissingLocaleProperty($field, $className)
-    {
-        return new self("Translatable: there is no locale field ({$field}) found on entity: {$className}");
-    }
-    
-    static public function failedToInsert()
-    {
-        return new self("Translatable: failed to insert new Translation record");
-    }
-}

+ 6 - 6
lib/Gedmo/Translatable/Mapping/Driver/Annotation.php

@@ -5,7 +5,7 @@ namespace Gedmo\Translatable\Mapping\Driver;
 use Gedmo\Mapping\Driver,
     Doctrine\Common\Annotations\AnnotationReader,
     Doctrine\ORM\Mapping\ClassMetadataInfo,
-    Gedmo\Translatable\Mapping\MappingException;
+    Gedmo\Exception\InvalidArgumentException;
 
 /**
  * This is an annotation mapping driver for Translatable
@@ -77,7 +77,7 @@ class Annotation implements Driver
         if (isset($classAnnotations[self::ANNOTATION_ENTITY_CLASS])) {
             $annot = $classAnnotations[self::ANNOTATION_ENTITY_CLASS];
             if (!class_exists($annot->class)) {
-                throw MappingException::translationClassNotFound($annot->class);
+                throw new InvalidArgumentException("Translation entity class: {$annot->class} does not exist.");
             }
             $config['translationClass'] = $annot->class;
         }
@@ -94,10 +94,10 @@ class Annotation implements Driver
             if ($translatable = $reader->getPropertyAnnotation($property, self::ANNOTATION_TRANSLATABLE)) {
                 $field = $property->getName();
                 if (!$meta->hasField($field)) {
-                    throw MappingException::fieldMustBeMapped($field, $meta->name);
+                    throw new InvalidArgumentException("Unable to find translatable [{$field}] as mapped property in entity - {$meta->name}");
                 }
                 if (!$this->_isValidField($meta, $field)) {
-                    throw MappingException::notValidFieldType($field, $meta->name);
+                    throw new InvalidArgumentException("Translatable field - [{$field}] type is not valid and must be 'string' or 'text' in class - {$meta->name}");
                 }
                 // fields cannot be overrided and throws mapping exception
                 $config['fields'][] = $field;
@@ -106,13 +106,13 @@ class Annotation implements Driver
             if ($locale = $reader->getPropertyAnnotation($property, self::ANNOTATION_LOCALE)) {
                 $field = $property->getName();
                 if ($meta->hasField($field)) {
-                    throw MappingException::fieldMustNotBeMapped($field, $meta->name);
+                    throw new InvalidArgumentException("Locale field [{$field}] should not be mapped as column property in entity - {$meta->name}, since it makes no sence");
                 }
                 $config['locale'] = $field;
             } elseif ($language = $reader->getPropertyAnnotation($property, self::ANNOTATION_LANGUAGE)) {
                 $field = $property->getName();
                 if ($meta->hasField($field)) {
-                    throw MappingException::fieldMustNotBeMapped($field, $meta->name);
+                    throw new InvalidArgumentException("Language field [{$field}] should not be mapped as column property in entity - {$meta->name}, since it makes no sence");
                 }
                 $config['locale'] = $field;
             }

+ 3 - 3
lib/Gedmo/Translatable/Mapping/Driver/Yaml.php

@@ -5,7 +5,7 @@ namespace Gedmo\Translatable\Mapping\Driver;
 use Gedmo\Mapping\Driver\File,
     Gedmo\Mapping\Driver,
     Doctrine\ORM\Mapping\ClassMetadataInfo,
-    Gedmo\Translatable\Mapping\MappingException;
+    Gedmo\Exception\InvalidArgumentException;
 
 /**
  * This is a yaml mapping driver for Translatable
@@ -59,7 +59,7 @@ class Yaml extends File implements Driver
             if (isset($classMapping['translation']['entity'])) {
                 $translationEntity = $classMapping['translation']['entity'];
                 if (!class_exists($translationEntity)) {
-                    throw MappingException::translationClassNotFound($translationEntity);
+                    throw new InvalidArgumentException("Translation entity class: {$translationEntity} does not exist.");
                 }
                 $config['translationClass'] = $translationEntity;
             }
@@ -74,7 +74,7 @@ class Yaml extends File implements Driver
                 if (isset($fieldMapping['gedmo'])) {
                     if (in_array('translatable', $fieldMapping['gedmo'])) {
                         if (!$this->_isValidField($meta, $field)) {
-                            throw MappingException::notValidFieldType($field, $meta->name);
+                            throw new InvalidArgumentException("Translatable field - [{$field}] type is not valid and must be 'string' or 'text' in class - {$meta->name}");
                         }
                         // fields cannot be overrided and throws mapping exception
                         $config['fields'][] = $field;

+ 0 - 35
lib/Gedmo/Translatable/Mapping/MappingException.php

@@ -1,35 +0,0 @@
-<?php
-
-namespace Gedmo\Translatable\Mapping;
-
-/**
- * The mapping exception list for Translatable behavior
- * 
- * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
- * @package Gedmo.Translatable.Mapping
- * @subpackage MappingException
- * @link http://www.gediminasm.org
- * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
- */
-class MappingException extends \Exception
-{   
-    static public function translationClassNotFound($class)
-    {
-        return new self("Translatable: the translation entity class: {$class} was not found.");
-    }
-    
-    static public function notValidFieldType($field, $class)
-    {
-        return new self("Translatable: cannot translate field - [{$field}] type is not valid and must be 'string' or 'text' in class - {$class}");
-    }
-    
-    static public function fieldMustBeMapped($field, $class)
-    {
-        return new self("Translatable: was unable to find [{$field}] as mapped property in entity - {$class}");
-    }
-    
-    static public function fieldMustNotBeMapped($field, $class)
-    {
-        return new self("Translatable: field [{$field}] should not be mapped as column property in entity - {$class}, since it makes no sence");
-    }
-}

+ 10 - 13
lib/Gedmo/Translatable/TranslationListener.php

@@ -143,6 +143,8 @@ class TranslationListener extends MappedEventSubscriber implements EventSubscrib
      * 
      * @param object $entity
      * @param ClassMetadataInfo $meta
+     * @throws RuntimeException - if language or locale property is not
+     * 		found in entity
      * @return string
      */
     public function getTranslatableLocale($entity, ClassMetadataInfo $meta)
@@ -152,10 +154,8 @@ class TranslationListener extends MappedEventSubscriber implements EventSubscrib
             $class = $meta->getReflectionClass();
             $reflectionProperty = $class->getProperty($this->_configurations[$meta->name]['locale']);
             if (!$reflectionProperty) {
-                throw Exception::entityMissingLocaleProperty(
-                    $this->_configurations[$meta->name]['locale'],
-                    $meta->name
-                );
+                $column = $this->_configurations[$meta->name]['locale'];
+                throw new \Gedmo\Exception\RuntimeException("There is no locale or language property ({$column}) found on entity: {$meta->name}");
             }
             $reflectionProperty->setAccessible(true);
             $value = $reflectionProperty->getValue($entity);
@@ -267,7 +267,6 @@ class TranslationListener extends MappedEventSubscriber implements EventSubscrib
      * by currently used locale
      * 
      * @param LifecycleEventArgs $args
-     * @throws Translatable\Exception if locale is not valid
      * @return void
      */
     public function postLoad(LifecycleEventArgs $args)
@@ -324,7 +323,7 @@ class TranslationListener extends MappedEventSubscriber implements EventSubscrib
      * @param EntityManager $em
      * @param object $entity
      * @param boolean $isInsert
-     * @throws Translatable\Exception if locale is not valid, or
+     * @throws UnexpectedValueException - if locale is not valid, or
      *      primary key is composite, missing or invalid
      * @return void
      */
@@ -343,7 +342,7 @@ class TranslationListener extends MappedEventSubscriber implements EventSubscrib
         } elseif ($isInsert) {
             $entityId = null;
         } else {
-            throw Exception::singleIdentifierRequired($entityClass);
+            throw new \Gedmo\Exception\UnexpectedValueException("Only a single identifier column is required for the Translatable extension, entity: {$entityClass}.");
         }
         
         // load the currently used locale
@@ -426,8 +425,6 @@ class TranslationListener extends MappedEventSubscriber implements EventSubscrib
      * @param string $entityClass
      * @param string $locale
      * @param string $field
-     * @throws Translatable\Exception if unit of work has pending inserts
-     *      to avoid infinite loop
      * @return mixed - null if nothing is found, Translation otherwise
      */
     protected function _findTranslation(EntityManager $em, $entityId, $entityClass, $locale, $field)
@@ -457,13 +454,13 @@ class TranslationListener extends MappedEventSubscriber implements EventSubscrib
      * Validates the given locale
      * 
      * @param string $locale - locale to validate
-     * @throws Translatable\Exception if locale is not valid
+     * @throws InvalidArgumentException if locale is not valid
      * @return void
      */
     protected function _validateLocale($locale)
     {
         if (!is_string($locale) || !strlen($locale)) {
-            throw Exception::undefinedLocale();
+            throw new \Gedmo\Exception\InvalidArgumentException('Locale or language cannot be empty and must be set through Listener or Entity');
         }
     }
     
@@ -490,7 +487,7 @@ class TranslationListener extends MappedEventSubscriber implements EventSubscrib
      * 
      * @param EntityManager $em
      * @param object $translation
-     * @throws Translatable\Exception if insert fails
+     * @throws RuntimeException if insert fails
      * @return void
      */
     private function _insertTranslationRecord(EntityManager $em, $translation)
@@ -506,7 +503,7 @@ class TranslationListener extends MappedEventSubscriber implements EventSubscrib
         
         $table = $translationMetadata->getTableName();
         if (!$em->getConnection()->insert($table, $data)) {
-            throw Exception::failedToInsert();
+            throw new \Gedmo\Exception\RuntimeException('Failed to insert new Translation record');
         }
     }
 }

+ 0 - 17
lib/Gedmo/Tree/Exception.php

@@ -1,17 +0,0 @@
-<?php
-
-namespace Gedmo\Tree;
-
-/**
- * The exception list for Tree behavior
- * 
- * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
- * @package Gedmo.Tree
- * @subpackage Exception
- * @link http://www.gediminasm.org
- * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
- */
-class Exception extends \Exception
-{    
-    
-}

+ 9 - 9
lib/Gedmo/Tree/Mapping/Driver/Annotation.php

@@ -5,7 +5,7 @@ namespace Gedmo\Tree\Mapping\Driver;
 use Gedmo\Mapping\Driver,
     Doctrine\Common\Annotations\AnnotationReader,
     Doctrine\ORM\Mapping\ClassMetadataInfo,
-    Gedmo\Tree\Mapping\MappingException;
+    Gedmo\Exception\InvalidArgumentException;
 
 /**
  * This is an annotation mapping driver for Tree
@@ -69,7 +69,7 @@ class Annotation implements Driver
                 $missingFields[] = 'right';
             }
             if ($missingFields) {
-                throw MappingException::missingMetaProperties($missingFields, $meta->name);
+                throw new InvalidArgumentException("Missing properties: " . implode(', ', $missingFields) . " in class - {$meta->name}");
             }
         }
     }
@@ -95,10 +95,10 @@ class Annotation implements Driver
             if ($left = $reader->getPropertyAnnotation($property, self::ANNOTATION_LEFT)) {
                 $field = $property->getName();
                 if (!$meta->hasField($field)) {
-                    throw MappingException::fieldMustBeMapped($field, $meta->name);
+                    throw new InvalidArgumentException("Unable to find 'left' - [{$field}] as mapped property in entity - {$meta->name}");
                 }
                 if (!$this->_isValidField($meta, $field)) {
-                    throw MappingException::notValidFieldType($field, $meta->name);
+                    throw new InvalidArgumentException("Tree left field - [{$field}] type is not valid and must be 'integer' in class - {$meta->name}");
                 }
                 $config['left'] = $field;
             }
@@ -106,10 +106,10 @@ class Annotation implements Driver
             if ($right = $reader->getPropertyAnnotation($property, self::ANNOTATION_RIGHT)) {
                 $field = $property->getName();
                 if (!$meta->hasField($field)) {
-                    throw MappingException::fieldMustBeMapped($field, $meta->name);
+                    throw new InvalidArgumentException("Unable to find 'right' - [{$field}] as mapped property in entity - {$meta->name}");
                 }
                 if (!$this->_isValidField($meta, $field)) {
-                    throw MappingException::notValidFieldType($field, $meta->name);
+                    throw new InvalidArgumentException("Tree right field - [{$field}] type is not valid and must be 'integer' in class - {$meta->name}");
                 }
                 $config['right'] = $field;
             }
@@ -117,7 +117,7 @@ class Annotation implements Driver
             if ($parent = $reader->getPropertyAnnotation($property, self::ANNOTATION_PARENT)) {
                 $field = $property->getName();
                 if (!$meta->isSingleValuedAssociation($field)) {
-                    throw MappingException::parentFieldNotMappedOrRelated($field, $meta->name);
+                    throw new InvalidArgumentException("Unable to find ancestor/parent child relation through ancestor field - [{$field}] in class - {$meta->name}");
                 }
                 $config['parent'] = $field;
             }
@@ -125,10 +125,10 @@ class Annotation implements Driver
             if ($parent = $reader->getPropertyAnnotation($property, self::ANNOTATION_LEVEL)) {
                 $field = $property->getName();
                 if (!$meta->hasField($field)) {
-                    throw MappingException::fieldMustBeMapped($field, $meta->name);
+                    throw new InvalidArgumentException("Unable to find 'level' - [{$field}] as mapped property in entity - {$meta->name}");
                 }
                 if (!$this->_isValidField($meta, $field)) {
-                    throw MappingException::notValidFieldType($field, $meta->name);
+                    throw new InvalidArgumentException("Tree level field - [{$field}] type is not valid and must be 'integer' in class - {$meta->name}");
                 }
                 $config['level'] = $field;
             }

+ 6 - 6
lib/Gedmo/Tree/Mapping/Driver/Yaml.php

@@ -5,7 +5,7 @@ namespace Gedmo\Tree\Mapping\Driver;
 use Gedmo\Mapping\Driver\File,
     Gedmo\Mapping\Driver,
     Doctrine\ORM\Mapping\ClassMetadataInfo,
-    Gedmo\Tree\Mapping\MappingException;
+    Gedmo\Exception\InvalidArgumentException;
 
 /**
  * This is a yaml mapping driver for Tree
@@ -55,7 +55,7 @@ class Yaml extends File implements Driver
                 $missingFields[] = 'right';
             }
             if ($missingFields) {
-                throw MappingException::missingMetaProperties($missingFields, $meta->name);
+                throw new InvalidArgumentException("Missing properties: " . implode(', ', $missingFields) . " in class - {$meta->name}");
             }
         }
     }
@@ -71,17 +71,17 @@ class Yaml extends File implements Driver
                 if (isset($fieldMapping['gedmo'])) {
                     if (in_array('treeLeft', $fieldMapping['gedmo'])) {
                         if (!$this->_isValidField($meta, $field)) {
-                            throw MappingException::notValidFieldType($field, $meta->name);
+                            throw new InvalidArgumentException("Tree left field - [{$field}] type is not valid and must be 'integer' in class - {$meta->name}");
                         }
                         $config['left'] = $field;
                     } elseif (in_array('treeRight', $fieldMapping['gedmo'])) {
                         if (!$this->_isValidField($meta, $field)) {
-                            throw MappingException::notValidFieldType($field, $meta->name);
+                            throw new InvalidArgumentException("Tree right field - [{$field}] type is not valid and must be 'integer' in class - {$meta->name}");
                         }
                         $config['right'] = $field;
                     } elseif (in_array('treeLevel', $fieldMapping['gedmo'])) {
                         if (!$this->_isValidField($meta, $field)) {
-                            throw MappingException::notValidFieldType($field, $meta->name);
+                            throw new InvalidArgumentException("Tree level field - [{$field}] type is not valid and must be 'integer' in class - {$meta->name}");
                         }
                         $config['level'] = $field;
                     }
@@ -93,7 +93,7 @@ class Yaml extends File implements Driver
                 if (isset($relationMapping['gedmo'])) {
                     if (in_array('treeParent', $relationMapping['gedmo'])) {
                         if ($relationMapping['targetEntity'] != $meta->name) {
-                            throw MappingException::parentFieldNotMappedOrRelated($field, $meta->name);
+                            throw new InvalidArgumentException("Unable to find ancestor/parent child relation through ancestor field - [{$field}] in class - {$meta->name}");
                         }
                         $config['parent'] = $field;
                     }

+ 0 - 35
lib/Gedmo/Tree/Mapping/MappingException.php

@@ -1,35 +0,0 @@
-<?php
-
-namespace Gedmo\Tree\Mapping;
-
-/**
- * The mapping exception list for Tree behavior
- * 
- * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
- * @package Gedmo.Tree.Mapping
- * @subpackage MappingException
- * @link http://www.gediminasm.org
- * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
- */
-class MappingException extends \Exception
-{
-    static public function parentFieldNotMappedOrRelated($field, $class)
-    {
-        return new self("Tree: was unable to find ancestor/parent child relation through ancestor field - [{$field}] in class - {$class}");
-    }
-    
-    static public function missingMetaProperties($fields, $class)
-    {
-        return new self("Tree: has detected missing properties: " . implode(', ', $fields) . " in class - {$class}");
-    }
-    
-    static public function notValidFieldType($field, $class)
-    {
-        return new self("Tree: field - [{$field}] type is not valid and must be 'integer', 'smallint' or 'bigint' in class - {$class}");
-    }
-    
-    static public function fieldMustBeMapped($field, $class)
-    {
-        return new self("Tree: was unable to find [{$field}] as mapped property in entity - {$class}");
-    }
-}

+ 14 - 12
lib/Gedmo/Tree/Repository/TreeNodeRepository.php

@@ -107,6 +107,7 @@ class TreeNodeRepository extends EntityRepository
      * @param boolean $direct - true to take only direct children
      * @param string $sortByField - field name to sort by
      * @param string $direction - sort direction : "ASC" or "DESC"
+     * @throws InvalidArgumentException - if sort options are invalid
      * @return array - list of given $node children, null on failure
      */
     public function children($node = null, $direct = false, $sortByField = null, $direction = 'ASC')
@@ -141,7 +142,7 @@ class TreeNodeRepository extends EntityRepository
             if ($meta->hasField($sortByField) && in_array(strtolower($direction), array('asc', 'desc'))) {
                 $qb->orderBy('node.' . $sortByField, $direction);
             } else {
-                throw new \RuntimeException("Invalid sort options specified: field - {$sortByField}, direction - {$direction}");
+                throw new \Gedmo\Exception\InvalidArgumentException("Invalid sort options specified: field - {$sortByField}, direction - {$direction}");
             }
         }
         $q = $qb->getQuery();
@@ -155,6 +156,7 @@ class TreeNodeRepository extends EntityRepository
      *
      * @param string $sortByField - field name to sort by
      * @param string $direction - sort direction : "ASC" or "DESC"
+     * @throws InvalidArgumentException - if sort options are invalid
      * @return array - list of given $node children, null on failure
      */
     public function getLeafs($sortByField = null, $direction = 'ASC')
@@ -172,7 +174,7 @@ class TreeNodeRepository extends EntityRepository
             if ($meta->hasField($sortByField) && in_array(strtolower($direction), array('asc', 'desc'))) {
                 $qb->orderBy('node.' . $sortByField, $direction);
             } else {
-                throw new \RuntimeException("Invalid sort options specified: field - {$sortByField}, direction - {$direction}");
+                throw new \Gedmo\Exception\InvalidArgumentException("Invalid sort options specified: field - {$sortByField}, direction - {$direction}");
             }
         }
         $q = $qb->getQuery();
@@ -186,7 +188,7 @@ class TreeNodeRepository extends EntityRepository
      * @param mixed $number
      *         integer - number of positions to shift
      *         boolean - true shift till last position
-     * @throws Exception if something fails in transaction
+     * @throws RuntimeException - if something fails in transaction
      * @return boolean - true if shifted
      */
     public function moveDown($node, $number = 1)
@@ -236,7 +238,7 @@ class TreeNodeRepository extends EntityRepository
         } catch (\Exception $e) {
             $this->_em->close();
             $this->_em->getConnection()->rollback();
-            throw $e;
+            throw new \Gedmo\Exception\RuntimeException('Transaction failed', null, $e);
         }
         if (is_int($number)) {
             $number--;
@@ -255,7 +257,7 @@ class TreeNodeRepository extends EntityRepository
      * @param mixed $number
      *         integer - number of positions to shift
      *         boolean - true shift till first position
-     * @throws Exception if something fails in transaction
+     * @throws RuntimeException - if something fails in transaction
      * @return boolean - true if shifted
      */
     public function moveUp($node, $number = 1)
@@ -304,7 +306,7 @@ class TreeNodeRepository extends EntityRepository
         } catch (\Exception $e) {
             $this->_em->close();
             $this->_em->getConnection()->rollback();
-            throw $e;
+            throw new \Gedmo\Exception\RuntimeException('Transaction failed', null, $e);
         }
         if (is_int($number)) {
             $number--;
@@ -352,7 +354,7 @@ class TreeNodeRepository extends EntityRepository
      * Removes given $node from the tree and reparents its descendants
      * 
      * @param Node $node
-     * @throws Exception if something fails in transaction
+     * @throws RuntimeException - if something fails in transaction
      * @return void
      */
     public function removeFromTree(Node $node)
@@ -397,7 +399,7 @@ class TreeNodeRepository extends EntityRepository
         } catch (\Exception $e) {
             $this->_em->close();
             $this->_em->getConnection()->rollback();
-            throw $e;
+            throw new \Gedmo\Exception\RuntimeException('Transaction failed', null, $e);
         }
         $this->_em->refresh($node);
         $this->_em->remove($node);
@@ -505,7 +507,7 @@ class TreeNodeRepository extends EntityRepository
     /**
      * Tries to recover the tree
      * 
-     * @throws Exception if something fails in transaction
+     * @throws RuntimeException - if something fails in transaction
      * @return void
      */
     public function recover()
@@ -550,14 +552,14 @@ class TreeNodeRepository extends EntityRepository
         } catch (\Exception $e) {
             $this->_em->close();
             $this->_em->getConnection()->rollback();
-            throw $e;
+            throw new \Gedmo\Exception\RuntimeException('Transaction failed', null, $e);
         }
     }
     
     /**
      * Generally loads configuration from cache
      * 
-     * @throws RuntimeException if no configuration for class found
+     * @throws RuntimeException - if no configuration for class found
      * @return array
      */
     public function getConfiguration() {
@@ -576,7 +578,7 @@ class TreeNodeRepository extends EntityRepository
             }
         }
         if (!$config) {
-            throw new \RuntimeException("TreeNodeRepository: this repository cannot be used on {$this->_entityName} without Tree metadata");
+            throw new \Gedmo\Exception\RuntimeException("TreeNodeRepository: this repository cannot be used on {$this->_entityName} without Tree metadata");
         }
         return $config;
     }