소스 검색

Add ignore namespace declaration in cache loader
Configure like:
bundles:
SomeBundle:
namespace: SomeBundle
active: true
ignore:
- Tests

Pavel Gopanenko 13 년 전
부모
커밋
ccf3494d57
2개의 변경된 파일44개의 추가작업 그리고 2개의 파일을 삭제
  1. 3 0
      .gitignore
  2. 41 2
      Service/GearmanCacheLoader.php

+ 3 - 0
.gitignore

@@ -0,0 +1,3 @@
+/.settings/
+.buildpath
+.project

+ 41 - 2
Service/GearmanCacheLoader.php

@@ -35,6 +35,13 @@ class GearmanCacheLoader extends ContainerAware
      * @var Array
      */
     private $bundles = null;
+    
+    /**
+     * Ignored namespaces
+     *
+     * @var Array
+     */
+    private $ignored = null;
 
     /**
      * This method load all data and saves all annotations into cache.
@@ -53,7 +60,6 @@ class GearmanCacheLoader extends ContainerAware
         $bundles = $this->container->get('kernel')->getBundles();
 
         foreach ($bundles as $bundle) {
-
             if (!\in_array($bundle->getNamespace(), $this->getParseableBundles())) {
                 continue;
             }
@@ -61,6 +67,11 @@ class GearmanCacheLoader extends ContainerAware
             $files = $filesLoader->load($bundle->getPath());
 
             foreach ($files as $file) {
+                
+                if ($this->isIgnore($file['class'])) {
+                    continue;
+                }
+                
                 $reflClass = new \ReflectionClass($file['class']);
                 $classAnnotations = $reader->getClassAnnotations($reflClass);
 
@@ -88,7 +99,7 @@ class GearmanCacheLoader extends ContainerAware
         if (null === $this->settings) {
             $this->loadSettings();
         }
-
+        
         if (null === $this->bundles) {
             $this->bundles = array();
 
@@ -99,6 +110,13 @@ class GearmanCacheLoader extends ContainerAware
                     if ('' !== $properties['namespace']) {
                         $this->bundles[] = $properties['namespace'];
                     }
+                    
+                    if (isset($properties['ignore'])) {
+                        $ignored = (array) $properties['ignore'];
+                        while ($ignored) {
+                            $this->ignored[] = $properties['namespace'] . '\\' . array_shift($ignored);
+                        }
+                    }
                 }
             }
         }
@@ -127,4 +145,25 @@ class GearmanCacheLoader extends ContainerAware
         $this->settings = $this->container->get('gearman.settings')->loadSettings();
         return $this->settings;
     }
+    
+    /**
+     * Checks the class it belongs to the ignored
+     *
+     * @param string $class
+     * @return boolean
+     */
+    public function isIgnore($class)
+    {
+        if (null === $this->ignored) {
+            return false;
+        }
+        
+        foreach ($this->ignored as $ns) {
+            if (strstr($class, $ns) !== false) {
+                return true;
+            }
+        }
+        
+        return false;
+    }
 }