コード例 #1
0
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";
}
コード例 #2
0
 /**
  * EntityPropertyMetadata constructor.
  *
  * @param string                                                    $propertyName
  * @param \GraphAware\Neo4j\OGM\Metadata\PropertyAnnotationMetadata $propertyAnnotationMetadata
  */
 public function __construct($propertyName, \ReflectionProperty $reflectionProperty, PropertyAnnotationMetadata $propertyAnnotationMetadata)
 {
     $this->propertyName = $propertyName;
     $this->reflectionProperty = $reflectionProperty;
     $this->propertyAnnotationMetadata = $propertyAnnotationMetadata;
     $this->isAccessible = $reflectionProperty->isPublic();
 }
コード例 #3
0
ファイル: property.php プロジェクト: azuya/Wi3
 public function __construct($class, $property)
 {
     $property = new ReflectionProperty($class, $property);
     list($description, $tags) = Kodoc::parse($property->getDocComment());
     $this->description = $description;
     if ($modifiers = $property->getModifiers()) {
         $this->modifiers = '<small>' . implode(' ', Reflection::getModifierNames($modifiers)) . '</small> ';
     }
     if (isset($tags['var'])) {
         if (preg_match('/^(\\S*)(?:\\s*(.+?))?$/', $tags['var'][0], $matches)) {
             $this->type = $matches[1];
             if (isset($matches[2])) {
                 $this->description = Markdown($matches[2]);
             }
         }
     }
     $this->property = $property;
     // Show the value of static properties, but only if they are public or we are php 5.3 or higher and can force them to be accessible
     if ($property->isStatic() and ($property->isPublic() or version_compare(PHP_VERSION, '5.3', '>='))) {
         // Force the property to be accessible
         if (version_compare(PHP_VERSION, '5.3', '>=')) {
             $property->setAccessible(TRUE);
         }
         // Don't debug the entire object, just say what kind of object it is
         if (is_object($property->getValue($class))) {
             $this->value = '<pre>object ' . get_class($property->getValue($class)) . '()</pre>';
         } else {
             $this->value = Kohana::debug($property->getValue($class));
         }
     }
 }
コード例 #4
0
 /**
  * {@inheritDoc}
  */
 public function getReference($name, $property = null)
 {
     if (isset($this->objectsCache[$name])) {
         try {
             $reference = $this->entityManager->merge($this->objectsCache[$name]);
         } catch (\Exception $e) {
             var_dump($e->getMessage());
             var_dump($this->objectsCache[$name]);
             exit;
         }
     } else {
         if (isset($this->references[$name])) {
             $reference = $this->references[$name];
         } else {
             throw new \UnexpectedValueException('Reference ' . $name . ' is not defined');
         }
     }
     if ($property !== null) {
         if (property_exists($reference, $property)) {
             $prop = new \ReflectionProperty($reference, $property);
             if ($prop->isPublic()) {
                 return $reference->{$property};
             }
         }
         $getter = 'get' . ucfirst($property);
         if (method_exists($reference, $getter) && is_callable(array($reference, $getter))) {
             return $reference->{$getter}();
         }
         throw new \UnexpectedValueException('Property ' . $property . ' is not defined for reference ' . $name);
     }
     return $reference;
 }
コード例 #5
0
ファイル: ArrayAccessT.php プロジェクト: bogdananton/vsc
 /**
  * @param string $sOffset
  */
 public function offsetUnset($sOffset)
 {
     $oProperty = new \ReflectionProperty($this, $sOffset);
     if ($oProperty->isPublic()) {
         unset($this->{$sOffset});
     }
 }
コード例 #6
0
ファイル: ObjectMixin.php プロジェクト: jakubkulhan/guestbook
 /**
  * Call to undefined method.
  *
  * @param  string  method name
  * @param  array   arguments
  * @return mixed
  * @throws \MemberAccessException
  */
 public static function call($_this, $name, $args)
 {
     $class = get_class($_this);
     if ($name === '') {
         throw new MemberAccessException("Call to class '{$class}' method without name.");
     }
     // event functionality
     if (preg_match('#^on[A-Z]#', $name)) {
         $rp = new ReflectionProperty($class, $name);
         if ($rp->isPublic() && !$rp->isStatic()) {
             $list = $_this->{$name};
             if (is_array($list) || $list instanceof Traversable) {
                 foreach ($list as $handler) {
                     /**/
                     fixCallback($handler);
                     /**/
                     if (!is_callable($handler)) {
                         $able = is_callable($handler, TRUE, $textual);
                         throw new InvalidStateException("Event handler '{$textual}' is not " . ($able ? 'callable.' : 'valid PHP callback.'));
                     }
                     call_user_func_array($handler, $args);
                 }
             }
             return NULL;
         }
     }
     // extension methods
     if ($cb = self::extensionMethod($class, $name)) {
         array_unshift($args, $_this);
         return call_user_func_array($cb, $args);
     }
     throw new MemberAccessException("Call to undefined method {$class}::{$name}().");
 }
コード例 #7
0
 public function __call($name, $args)
 {
     $class = get_class($this);
     if ($name === '') {
         throw new MemberAccessException("Call to class '{$class}' method without name.");
     }
     if (preg_match('#^on[A-Z]#', $name)) {
         $rp = new ReflectionProperty($class, $name);
         if ($rp->isPublic() && !$rp->isStatic()) {
             $list = $this->{$name};
             if (is_array($list) || $list instanceof Traversable) {
                 foreach ($list as $handler) {
                     if (is_object($handler)) {
                         call_user_func_array(array($handler, '__invoke'), $args);
                     } else {
                         call_user_func_array($handler, $args);
                     }
                 }
             }
             return NULL;
         }
     }
     if ($cb = self::extensionMethod("{$class}::{$name}")) {
         array_unshift($args, $this);
         return call_user_func_array($cb, $args);
     }
     throw new MemberAccessException("Call to undefined method {$class}::{$name}().");
 }
コード例 #8
0
ファイル: fileTest.php プロジェクト: RanLee/XoopsCore
 public function test_publicProperties()
 {
     $items = array('folder', 'name', 'info', 'handle', 'lock');
     foreach ($items as $item) {
         $prop = new ReflectionProperty($this->myClass, $item);
         $this->assertTrue($prop->isPublic());
     }
 }
コード例 #9
0
ファイル: property.php プロジェクト: naderman/ezc-reflection
 /**
  * Returns true if this property has public as access level.
  *
  * @return bool
  */
 public function isPublic()
 {
     if ($this->reflectionSource instanceof ReflectionProperty) {
         return $this->reflectionSource->isPublic();
     } else {
         return parent::isPublic();
     }
 }
コード例 #10
0
 public function test___publicProperties()
 {
     $items = array('vars', 'cleanVars', 'plugin_path');
     foreach ($items as $item) {
         $prop = new ReflectionProperty($this->myClass, $item);
         $this->assertTrue($prop->isPublic());
     }
 }
コード例 #11
0
 public function test___publicProperties()
 {
     $items = array('handler', 'active', 'path_basic', 'path_plugin', 'configPath', 'name', 'config', 'message');
     foreach ($items as $item) {
         $prop = new ReflectionProperty($this->myclass, $item);
         $this->assertTrue($prop->isPublic());
     }
 }
コード例 #12
0
 public function test___publicProperties()
 {
     $items = array('tempArr', 'themeSetData', 'imagesData', 'templatesData');
     foreach ($items as $item) {
         $prop = new ReflectionProperty($this->myclass, $item);
         $this->assertTrue($prop->isPublic());
     }
 }
コード例 #13
0
 public function test___publicProperties()
 {
     $items = array('db');
     foreach ($items as $item) {
         $prop = new ReflectionProperty($this->myclass, $item);
         $this->assertTrue($prop->isPublic());
     }
 }
コード例 #14
0
 public function test___publicProperties()
 {
     $items = array('ldap_provisioning', 'ldap_provisioning_upd', 'ldap_field_mapping', 'ldap_provisioning_group');
     foreach ($items as $item) {
         $prop = new ReflectionProperty($this->object, $item);
         $this->assertTrue($prop->isPublic());
     }
 }
コード例 #15
0
 private function getProperty($classOrObject, $property)
 {
     $property = new \ReflectionProperty(is_object($classOrObject) ? get_class($classOrObject) : $classOrObject, $property);
     if (!$property->isPublic()) {
         $property->setAccessible(true);
     }
     return $property->isStatic() ? $property->getValue($classOrObject) : $property->getValue();
 }
コード例 #16
0
 public function test___publicProperties()
 {
     $items = array('table', 'keyName', 'className', 'table_link', 'identifierName', 'field_link', 'field_object', 'keyName_link');
     foreach ($items as $item) {
         $prop = new ReflectionProperty($this->myClass, $item);
         $this->assertTrue($prop->isPublic());
     }
 }
コード例 #17
0
 /**
  * Returns 'true' if the class property is public (it exists and its scope is 'public').
  *
  * @param string $classNamespace The fully qualified name of the class
  * @param string $propertyName
  *
  * @return bool
  */
 public function isPublic($classNamespace, $propertyName)
 {
     if (!property_exists($classNamespace, $propertyName)) {
         return false;
     }
     $propertyMetadata = new \ReflectionProperty($classNamespace, $propertyName);
     return $propertyMetadata->isPublic();
 }
コード例 #18
0
 /**
  * {@inheritdoc}
  * @throws PropertyDefinitionNotFoundException
  */
 public function analyze(DefinitionAnalyzer $analyzer, ClassDefinition $classDefinition, \ReflectionProperty $reflectionProperty)
 {
     $propertyName = $reflectionProperty->getName();
     // Set property metadata
     if ($classDefinition->hasProperty($propertyName)) {
         $classDefinition->getProperty($propertyName)->setIsPublic($reflectionProperty->isPublic())->setModifiers($reflectionProperty->getModifiers());
     }
 }
コード例 #19
0
 public function setAttributes(array $params)
 {
     foreach ($params as $key => $param) {
         if (property_exists($this, $key) and $reflectionProp = new \ReflectionProperty(get_class($this), $key) and $reflectionProp->isPublic()) {
             $this->{$key} = $param;
         }
     }
     return $this;
 }
コード例 #20
0
 /**
  * @param $argument
  * @return bool
  */
 public function hasArgument($argument)
 {
     try {
         $reflectionProperty = new \ReflectionProperty($this, $argument);
     } catch (\ReflectionException $e) {
         return false;
     }
     return $reflectionProperty->isPublic();
 }
コード例 #21
0
ファイル: Reflection.php プロジェクト: ptrofimov/xpmock
 public function __set($key, $value)
 {
     $property = new \ReflectionProperty($this->class, $key);
     if (!$property->isPublic()) {
         $property->setAccessible(true);
     }
     $property->isStatic() ? $property->setValue($value) : $property->setValue($this->object, $value);
     return $this;
 }
コード例 #22
0
ファイル: PropertyEnumerator.php プロジェクト: saj696/pipe
 /**
  * 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;
     }
 }
コード例 #23
0
 /**
  * {@inheritdoc}
  */
 public function setValue(&$object, $propertyPath, $value)
 {
     if ($this->isWritable($object, $propertyPath)) {
         $property = new \ReflectionProperty(get_class($object), $propertyPath);
         if (!$property->isPublic()) {
             $property->setAccessible(true);
         }
         $property->setValue($object, $value);
     }
 }
コード例 #24
0
ファイル: Mapper.php プロジェクト: nawarian/EventProxy
 private function getPropertyFromObject($object, $property)
 {
     if (!is_object($object)) {
         throw new InvalidArgumentException('Object expected as first parameter.');
     }
     $ref = new \ReflectionProperty($object, $property);
     if (!$ref->isPublic()) {
         $ref->setAccessible(true);
     }
     return $ref->getValue($object);
 }
コード例 #25
0
 /**
  * Generic class property resolver.
  *
  * @param \ReflectionProperty $property
  * @param ClassMetadata       $classMetadata
  *
  * @return PropertyMetadata Resolved property metadata
  */
 protected function resolvePropertyMetadata(\ReflectionProperty $property, ClassMetadata $classMetadata) : PropertyMetadata
 {
     // Create method metadata instance
     $propertyMetadata = $classMetadata->propertiesMetadata[$property->getName()] ?? new PropertyMetadata($classMetadata);
     $propertyMetadata->name = $property->getName();
     $propertyMetadata->modifiers = $property->getModifiers();
     $propertyMetadata->isPublic = $property->isPublic();
     $propertyMetadata->typeHint = $this->getCommentTypeHint(is_string($property->getDocComment()) ? $property->getDocComment() : '');
     // Store property metadata to class metadata
     return $classMetadata->propertiesMetadata[$propertyMetadata->name] = $propertyMetadata;
 }
コード例 #26
0
ファイル: Abstract.php プロジェクト: Maikel-Koek/magento
 /**
  * Offset to set
  * @link http://php.net/manual/en/arrayaccess.offsetset.php
  * @param mixed $offset
  * The offset to assign the value to.
  * @param mixed $value
  * The value to set.
  * @return void
  */
 public function offsetSet($offset, $value)
 {
     if (property_exists(get_class($this), $offset)) {
         $property = new ReflectionProperty(get_class($this), $offset);
         if ($property->isPublic()) {
             $this->{$offset} = $value;
         }
         return;
     }
     $this->{$offset} = $value;
 }
コード例 #27
0
 /**
  * {@inheritdoc}
  */
 public function getValue($object, $propertyPath)
 {
     if ($this->isReadable($object, $propertyPath)) {
         $property = new \ReflectionProperty(get_class($object), $propertyPath);
         if (!$property->isPublic()) {
             $property->setAccessible(true);
         }
         return $property->getValue($object);
     }
     return;
 }
コード例 #28
0
ファイル: idea.php プロジェクト: ryunhe/everidea
 public function attris()
 {
     $attris = array();
     foreach ($this as $field => $value) {
         $property = new ReflectionProperty($this, $field);
         if ($property->isPublic()) {
             $attris[$field] = $value instanceof Types\Set ? $value->members() : $value;
         }
     }
     return $this->_data + $attris;
 }
コード例 #29
0
ファイル: Base.php プロジェクト: moiseh/codegen
 public function __construct($properties = array())
 {
     // define attributes
     foreach ($properties as $key => $val) {
         $attr = new \ReflectionProperty($this, $key);
         if ($attr->isPublic()) {
             $this->{$key} = $val;
         } else {
             throw new \Exception(t('The attribute "' . $key . '" is not public'));
         }
     }
 }
コード例 #30
0
ファイル: xoopseditorTest.php プロジェクト: RanLee/XoopsCore
 public function test___construct()
 {
     $class = $this->myclass;
     $instance = new $class();
     $this->assertInstanceOf($class, $instance);
     $this->assertInstanceOf('Xoops\\Form\\TextArea', $instance);
     $items = array('isEnabled', 'configs', 'rootPath');
     foreach ($items as $item) {
         $reflection = new ReflectionProperty($this->myclass, $item);
         $this->assertTrue($reflection->isPublic());
     }
 }