public static function set(&$subject, $propertyName, $propertyValue) { if (is_array($subject)) { $subject[$propertyName] = $propertyValue; return true; } if (!is_object($subject)) { throw new \Exception('subject must be an object or array, ' . gettype($subject) . ' given.', 1237301368); } if (!is_string($propertyName) && !is_integer($propertyName)) { throw new \Exception('Given property name/index is not of type string or integer.', 1231178878); } if ($forceDirectAccess === true) { $className = TypeHandling::getTypeForValue($subject); if (property_exists($className, $propertyName)) { $propertyReflection = new PropertyReflection($className, $propertyName); $propertyReflection->setValue($subject, $propertyValue); } else { $subject->{$propertyName} = $propertyValue; } } elseif (is_callable([$subject, $setterMethodName = self::buildSetterMethodName($propertyName)])) { $subject->{$setterMethodName}($propertyValue); } elseif ($subject instanceof \ArrayAccess) { $subject[$propertyName] = $propertyValue; } elseif (array_key_exists($propertyName, get_object_vars($subject))) { $subject->{$propertyName} = $propertyValue; } else { return false; } return true; }
/** * Returns the property of the reflected class and all of its parents * (This last point is the main difference with the PHP reflection). * Filter is the same as \ReflectionProperty of PHP reflection: * You can use these constants or use AttributeReflection constants. * * @param int $filter * @return PropertyReflection[] */ public function getReflectionProperties($filter = AttributeReflection::NO_FILTER) { $result = array(); foreach ($this->extractProperties($this->getReflector(), $filter) as $key => $reflectedProperty) { $result[$key] = PropertyReflection::instantiate($reflectedProperty); } return $result; }
function getProperty($name) { return PropertyReflection::import(parent::getProperty($name)); }