Przeglądaj źródła

changed SPL exceptions to bundle exceptions

Johannes Schmitt 14 lat temu
rodzic
commit
097939443e

+ 2 - 1
DependencyInjection/Compiler/RegisterEncodersPass.php

@@ -2,6 +2,7 @@
 
 namespace JMS\SerializerBundle\DependencyInjection\Compiler;
 
+use JMS\SerializerBundle\Exception\RuntimeException;
 use Symfony\Component\DependencyInjection\ContainerBuilder;
 use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
 
@@ -12,7 +13,7 @@ class RegisterEncodersPass implements CompilerPassInterface
         $encoders = array();
         foreach ($container->findTaggedServiceIds('jms_serializer.encoder') as $id => $attributes) {
             if (!isset($attributes[0]['format'])) {
-                throw new \RuntimeException(sprintf('"format" attribute must be specified for service "%s" and tag "jms_serializer.encoder".', $id));
+                throw new RuntimeException(sprintf('"format" attribute must be specified for service "%s" and tag "jms_serializer.encoder".', $id));
             }
 
             $encoders[$attributes[0]['format']] = $id;

+ 2 - 1
Serializer/Normalizer/ArrayCollectionNormalizer.php

@@ -18,6 +18,7 @@
 
 namespace JMS\SerializerBundle\Serializer\Normalizer;
 
+use JMS\SerializerBundle\Exception\InvalidArgumentException;
 use JMS\SerializerBundle\Exception\UnsupportedException;
 use Doctrine\Common\Collections\ArrayCollection;
 use Symfony\Component\Serializer\Normalizer\SerializerAwareNormalizer;
@@ -43,7 +44,7 @@ class ArrayCollectionNormalizer extends SerializerAwareNormalizer
     public function denormalize($data, $type, $format = null)
     {
         if (!is_array($data)) {
-            throw new \InvalidArgumentException('$data must be an array.');
+            throw new InvalidArgumentException('$data must be an array.');
         }
 
         if (!$this->supportsDenormalization($data, $type, $format)) {

+ 3 - 2
Serializer/Normalizer/NativePhpTypeNormalizer.php

@@ -18,6 +18,7 @@
 
 namespace JMS\SerializerBundle\Serializer\Normalizer;
 
+use JMS\SerializerBundle\Exception\RuntimeException;
 use JMS\SerializerBundle\Exception\UnsupportedException;
 use Symfony\Component\Serializer\Normalizer\SerializerAwareNormalizer;
 
@@ -72,7 +73,7 @@ class NativePhpTypeNormalizer extends SerializerAwareNormalizer
             return (string) $data;
         } else if ('DateTime' === $type) {
             if (!is_array($data) || !isset($data['time'], $data['timezone'])) {
-                throw new \RuntimeException('Invalid input data for type "DateTime".');
+                throw new RuntimeException('Invalid input data for type "DateTime".');
             }
 
             $date = new \DateTime($data['time']);
@@ -81,7 +82,7 @@ class NativePhpTypeNormalizer extends SerializerAwareNormalizer
             return $date;
         } else if (0 === strpos($type, 'array')) {
             if (!is_array($data)) {
-                throw new \RuntimeException('Invalid input data for type "array".');
+                throw new RuntimeException('Invalid input data for type "array".');
             }
 
             // unspecified array

+ 2 - 1
Serializer/Normalizer/PropertyBasedNormalizer.php

@@ -18,6 +18,7 @@
 
 namespace JMS\SerializerBundle\Serializer\Normalizer;
 
+use JMS\SerializerBundle\Exception\RuntimeException;
 use JMS\SerializerBundle\Annotation\Type;
 use JMS\SerializerBundle\Annotation\ExclusionPolicy;
 use JMS\SerializerBundle\Exception\InvalidArgumentException;
@@ -107,7 +108,7 @@ class PropertyBasedNormalizer extends SerializerAwareNormalizer
                 }
 
                 if (null === $type = $propertyMetadata->getType()) {
-                    throw new \RuntimeException(sprintf('You must define the type for %s::$%s.', $propertyMetadata->getClass(), $propertyMetadata->getName()));
+                    throw new RuntimeException(sprintf('You must define the type for %s::$%s.', $propertyMetadata->getClass(), $propertyMetadata->getName()));
                 }
 
                 $value = $this->serializer->denormalize($data[$serializedName], $type, $format);

+ 2 - 1
Serializer/Serializer.php

@@ -18,6 +18,7 @@
 
 namespace JMS\SerializerBundle\Serializer;
 
+use JMS\SerializerBundle\Exception\RuntimeException;
 use Symfony\Component\Serializer\SerializerAwareInterface;
 use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
 use Symfony\Component\Serializer\SerializerInterface;
@@ -138,7 +139,7 @@ class Serializer implements SerializerInterface
     protected function getEncoder($format)
     {
         if (!isset($this->encoderMap[$format])) {
-            throw new \RuntimeException(sprintf('No encoder found for format "%s".', $format));
+            throw new RuntimeException(sprintf('No encoder found for format "%s".', $format));
         }
 
         return $this->encoderMap[$format];

+ 2 - 1
Serializer/SerializerFactory.php

@@ -18,6 +18,7 @@
 
 namespace JMS\SerializerBundle\Serializer;
 
+use JMS\SerializerBundle\Exception\RuntimeException;
 use Symfony\Component\DependencyInjection\ContainerInterface;
 
 class SerializerFactory
@@ -38,7 +39,7 @@ class SerializerFactory
         }
 
         if (!isset($this->serializerMap[$version])) {
-            throw new \RuntimeException(sprintf('There was no serializer configured for version "%s".', $version));
+            throw new RuntimeException(sprintf('There was no serializer configured for version "%s".', $version));
         }
 
         return $this->container->get($this->serializerMap[$version]);

+ 2 - 1
Tests/PerformanceTest.php

@@ -2,6 +2,7 @@
 
 namespace JMS\SerializerBundle\Tests;
 
+use JMS\SerializerBundle\Exception\InvalidArgumentException;
 use Symfony\Component\DependencyInjection\Compiler\ResolveDefinitionTemplatesPass;
 
 use JMS\SerializerBundle\JMSSerializerBundle;
@@ -89,7 +90,7 @@ class PerformanceTest extends \PHPUnit_Framework_TestCase
     private function printResults($test, $time, $iterations)
     {
         if (0 == $iterations) {
-            throw new \InvalidArgumentException('$iterations cannot be zero.');
+            throw new InvalidArgumentException('$iterations cannot be zero.');
         }
 
         $title = $test." results:\n";