3 * This file is part of the GlobalState package.
5 * (c) Sebastian Bergmann <sebastian@phpunit.de>
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
11 namespace SebastianBergmann\GlobalState;
16 * A blacklist for global state elements that should not be snapshotted.
23 private $globalVariables = array();
28 private $classes = array();
33 private $classNamePrefixes = array();
38 private $parentClasses = array();
43 private $interfaces = array();
48 private $staticAttributes = array();
51 * @param string $variableName
53 public function addGlobalVariable($variableName)
55 $this->globalVariables[$variableName] = true;
59 * @param string $className
61 public function addClass($className)
63 $this->classes[] = $className;
67 * @param string $className
69 public function addSubclassesOf($className)
71 $this->parentClasses[] = $className;
75 * @param string $interfaceName
77 public function addImplementorsOf($interfaceName)
79 $this->interfaces[] = $interfaceName;
83 * @param string $classNamePrefix
85 public function addClassNamePrefix($classNamePrefix)
87 $this->classNamePrefixes[] = $classNamePrefix;
91 * @param string $className
92 * @param string $attributeName
94 public function addStaticAttribute($className, $attributeName)
96 if (!isset($this->staticAttributes[$className])) {
97 $this->staticAttributes[$className] = array();
100 $this->staticAttributes[$className][$attributeName] = true;
104 * @param string $variableName
107 public function isGlobalVariableBlacklisted($variableName)
109 return isset($this->globalVariables[$variableName]);
113 * @param string $className
114 * @param string $attributeName
117 public function isStaticAttributeBlacklisted($className, $attributeName)
119 if (in_array($className, $this->classes)) {
123 foreach ($this->classNamePrefixes as $prefix) {
124 if (strpos($className, $prefix) === 0) {
129 $class = new ReflectionClass($className);
131 foreach ($this->parentClasses as $type) {
132 if ($class->isSubclassOf($type)) {
137 foreach ($this->interfaces as $type) {
138 if ($class->implementsInterface($type)) {
143 if (isset($this->staticAttributes[$className][$attributeName])) {