Search in sources :

Example 6 with PropertyEntity

use of php.runtime.reflection.PropertyEntity in project jphp by jphp-compiler.

the class ReflectionClass method getStaticPropertyValue.

@Signature(@Arg("name"))
public Memory getStaticPropertyValue(Environment env, Memory... args) {
    String name = args[0].toString();
    PropertyEntity e = entity.findStaticProperty(name);
    if (e == null) {
        exception(env, Messages.ERR_UNDEFINED_PROPERTY.fetch(entity.getName(), name));
        return Memory.NULL;
    }
    if (!e.isDefault())
        return Memory.FALSE;
    return e.getDefaultValue(env).toImmutable();
}
Also used : PropertyEntity(php.runtime.reflection.PropertyEntity)

Example 7 with PropertyEntity

use of php.runtime.reflection.PropertyEntity in project jphp by jphp-compiler.

the class PropertyDumper method load.

@Override
public PropertyEntity load(InputStream input) throws IOException {
    PropertyEntity property = new PropertyEntity(context);
    DumpInputStream data = new DumpInputStream(input);
    String docComment = data.readUTF();
    if (!docComment.isEmpty()) {
        property.setDocComment(new DocumentComment(docComment));
    }
    property.setStatic(data.readBoolean());
    property.setModifier(data.readModifier());
    property.setName(data.readName());
    property.setTrace(data.readTrace(context));
    // typed
    property.setNullable(data.readBoolean());
    property.setType(data.readHintType());
    String typeClass = data.readName();
    if (typeClass != null && !typeClass.isEmpty()) {
        property.setTypeClass(typeClass);
    }
    property.setDefault(data.readBoolean());
    property.setDefaultValue(data.readMemory());
    byte[] raw = data.readRawData();
    return property;
}
Also used : DumpInputStream(php.runtime.loader.dump.io.DumpInputStream) DocumentComment(php.runtime.reflection.DocumentComment) PropertyEntity(php.runtime.reflection.PropertyEntity)

Example 8 with PropertyEntity

use of php.runtime.reflection.PropertyEntity in project jphp by jphp-compiler.

the class ReflectionClass method getProperty.

@Signature(@Arg("name"))
public Memory getProperty(Environment env, Memory... args) {
    String name = args[0].toString();
    PropertyEntity e = entity.findProperty(name);
    if (e == null)
        e = entity.findStaticProperty(name);
    if (e == null)
        return Memory.NULL;
    ClassEntity classEntity = env.fetchClass("ReflectionProperty");
    ReflectionProperty prop = new ReflectionProperty(env, classEntity);
    prop.setEntity(e);
    return new ObjectMemory(prop);
}
Also used : ClassEntity(php.runtime.reflection.ClassEntity) PropertyEntity(php.runtime.reflection.PropertyEntity) ObjectMemory(php.runtime.memory.ObjectMemory)

Example 9 with PropertyEntity

use of php.runtime.reflection.PropertyEntity in project jphp by jphp-compiler.

the class ReflectionClass method getProperties.

@Signature(@Arg(value = "filter", optional = @Optional("NULL")))
public Memory getProperties(Environment env, Memory... args) {
    int mod = args[0].isNull() ? -1 : args[0].toInteger();
    ArrayMemory result = new ArrayMemory();
    ClassEntity classEntity = env.fetchClass("ReflectionProperty");
    if (mod == -1 || (mod & ReflectionProperty.IS_STATIC) == ReflectionProperty.IS_STATIC) {
        for (PropertyEntity e : entity.getStaticProperties()) {
            ReflectionProperty prop = new ReflectionProperty(env, classEntity);
            prop.setEntity(e);
            result.add(new ObjectMemory(prop));
        }
    }
    for (PropertyEntity e : entity.getProperties()) {
        if (checkModifiers(e, mod)) {
            ReflectionProperty prop = new ReflectionProperty(env, classEntity);
            prop.setEntity(e);
            result.add(new ObjectMemory(prop));
        }
    }
    return result.toConstant();
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) ClassEntity(php.runtime.reflection.ClassEntity) PropertyEntity(php.runtime.reflection.PropertyEntity) ObjectMemory(php.runtime.memory.ObjectMemory)

Example 10 with PropertyEntity

use of php.runtime.reflection.PropertyEntity in project jphp by jphp-compiler.

the class ReflectionClass method getStaticProperties.

@Signature
public Memory getStaticProperties(Environment env, Memory... args) {
    ArrayMemory result = new ArrayMemory();
    ClassEntity classEntity = env.fetchClass("ReflectionProperty");
    for (PropertyEntity e : entity.getStaticProperties()) {
        ReflectionProperty prop = new ReflectionProperty(env, classEntity);
        prop.setEntity(e);
        result.add(new ObjectMemory(prop));
    }
    return result.toConstant();
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) ClassEntity(php.runtime.reflection.ClassEntity) PropertyEntity(php.runtime.reflection.PropertyEntity) ObjectMemory(php.runtime.memory.ObjectMemory)

Aggregations

PropertyEntity (php.runtime.reflection.PropertyEntity)13 ClassEntity (php.runtime.reflection.ClassEntity)10 Memory (php.runtime.Memory)6 ObjectMemory (php.runtime.memory.ObjectMemory)4 ForeachIterator (php.runtime.lang.ForeachIterator)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 Test (org.junit.Test)2 Modifier (php.runtime.common.Modifier)2 ICloneableObject (php.runtime.lang.support.ICloneableObject)2 IComparableObject (php.runtime.lang.support.IComparableObject)2 ArrayMemory (php.runtime.memory.ArrayMemory)2 LinkedHashSet (java.util.LinkedHashSet)1 IObject (php.runtime.lang.IObject)1 Serializable (php.runtime.lang.spl.Serializable)1 Traversable (php.runtime.lang.spl.Traversable)1 Iterator (php.runtime.lang.spl.iterator.Iterator)1 IteratorAggregate (php.runtime.lang.spl.iterator.IteratorAggregate)1 DumpInputStream (php.runtime.loader.dump.io.DumpInputStream)1 LongMemory (php.runtime.memory.LongMemory)1