Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore class #2

Merged
merged 4 commits into from
Dec 11, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}