Skip to content

Commit

Permalink
Merge pull request #2 from Itart/development
Browse files Browse the repository at this point in the history
Ignore class
  • Loading branch information
Marc committed Dec 11, 2011
2 parents c90f20e + f02f1ab commit 1b99cb7
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/.settings/
.buildpath
.project
42 changes: 41 additions & 1 deletion Service/GearmanCacheLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -53,14 +60,18 @@ public function load(GearmanCache $cache)
$bundles = $this->container->get('kernel')->getBundles();

foreach ($bundles as $bundle) {

if (!\in_array($bundle->getNamespace(), $this->getParseableBundles())) {
continue;
}
$filesLoader = new WorkerDirectoryLoader(new FileLocator('.'));
$files = $filesLoader->load($bundle->getPath());

foreach ($files as $file) {

if ($this->isIgnore($file['class'])) {
continue;
}

$reflClass = new \ReflectionClass($file['class']);
$classAnnotations = $reader->getClassAnnotations($reflClass);

Expand Down Expand Up @@ -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);
}
}
}
}
}
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 1b99cb7

Please sign in to comment.