瀏覽代碼

Added forwards compatibility for Doctrine 2.2.

Martin Parsiegla 13 年之前
父節點
當前提交
c2da2b7695
共有 2 個文件被更改,包括 22 次插入12 次删除
  1. 8 8
      Module/WorkerClass.php
  2. 14 4
      Service/GearmanCacheLoader.php

+ 8 - 8
Module/WorkerClass.php

@@ -2,7 +2,7 @@
 
 namespace Mmoreramerino\GearmanBundle\Module;
 
-use Doctrine\Common\Annotations\AnnotationReader;
+use Doctrine\Common\Annotations\Reader;
 use Mmoreramerino\GearmanBundle\Driver\Gearman\Work;
 use Mmoreramerino\GearmanBundle\Module\JobCollection;
 use Mmoreramerino\GearmanBundle\Module\JobClass as Job;
@@ -44,20 +44,20 @@ class WorkerClass
      *
      * @param Work             $classAnnotation ClassAnnotation class
      * @param \ReflectionClass $reflectionClass Reflexion class
-     * @param AnnotationReader $reader          ReaderAnnotation class
+     * @param Reader           $reader          ReaderAnnotation class
      * @param array            $settings        Settings array
      */
-    public function __construct( Work $classAnnotation, \ReflectionClass $reflectionClass, AnnotationReader $reader, array $settings)
+    public function __construct(Work $classAnnotation, \ReflectionClass $reflectionClass, Reader $reader, array $settings)
     {
         $this->namespace = $reflectionClass->getNamespaceName();
 
         $this->callableName =   str_replace('\\', '', ((null !== $classAnnotation->name) ?
-                                ($this->namespace .'\\' .$classAnnotation->name) :
-                                $reflectionClass->getName()));
+            ($this->namespace .'\\' .$classAnnotation->name) :
+            $reflectionClass->getName()));
 
         $this->description =    (null !== $classAnnotation->description) ?
-                                $classAnnotation->description :
-                                'No description is defined';
+            $classAnnotation->description :
+            'No description is defined';
 
         $this->fileName = $reflectionClass->getFileName();
         $this->className = $reflectionClass->getName();
@@ -143,4 +143,4 @@ class WorkerClass
         return $dump;
     }
 
-}
+}

+ 14 - 4
Service/GearmanCacheLoader.php

@@ -53,12 +53,22 @@ class GearmanCacheLoader extends ContainerAware
      */
     public function load(GearmanCache $cache)
     {
-        $reader = new AnnotationReader();
-        AnnotationRegistry::registerFile(__DIR__ . "/../Driver/Gearman/GearmanAnnotations.php");
-        $reader->setDefaultAnnotationNamespace('Mmoreramerino\GearmanBundle\Driver\\');
+        if (version_compare(\Doctrine\Common\Version::VERSION, '2.2.0-DEV', '>=')) {
+            // Register the ORM Annotations in the AnnotationRegistry
+            AnnotationRegistry::registerFile(__DIR__ . "/../Driver/Gearman/GearmanAnnotations.php");
+
+            $reader = new \Doctrine\Common\Annotations\SimpleAnnotationReader();
+            $reader->addNamespace('Mmoreramerino\GearmanBundle\Driver');
+        } else {
+            // Register the ORM Annotations in the AnnotationRegistry
+            AnnotationRegistry::registerFile(__DIR__ . "/../Driver/Gearman/GearmanAnnotations.php");
+
+            $reader = new AnnotationReader();
+            $reader->setDefaultAnnotationNamespace('Mmoreramerino\GearmanBundle\Driver\\');
+        }
+
         $workerCollection = new WorkerCollection;
         $bundles = $this->container->get('kernel')->getBundles();
-
         foreach ($bundles as $bundle) {
             if (!\in_array($bundle->getNamespace(), $this->getParseableBundles())) {
                 continue;