From ccf3494d5742d96470a5ceba3c314a1aee126d2e Mon Sep 17 00:00:00 2001 From: Pavel Gopanenko Date: Tue, 6 Dec 2011 16:01:18 +0600 Subject: [PATCH 1/3] Add ignore namespace declaration in cache loader Configure like: bundles: SomeBundle: namespace: SomeBundle active: true ignore: - Tests --- .gitignore | 3 +++ Service/GearmanCacheLoader.php | 43 ++++++++++++++++++++++++++++++++-- 2 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6359f32 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/.settings/ +.buildpath +.project \ No newline at end of file diff --git a/Service/GearmanCacheLoader.php b/Service/GearmanCacheLoader.php index 7e96a07..4e81af7 100644 --- a/Service/GearmanCacheLoader.php +++ b/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 @@ 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); @@ -88,7 +99,7 @@ public function getParseableBundles() if (null === $this->settings) { $this->loadSettings(); } - + if (null === $this->bundles) { $this->bundles = array(); @@ -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,25 @@ 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 + * @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; + } } From 352e8666c535fda454f5f4be31c6752030530ea1 Mon Sep 17 00:00:00 2001 From: Pavel Gopanenko Date: Tue, 6 Dec 2011 16:05:07 +0600 Subject: [PATCH 2/3] gitignore for PDT Project --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 6359f32..0ef51f4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ /.settings/ .buildpath -.project \ No newline at end of file +.project From 192506bc866f77c0867521401298a91b9961b55f Mon Sep 17 00:00:00 2001 From: Pavel Gopanenko Date: Tue, 6 Dec 2011 16:01:18 +0600 Subject: [PATCH 3/3] Add ignore namespace declaration in cache loader Configure like: bundles: SomeBundle: namespace: SomeBundle active: true ignore: - Tests --- .gitignore | 3 +++ Service/GearmanCacheLoader.php | 42 +++++++++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 .gitignore 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; + } }