diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0ef51f4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/.settings/ +.buildpath +.project diff --git a/Service/GearmanCacheLoader.php b/Service/GearmanCacheLoader.php index 7e96a07..0f49f93 100644 --- a/Service/GearmanCacheLoader.php +++ b/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 @@ public function load(GearmanCache $cache) $bundles = $this->container->get('kernel')->getBundles(); foreach ($bundles as $bundle) { - if (!\in_array($bundle->getNamespace(), $this->getParseableBundles())) { continue; } @@ -61,6 +67,11 @@ public function load(GearmanCache $cache) $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 @@ public function getParseableBundles() 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 @@ public function loadSettings() $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; + } }