def construct(interp, this, w_class, property_name): space = interp.space if space.is_str(w_class): class_name = space.str_w(w_class) klass = interp.lookup_class_or_intf(class_name) if klass is None: msg = "Class %s does not exist" % class_name raise PHPException(k_ReflectionException.call_args( interp, [space.wrap(msg)])) elif isinstance(w_class, W_InstanceObject): klass = w_class.klass class_name = klass.name else: msg = ("The parameter class is expected to be either a string " "or an object") raise PHPException(k_ReflectionException.call_args( interp, [space.wrap(msg)])) this.class_name = class_name this.name = property_name this.ref_klass = klass this.flags = 0 try: this.ref_prop = klass.properties[property_name] if this.ref_prop.is_static(): this.flags |= IS_STATIC if this.ref_prop.is_public(): this.flags |= IS_PUBLIC elif this.ref_prop.is_private(): this.flags |= IS_PRIVATE elif this.ref_prop.is_protected(): this.flags |= IS_PROTECTED except KeyError: if (isinstance(w_class, W_InstanceObject) and w_class.map.lookup(property_name) is not None): this.ref_prop = None this.flags = consts.ACC_IMPLICIT_PUBLIC return msg = "Property %s::$%s does not exist" % (class_name, property_name) raise PHPException(k_ReflectionException.call_args( interp, [interp.space.wrap(msg)]))
def get_value(interp, this, w_obj=None): property = this.ref_prop if property is None: return w_obj.getattr(interp, this.name, w_obj.getclass(), give_notice=False) if not property.is_public(): msg = "Cannot access non-public member %s::%s" % (this.class_name, this.name) raise PHPException(k_ReflectionException.call_args( interp, [interp.space.wrap(msg)])) if not property.is_static(): w_value = w_obj.getattr(interp, this.name, w_obj.getclass(), give_notice=False) else: w_value = property.getvalue(interp.space).deref() return w_value
def set_value(interp, this, w_arg_1, w_arg_2=None): if not this.ref_prop.is_public(): msg = "Cannot access non-public member %s::%s" % (this.class_name, this.name) raise PHPException(k_ReflectionException.call_args( interp, [interp.space.wrap(msg)])) if not this.ref_prop.is_static(): w_obj = w_arg_1 w_value = w_arg_2 w_obj.setattr(interp, this.name, w_value, None) else: if w_arg_2 is None: w_value = w_arg_1 else: w_value = w_arg_2 this.ref_prop.r_value.store(w_value)