示例#1
0
 /**
  * Activates or deactivates filtering.
  *
  * @param $filter boolean       	
  * @throws InvalidArgumentException
  * @since Method available since Release 3.0.0
  */
 public static function setFilter($filter)
 {
     if (is_bool($filter)) {
         self::$filter = $filter;
     } else {
         throw PHPCoverage_Util_InvalidArgumentHelper::factory(1, 'boolean');
     }
 }
示例#2
0
 /**
  * @param  Iterator $iterator
  * @param  array    $suffixes
  * @param  array    $prefixes
  */
 public function __construct(Iterator $iterator, $suffixes = array(), $prefixes = array())
 {
     if (is_string($suffixes)) {
         if (!empty($suffixes)) {
             $suffixes = array($suffixes);
         } else {
             $suffixes = array();
         }
     }
     if (!is_array($suffixes)) {
         throw PHPCoverage_Util_InvalidArgumentHelper::factory(2, 'array or string');
     }
     $this->suffixes = $suffixes;
     if (is_string($prefixes)) {
         if (!empty($prefixes)) {
             $prefixes = array($prefixes);
         } else {
             $prefixes = array();
         }
     }
     if (!is_array($prefixes)) {
         throw PHPCoverage_Util_InvalidArgumentHelper::factory(3, 'array or string');
     }
     $this->prefixes = $prefixes;
     parent::__construct($iterator);
 }
示例#3
0
 /**
  * Returns the value of an object's attribute.
  * This also works for attributes that are declared protected or private.
  *
  * @param $object object       	
  * @param $attributeName string       	
  * @return mixed
  * @throws InvalidArgumentException
  * @since Method available since Release 3.4.0
  */
 public static function getObjectAttribute($object, $attributeName)
 {
     if (!is_object($object)) {
         throw PHPCoverage_Util_InvalidArgumentHelper::factory(1, 'object');
     }
     if (!is_string($attributeName)) {
         throw PHPCoverage_Util_InvalidArgumentHelper::factory(2, 'string');
     }
     //PHPCoverage_Framework_Assert::assertObjectHasAttribute ( $attributeName, $object );
     try {
         $attribute = new ReflectionProperty($object, $attributeName);
     } catch (ReflectionException $e) {
         // Workaround for http://bugs.php.net/46064
         if (version_compare(PHP_VERSION, '5.2.7', '<')) {
             $reflector = new ReflectionObject($object);
             $attributes = $reflector->getProperties();
             foreach ($attributes as $_attribute) {
                 if ($_attribute->getName() == $attributeName) {
                     $attribute = $_attribute;
                     break;
                 }
             }
         }
         $reflector = new ReflectionObject($object);
         while ($reflector = $reflector->getParentClass()) {
             try {
                 $attribute = $reflector->getProperty($attributeName);
                 break;
             } catch (ReflectionException $e) {
             }
         }
     }
     if ($attribute->isPublic()) {
         return $object->{$attributeName};
     } else {
         $array = (array) $object;
         $protectedName = "*" . $attributeName;
         if (array_key_exists($protectedName, $array)) {
             return $array[$protectedName];
         } else {
             $classes = self::getHierarchy(get_class($object));
             foreach ($classes as $class) {
                 $privateName = sprintf("%s%s", $class, $attributeName);
                 if (array_key_exists($privateName, $array)) {
                     return $array[$privateName];
                 }
             }
         }
     }
     throw new Exception(sprintf('Attribute "%s" not found in object.', $attributeName));
 }