Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Added exclution of class names to Zend\Di\Definition\IntrospectionRul…
Browse files Browse the repository at this point in the history
…eset

Fixed bug in Zend\Code\Scanner\ClassScanner when finding method names
Added caching of classes to filescanners in Zend\Code\Scanner\DirectoryScanner
  • Loading branch information
Ralph Schindler committed Jul 20, 2011
1 parent ded6e9c commit 144ea5b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Definition/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,19 @@ public function compile()
{
$data = array();

$gRules = $this->getIntrospectionRuleset()->getGeneralRules();

/* @var $classScanner Zend\Code\Scanner\DerivedClassScanner */
foreach ($this->directoryScanner->getClasses(true, true) as $classScanner) {

if ($gRules['excludedClassPatterns']) {
foreach ($gRules['excludedClassPatterns'] as $ecPattern) {
if (preg_match($ecPattern, $classScanner->getName())) {
continue 2;
}
}
}

// determine supertypes
$superTypes = array();
if (($parentClasses = $classScanner->getParentClasses()) !== null) {
Expand Down
20 changes: 20 additions & 0 deletions src/Definition/IntrospectionRuleset.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@

class IntrospectionRuleset
{
const TYPE_GENERAL = 'general';
const TYPE_CONSTRUCTOR = 'constructor';
const TYPE_SETTER = 'setter';
const TYPE_INTERFACE = 'interface';

protected $generalRules = array(
'excludedClassPatterns' => array('/[\w\\\\]*Exception\w*/')
);

protected $constructorRules = array(
'enabled' => true,
'includedClasses' => array(),
Expand Down Expand Up @@ -38,6 +43,9 @@ public function __construct($config = null)
public function addRule($strategy, $name, $value)
{
switch ($strategy) {
case self::TYPE_GENERAL:
$rule = &$this->generalRules;
break;
case self::TYPE_CONSTRUCTOR:
$rule = &$this->constructorRules;
break;
Expand Down Expand Up @@ -72,19 +80,31 @@ public function getRules($ruleType)
{
if (!$ruleType) {
return array(
self::TYPE_GENERAL => $this->generalRules,
self::TYPE_CONSTRUCTOR => $this->constructorRules,
self::TYPE_SETTER => $this->setterRules,
self::TYPE_INTERFACE => $this->interfaceRules
);
} else {
switch ($ruleType) {
case self::TYPE_GENERAL: return $this->generalRules;
case self::TYPE_CONSTRUCTOR: return $this->constructorRules;
case self::TYPE_SETTER: return $this->setterRules;
case self::TYPE_INTERFACE: return $this->interfaceRules;
}
}
}

public function addGeneralRule($name, $value)
{
$this->addRule(self::TYPE_GENERAL, $name, $value);
}

public function getGeneralRules()
{
return $this->generalRules;
}

public function addConstructorRule($name, $value)
{
$this->addRule(self::TYPE_CONSTRUCTOR, $name, $value);
Expand Down

0 comments on commit 144ea5b

Please sign in to comment.