This repository has been archived by the owner on Jan 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
755 additions
and
288 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<?php | ||
|
||
namespace Zend\Di\Definition; | ||
|
||
class IntrospectionRuleset | ||
{ | ||
const TYPE_CONSTRUCTOR = 'constructor'; | ||
const TYPE_SETTER = 'setter'; | ||
const TYPE_INTERFACE = 'interface'; | ||
|
||
protected $construtorRules = array( | ||
'enabled' => true, | ||
'includedClasses' => array(), | ||
'excludedClasses' => array(), | ||
); | ||
|
||
protected $setterRules = array( | ||
'enabled' => true, | ||
'pattern' => '^set[A-Z]{1}\w*', | ||
'includedClasses' => array(), | ||
'excludedClasses' => array('ArrayObject'), | ||
'methodMaximumParams' => 1, | ||
'paramCanBeOptional' => true, | ||
); | ||
|
||
protected $interfaceRules = array( | ||
'enabled' => true, | ||
'pattern' => '\w*Aware\w*', | ||
'includedInterfaces' => array(), | ||
'excludedInterfaces' => array() | ||
); | ||
|
||
public function __construct($config = null) | ||
{ | ||
|
||
} | ||
|
||
public function addRule($strategy, $name, $value) | ||
{ | ||
switch ($strategy) { | ||
case self::TYPE_CONSTRUCTOR: | ||
$rule = &$this->construtorRules; | ||
break; | ||
case self::TYPE_SETTER: | ||
$rule = &$this->setterRules; | ||
break; | ||
case self::TYPE_INTERFACE: | ||
$rule = &$this->interfaceRules; | ||
break; | ||
} | ||
|
||
if (!isset($rule[$name])) { | ||
throw new \InvalidArgumentException('The rule name provided is not a valid rule name.'); | ||
} | ||
|
||
switch (gettype($rule[$name])) { | ||
case 'array': | ||
array_push($rule[$name], $value); | ||
break; | ||
case 'bool': | ||
$rule[$name] = (bool) $value; | ||
break; | ||
case 'string': | ||
$rule[$name] = (string) $value; | ||
break; | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
public function getRules($ruleType) | ||
{ | ||
if (!$ruleType) { | ||
return array( | ||
self::TYPE_CONSTRUCTOR => $this->construtorRules, | ||
self::TYPE_SETTER => $this->setterRules, | ||
self::TYPE_INTERFACE => $this->interfaceRules | ||
); | ||
} else { | ||
switch ($ruleType) { | ||
case self::TYPE_CONSTRUCTOR: return $this->construtorRules; | ||
case self::TYPE_SETTER: return $this->setterRules; | ||
case self::TYPE_INTERFACE: return $this->interfaceRules; | ||
} | ||
} | ||
} | ||
|
||
public function addConstructorRule($name, $value) | ||
{ | ||
$this->addRule(self::TYPE_CONSTRUCTOR, $name, $value); | ||
} | ||
|
||
public function getConstructorRules() | ||
{ | ||
return $this->construtorRules; | ||
} | ||
|
||
public function addSetterRule($name, $value) | ||
{ | ||
$this->addRule(self::TYPE_SETTER, $name, $value); | ||
} | ||
|
||
public function getSetterRules() | ||
{ | ||
return $this->setterRules; | ||
} | ||
|
||
public function addInterfaceRule($name, $value) | ||
{ | ||
$this->addRule(self::TYPE_INTERFACE, $name, $value); | ||
} | ||
|
||
public function getInterfaceRules() | ||
{ | ||
return $this->interfaceRules; | ||
} | ||
|
||
} |
Oops, something went wrong.