Browse Source

Merge pull request #2 from Itart/development

Ignore class
Marc 13 years ago
parent
commit
1b99cb74ec
2 changed files with 44 additions and 1 deletions
  1. 3 0
      .gitignore
  2. 41 1
      Service/GearmanCacheLoader.php

+ 3 - 0
.gitignore

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

+ 41 - 1
Service/GearmanCacheLoader.php

@@ -36,6 +36,13 @@ class GearmanCacheLoader extends ContainerAware
      */
     private $bundles = null;
 
+    /**
+     * Ignored namespaces
+     *
+     * @var Array
+     */
+    private $ignored = null;
+
     /**
      * This method load all data and saves all annotations into cache.
      * Also, it load all settings from Yaml file format
@@ -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);
 
@@ -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,26 @@ 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 Class name
+     *
+     * @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;
+    }
 }