/**
  * 
  * @param \AgNetSolutions\Common\Metadata\PropertyAnnotation $annotation
  * @param \ReflectionProperty $reflection
  */
 public function __construct(PropertyAnnotation $annotation, \ReflectionProperty $reflection)
 {
     $this->reflection = $reflection;
     $this->annotation = $annotation;
     if ($this->reflection->isPrivate() || $this->reflection->isProtected()) {
         $this->reflection->setAccessible(true);
     }
 }
function reflectProperty($class, $property)
{
    $propInfo = new ReflectionProperty($class, $property);
    echo "**********************************\n";
    echo "Reflecting on property {$class}::{$property}\n\n";
    echo "__toString():\n";
    var_dump($propInfo->__toString());
    echo "export():\n";
    var_dump(ReflectionProperty::export($class, $property, true));
    echo "export():\n";
    var_dump(ReflectionProperty::export($class, $property, false));
    echo "getName():\n";
    var_dump($propInfo->getName());
    echo "isPublic():\n";
    var_dump($propInfo->isPublic());
    echo "isPrivate():\n";
    var_dump($propInfo->isPrivate());
    echo "isProtected():\n";
    var_dump($propInfo->isProtected());
    echo "isStatic():\n";
    var_dump($propInfo->isStatic());
    $instance = new $class();
    if ($propInfo->isPublic()) {
        echo "getValue():\n";
        var_dump($propInfo->getValue($instance));
        $propInfo->setValue($instance, "NewValue");
        echo "getValue() after a setValue():\n";
        var_dump($propInfo->getValue($instance));
    }
    echo "\n**********************************\n";
}
 private function parseAttribute($class, $attribute)
 {
     $attr = new ReflectionProperty($class, $attribute);
     $annotations = array('validate' => $attr->isProtected(), 'mandatory' => true);
     $comment = $attr->getDocComment();
     if (!$comment) {
         return $annotations;
     }
     if (!preg_match_all('/\\s*\\* @(\\w+) ([^\\n\\r]*)/', $comment, $matches)) {
         return $annotations;
     }
     foreach ($matches[1] as $index => $match) {
         $value = $matches[2][$index];
         switch ($value) {
             case 'false':
                 $value = false;
                 break;
             case 'true':
                 $value = true;
                 break;
         }
         $annotations[$match] = $value;
     }
     return $annotations;
 }
Example #4
0
 public function testCanSetScopeGlue()
 {
     $this->parser->scopeGlue('~');
     $scopeGlue = new ReflectionProperty($this->parser, 'scopeGlue');
     $this->assertTrue($scopeGlue->isProtected());
     $scopeGlue->setAccessible(true);
     $this->assertEquals('~', $scopeGlue->getValue($this->parser));
 }
Example #5
0
 /**
  * Returns true if this property has protected as access level.
  *
  * @return bool
  */
 public function isProtected()
 {
     if ($this->reflectionSource instanceof ReflectionProperty) {
         return $this->reflectionSource->isProtected();
     } else {
         return parent::isProtected();
     }
 }
Example #6
0
 public function __call($method, $args)
 {
     if (property_exists($this, $method) && is_callable($this->{$method})) {
         $check = new \ReflectionProperty($this, $method);
         if ($check->isProtected()) {
             return call_user_func_array($this->{$method}, $args);
         }
     }
 }
Example #7
0
 /**
  * Get output style for the given property's visibility.
  *
  * @param \ReflectionProperty $property
  *
  * @return string
  */
 private function getVisibilityStyle(\ReflectionProperty $property)
 {
     if ($property->isPublic()) {
         return self::IS_PUBLIC;
     } elseif ($property->isProtected()) {
         return self::IS_PROTECTED;
     } else {
         return self::IS_PRIVATE;
     }
 }
Example #8
0
 /**
  * @return self
  */
 public static function from(\ReflectionProperty $from)
 {
     $prop = new static($from->getName());
     $defaults = $from->getDeclaringClass()->getDefaultProperties();
     $prop->value = isset($defaults[$prop->name]) ? $defaults[$prop->name] : NULL;
     $prop->static = $from->isStatic();
     $prop->visibility = $from->isPrivate() ? 'private' : ($from->isProtected() ? 'protected' : 'public');
     $prop->comment = $from->getDocComment() ? preg_replace('#^\\s*\\* ?#m', '', trim($from->getDocComment(), "/* \r\n\t")) : NULL;
     return $prop;
 }
 public function testPublicize_with_protected_static_property()
 {
     $className = __FUNCTION__ . md5(uniqid());
     eval(sprintf('class %s { protected static $foo = "foo_value"; }', $className));
     $reflectionProperty = new ReflectionProperty($className, 'foo');
     $this->assertTrue($reflectionProperty->isStatic());
     $this->assertTrue($reflectionProperty->isProtected());
     $this->assertSame($reflectionProperty, $reflectionProperty->publicize());
     $this->assertSame('foo_value', $reflectionProperty->getValue($className));
 }
Example #10
0
 /**
  * @param object $object
  * @param string $property
  * @param mixed  $value
  */
 protected function setPrivatePropertyValue($object, $property, $value)
 {
     $reflectionProperty = new \ReflectionProperty($object, $property);
     if ($reflectionProperty->isPrivate() || $reflectionProperty->isProtected()) {
         $reflectionProperty->setAccessible(true);
         $reflectionProperty->setValue($object, $value);
         $reflectionProperty->setAccessible(false);
     } else {
         $object->{$property} = $value;
     }
 }
 /**
  * Backwards compatibility method to get 'topic0attop' attribute value.
  *
  * @return boolean Value of topic0attop.
  */
 private function get_topic0attop()
 {
     if (property_exists($this, 'topic0attop')) {
         $reflectionproperty = new ReflectionProperty($this, 'topic0attop');
         if ($reflectionproperty->isProtected()) {
             return $this->topic0attop;
         }
     }
     // Grid format fix #24 not implemented.  Assume section 0 is at the top.
     return 1;
 }
Example #12
0
 function __construct(ReflectionProperty $property)
 {
     $this->name = $property->getName();
     $this->is_public = $property->isPublic();
     $this->is_private = $property->isPrivate();
     $this->is_protected = $property->isProtected();
     $this->is_static = $property->isStatic();
     $this->declaring_class = API_Doc_Class::instance($property->getDeclaringClass());
     list($comment, $meta) = $this->_docComment($property->getDocComment());
     $this->_processDescription($comment);
     $this->_processMeta($meta);
 }
 public static function fromReflection(\ReflectionProperty $ref)
 {
     $property = new static($ref->name);
     $property->setStatic($ref->isStatic())->setVisibility($ref->isPublic() ? self::VISIBILITY_PUBLIC : ($ref->isProtected() ? self::VISIBILITY_PROTECTED : self::VISIBILITY_PRIVATE));
     $docblock = new Docblock($ref);
     $property->setDocblock($docblock);
     $property->setDescription($docblock->getShortDescription());
     $defaultProperties = $ref->getDeclaringClass()->getDefaultProperties();
     if (isset($defaultProperties[$ref->name])) {
         $property->setDefaultValue($defaultProperties[$ref->name]);
     }
     return $property;
 }
 public static function fromReflection(\ReflectionProperty $ref)
 {
     $property = new static();
     $property->setName($ref->name)->setStatic($ref->isStatic())->setVisibility($ref->isPublic() ? self::VISIBILITY_PUBLIC : ($ref->isProtected() ? self::VISIBILITY_PROTECTED : self::VISIBILITY_PRIVATE));
     if ($docComment = $ref->getDocComment()) {
         $property->setDocblock(ReflectionUtils::getUnindentedDocComment($docComment));
     }
     $defaultProperties = $ref->getDeclaringClass()->getDefaultProperties();
     if (isset($defaultProperties[$ref->name])) {
         $property->setDefaultValue($defaultProperties[$ref->name]);
     }
     return $property;
 }
    /**
     * @param ReflectionProperty
     * @return object get => callable(object|NULL $instance), set => callable(object|NULL $instance, mixed $value)
     */
    public function accessProperty(ReflectionProperty $property)
    {
        if (PHP_VERSION_ID >= 50300 or $property->isPublic()) {
            if (PHP_VERSION_ID >= 50300) {
                $property->setAccessible(true);
            }
            return (object) array('get' => $this->callback('$instance', '
					if ($instance)
					{
						return $property->getValue($instance);
					}
					return $property->getValue();
				', array('property' => $property)), 'set' => $this->callback('$instance, $value', '
					if ($instance)
					{
						$property->setValue($instance, $value);
					}
					else
					{
						$property->setValue($value);
					}
				', array('property' => $property)));
        } else {
            if ($property->isProtected()) {
                return (object) array('get' => $this->callback('$instance', '
					if ($instance AND $property->isStatic()) $instance = NULL;
					return call_user_func(array($helperClassName, "__AccessAccessor_php52__get"), $instance, $propertyName);
				', array('property' => $property, 'helperClassName' => $this->getHelperClass($property->getDeclaringClass()), 'propertyName' => $property->getName())), 'set' => $this->callback('$instance, $value', '
					if ($instance AND $property->isStatic()) $instance = NULL;
					return call_user_func(array($helperClassName, "__AccessAccessor_php52__set"), $instance, $propertyName, $value);
				', array('property' => $property, 'helperClassName' => $this->getHelperClass($property->getDeclaringClass()), 'propertyName' => $property->getName())));
            } else {
                if ($property->isPrivate()) {
                    if ($property->isStatic()) {
                        throw new Exception('AccessProperty needs PHP 5.3.0 or newer to access static private property.');
                    }
                    return (object) array('get' => $this->callback('$instance', '
					if ($instance)
					{
						$array = (array) $instance;
						return $array["\\0{$className}\\0{$propertyName}"];
					}
					throw new Exception("AccessProperty needs PHP 5.3.0 or newer to access static private property.");
				', array('helperClassName' => $this->getHelperClass($property->getDeclaringClass()), 'className' => $property->getDeclaringClass()->getName(), 'propertyName' => $property->getName())), 'set' => $this->callback('$instance, $value', '
					throw new Exception("AccessProperty needs PHP 5.3.0 or newer to write to private property.");
				'));
                }
            }
        }
    }
Example #16
0
 public static function getPropertyIdentifier(\ReflectionProperty $reflectionProperty, $className)
 {
     $key = null;
     if ($reflectionProperty->isPrivate()) {
         $key = '\\0' . $className . '\\0' . $reflectionProperty->getName();
     } elseif ($reflectionProperty->isProtected()) {
         $key = '' . "" . '*' . "" . $reflectionProperty->getName();
     } elseif ($reflectionProperty->isPublic()) {
         $key = $reflectionProperty->getName();
     }
     if (null === $key) {
         throw new \InvalidArgumentException('Unable to detect property visibility');
     }
     return $key;
 }
 /**
  * Constructor
  *
  * @param string $declaringAspectClassName Name of the aspect containing the declaration for this introduction
  * @param string $propertyName Name of the property to introduce
  * @param \TYPO3\Flow\Aop\Pointcut\Pointcut $pointcut The pointcut for this introduction
  */
 public function __construct($declaringAspectClassName, $propertyName, \TYPO3\Flow\Aop\Pointcut\Pointcut $pointcut)
 {
     $this->declaringAspectClassName = $declaringAspectClassName;
     $this->propertyName = $propertyName;
     $this->pointcut = $pointcut;
     $propertyReflection = new \ReflectionProperty($declaringAspectClassName, $propertyName);
     if ($propertyReflection->isPrivate()) {
         $this->propertyVisibility = 'private';
     } elseif ($propertyReflection->isProtected()) {
         $this->propertyVisibility = 'protected';
     } else {
         $this->propertyVisibility = 'public';
     }
     $this->propertyDocComment = preg_replace('/@(TYPO3\\\\Flow\\\\Annotations|Flow)\\\\Introduce.+$/mi', 'introduced by ' . $declaringAspectClassName, $propertyReflection->getDocComment());
 }
Example #18
0
 /**
  * Get public and protected properties of current class
  *
  * @return array
  */
 protected function getReflectedProperties()
 {
     if (is_null($this->_ReflectedPropertiesCache)) {
         $this->_ReflectedPropertiesCache = array();
         $refectionClass = new ReflectionClass($this);
         $propertiesArray = $refectionClass->getProperties();
         if (is_array($propertiesArray) and count($propertiesArray) > 0) {
             while (list(, $property) = each($propertiesArray)) {
                 $refectionProperty = new ReflectionProperty($property->class, $property->name);
                 if ($refectionProperty->isPublic() || $refectionProperty->isProtected()) {
                     $this->_ReflectedPropertiesCache[] = $property->name;
                 }
             }
         }
     }
     return $this->_ReflectedPropertiesCache;
 }
 private function emulate($action, $property, $value = null)
 {
     // requested property converted to method (test => getTest())
     $method = $action . ucfirst($property);
     if (method_exists($this, $method)) {
         return $this->{$method}($value);
     }
     if (property_exists($this, $property)) {
         $ref = new \ReflectionProperty($this, $property);
         if ($ref->isProtected() || $ref->isPrivate()) {
             return;
             // prevent private and protected ivars from getting out.
         }
     }
     // catchall method that gets and sets undeclared variables.
     return $this->synthesize($action, $property, $value);
 }
Example #20
0
 protected function getNonpublicProperty($object, $property_name)
 {
     if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
         $ref = new ReflectionProperty(get_class($object), $property_name);
         $ref->setAccessible(true);
         return $ref->getValue($object);
     } else {
         $arr = (array) $object;
         $key = $property_name;
         $ref = new ReflectionProperty(get_class($object), $property_name);
         if ($ref->isProtected()) {
             $key = "*" . $key;
         } elseif ($ref->isPrivate()) {
             $key = "" . get_class($object) . "" . $key;
         }
         return $arr[$key];
     }
 }
Example #21
0
 /**
  * @param \ReflectionProperty $property
  * @return Property
  */
 public function property(\ReflectionProperty $property)
 {
     $phpyProperty = new Property($property->getName());
     $phpyProperty->setStatic($property->isStatic());
     $refClass = $property->getDeclaringClass();
     $defClassValues = $refClass->getDefaultProperties();
     if (isset($defClassValues[$property->getName()])) {
         $phpyProperty->setDefaultValue($defClassValues[$property->getName()]);
     }
     if ($property->isPublic()) {
         $phpyProperty->setVisibility('public');
     } elseif ($property->isProtected()) {
         $phpyProperty->setVisibility('protected');
     } else {
         $phpyProperty->setVisibility('private');
     }
     return $phpyProperty;
 }
 /**
  * Constructor
  *
  * @param string $declaringAspectClassName Name of the aspect containing the declaration for this introduction
  * @param string $propertyName Name of the property to introduce
  * @param Pointcut $pointcut The pointcut for this introduction
  */
 public function __construct($declaringAspectClassName, $propertyName, Pointcut $pointcut)
 {
     $this->declaringAspectClassName = $declaringAspectClassName;
     $this->propertyName = $propertyName;
     $this->pointcut = $pointcut;
     $propertyReflection = new \ReflectionProperty($declaringAspectClassName, $propertyName);
     $classReflection = new \ReflectionClass($declaringAspectClassName);
     $defaultProperties = $classReflection->getDefaultProperties();
     $this->initialValue = $defaultProperties[$propertyName];
     if ($propertyReflection->isPrivate()) {
         $this->propertyVisibility = 'private';
     } elseif ($propertyReflection->isProtected()) {
         $this->propertyVisibility = 'protected';
     } else {
         $this->propertyVisibility = 'public';
     }
     $this->propertyDocComment = preg_replace('/@(Neos\\\\Flow\\\\Annotations|Flow)\\\\Introduce.+$/mi', 'introduced by ' . $declaringAspectClassName, $propertyReflection->getDocComment());
 }
Example #23
0
 protected function buildFieldSignature(\ReflectionProperty $prop) : string
 {
     if ($prop->isProtected()) {
         $code = 'protected ';
     } elseif ($prop->isPrivate()) {
         $code = 'private ';
     } else {
         $code = 'public ';
     }
     if ($prop->isStatic()) {
         $code .= 'static ';
     }
     $code .= '$' . $prop->name;
     $defaults = $prop->getDeclaringClass()->getDefaultProperties();
     if (array_key_exists($prop->name, $defaults)) {
         $code .= ' = ' . $this->buildLiteralCode($defaults[$prop->name]);
     }
     return $code;
 }
Example #24
0
 /**
  * Magic Get metódus
  *
  * @param string $name
  * @return mixed
  */
 public function __get($name)
 {
     if ($name == 'id' && defined(get_class($this) . '::id_property')) {
         return $this->{$this->id_property};
     }
     if ($name == 'code' && defined(get_class($this) . '::code_property')) {
         return $this->{$this->code_property};
     }
     // Checking the property is exists?
     if (property_exists($this, $name)) {
         $property = new \ReflectionProperty($this, $name);
         if ($property->isProtected() || $property->isPublic()) {
             return $this->{$name};
         } else {
             throw new InvalidArgumentException(get_class($this) . " class '" . $name . "' property not accessable!");
         }
     } else {
         throw new InvalidArgumentException(get_class($this) . " class does not have '" . $name . "' property!");
     }
 }
Example #25
0
 /**
  * @param \ReflectionMethod|\ReflectionProperty $element
  * @return bool
  */
 private function filter($element, $static, $public_only)
 {
     if (!$element instanceof \ReflectionMethod && !$element instanceof \ReflectionProperty) {
         throw new \InvalidArgumentException('Parameter must be a member of ReflectionMethod or ReflectionProperty class');
     }
     if ($static !== null && ($element->isStatic() xor $static)) {
         return false;
     }
     if ($element->isPublic()) {
         return true;
     }
     if ($public_only) {
         return false;
     }
     if ($element->isProtected()) {
         return true;
     }
     // $element is then private
     return $element->getDeclaringClass()->getName() === $this->getName();
 }
 /**
  * takes a reflection property and returns a nicely formatted key of the property name
  *
  * @param ReflectionProperty
  * @return string
  */
 protected function _getPropertyKey(ReflectionProperty $property)
 {
     $static = $property->isStatic() ? ' static' : '';
     if ($property->isPublic()) {
         return 'public' . $static . ' ' . $property->getName();
     }
     if ($property->isProtected()) {
         return 'protected' . $static . ' ' . $property->getName();
     }
     if ($property->isPrivate()) {
         return 'private' . $static . ' ' . $property->getName();
     }
 }
Example #27
0
function _pprintr_object_ReflectionProperty(ReflectionProperty $property, $var, $indent, $indentStep)
{
    $modifiers = array();
    $property->setAccessible(true);
    if (defined('PPRINTR_INCLUDE_PROTECTED') && PPRINTR_INCLUDE_PROTECTED) {
        $property->isPublic() && ($modifiers[] = "public");
        $property->isProtected() && ($modifiers[] = "protected");
        $property->isPrivate() && ($modifiers[] = "private");
    }
    $property->isStatic() && ($modifiers[] = "static");
    $modifiers = implode(' ', $modifiers);
    $name = $property->getName();
    $value = pprintr($property->getValue($var), $indent + $indentStep, $indentStep);
    $str = "{$name} => {$value}";
    if ($modifiers != []) {
        $str = "{$modifiers} {$str}";
    }
    return $str;
}
Example #28
0
 /**
  * Property access level label.
  *
  * @param \ReflectionProperty $property
  * @return string
  */
 private function getAccess(\ReflectionProperty $property)
 {
     if ($property->isPrivate()) {
         return 'private';
     } elseif ($property->isProtected()) {
         return 'protected';
     }
     return 'public';
 }
Example #29
0
 public function __construct()
 {
     $property = new ReflectionProperty(get_class($this), '_values');
     var_dump($property->isProtected());
 }
Example #30
0
 /**
  * @param string $class
  * @param string $property
  *
  * @return string
  */
 public static function reflectClassProperty($class, $property, $output = true)
 {
     $data = '';
     $reflectionClass = new \ReflectionClass($class);
     $reflectionProperty = new \ReflectionProperty($class, $property);
     $defaultPropertyValues = $reflectionClass->getDefaultProperties();
     $comment = $reflectionProperty->getDocComment();
     if (!empty($comment)) {
         $data .= "\n";
         $data .= "\t";
         $data .= $comment;
     }
     $data .= "\n";
     $data .= "\t";
     $data .= $reflectionProperty->isPublic() ? 'public ' : '';
     $data .= $reflectionProperty->isPrivate() ? 'private ' : '';
     $data .= $reflectionProperty->isProtected() ? 'protected ' : '';
     $data .= $reflectionProperty->isStatic() ? 'static ' : '';
     $data .= '$' . $reflectionProperty->name;
     if (isset($defaultPropertyValues[$property])) {
         $data .= ' = ' . self::getDebugInformation($defaultPropertyValues[$property]);
     }
     $data .= ';';
     if ($output) {
         self::output($data);
     }
     return $data;
 }