Search in sources :

Example 11 with ObjectMemory

use of php.runtime.memory.ObjectMemory in project jphp by jphp-compiler.

the class Environment method __throwCatch.

public Memory __throwCatch(BaseBaseException e, String className, String lowerClassName) {
    ClassEntity origin = e.getReflection();
    ClassEntity cause = fetchClass(className, lowerClassName, false);
    if (cause != null && origin.isInstanceOf(cause))
        return new ObjectMemory(e);
    if (origin.isInstanceOfLower(lowerClassName))
        return new ObjectMemory(e);
    else
        return Memory.NULL;
}
Also used : ObjectMemory(php.runtime.memory.ObjectMemory)

Example 12 with ObjectMemory

use of php.runtime.memory.ObjectMemory in project jphp by jphp-compiler.

the class LangFunctions method property_exists.

public static Memory property_exists(Environment env, Memory clazz, String property) throws Throwable {
    ClassEntity classEntity;
    IObject object = null;
    boolean isMagic = false;
    if (clazz.isObject()) {
        ObjectMemory tmp = clazz.toValue(ObjectMemory.class);
        classEntity = tmp.getReflection();
        object = tmp.value;
    } else {
        String name = clazz.toString();
        String nameL = name.toLowerCase();
        classEntity = env.fetchClass(name, nameL, true);
        if (classEntity == null) {
            classEntity = env.fetchMagicClass(name, nameL);
            isMagic = true;
        }
    }
    if (classEntity == null) {
        return Memory.FALSE;
    }
    if (object != null) {
        ArrayMemory props = object.getProperties();
        ClassEntity context = env.getLastClassOnStack();
        PropertyEntity entity = classEntity.isInstanceOf(context) ? context.properties.get(property) : classEntity.properties.get(property);
        int accessFlags = entity == null ? 0 : entity.canAccess(env);
        if (accessFlags != 0)
            return Memory.FALSE;
        return (props != null && props.getByScalar(entity == null ? property : entity.getSpecificName()) != null) ? Memory.TRUE : Memory.FALSE;
    } else {
        PropertyEntity entity = classEntity.properties.get(property);
        if (isMagic) {
            int accessFlags = entity == null ? 0 : entity.canAccess(env);
            if (accessFlags != 0)
                return Memory.FALSE;
        }
        return entity != null ? Memory.TRUE : Memory.FALSE;
    }
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) IObject(php.runtime.lang.IObject) ObjectMemory(php.runtime.memory.ObjectMemory)

Example 13 with ObjectMemory

use of php.runtime.memory.ObjectMemory in project jphp by jphp-compiler.

the class CallStackItem method toArray.

public ArrayMemory toArray(boolean provideObject, boolean ignoreArgs) {
    ArrayMemory el = new ArrayMemory();
    if (trace != null) {
        if (trace.getFile() != null)
            el.refOfIndex("file").assign(trace.getFileName());
        el.refOfIndex("line").assign(trace.getStartLine() + 1);
    }
    el.refOfIndex("function").assign(function);
    if (clazz != null) {
        el.refOfIndex("class").assign(clazz);
        el.refOfIndex("type").assign("::");
    }
    if (object != null) {
        if (provideObject) {
            el.refOfIndex("object").assign(new ObjectMemory(object));
        }
        el.refOfIndex("type").assign("->");
    }
    if (!ignoreArgs) {
        el.refOfIndex("args").assign(ArrayMemory.of(args));
    }
    if (trace != null)
        el.refOfIndex("position").assign(trace.getStartPosition() + 1);
    return el;
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) ObjectMemory(php.runtime.memory.ObjectMemory)

Example 14 with ObjectMemory

use of php.runtime.memory.ObjectMemory in project jphp by jphp-compiler.

the class FileObject method find.

@Signature(@Arg(value = "filter", optional = @Optional("NULL")))
public Memory find(final Environment env, Memory... args) {
    if (args[0].isNull()) {
        return ArrayMemory.ofStrings(file.list()).toConstant();
    } else {
        final Invoker invoker = Invoker.valueOf(env, null, args[0]);
        if (invoker == null) {
            exception(env, "Invalid filter value, must be callable");
            return Memory.NULL;
        }
        final TraceInfo trace = env.trace();
        invoker.setTrace(trace);
        String[] result = file.list(new FilenameFilter() {

            @Override
            public boolean accept(File dir, String name) {
                FileObject o = new FileObject(env, __class__, dir);
                Memory[] args = new Memory[] { new ObjectMemory(o), new StringMemory(name) };
                return invoker.callNoThrow(args).toBoolean();
            }
        });
        return ArrayMemory.ofStrings(result);
    }
}
Also used : Invoker(php.runtime.invoke.Invoker) ObjectMemory(php.runtime.memory.ObjectMemory) StringMemory(php.runtime.memory.StringMemory) TraceInfo(php.runtime.env.TraceInfo)

Example 15 with ObjectMemory

use of php.runtime.memory.ObjectMemory in project jphp by jphp-compiler.

the class Stream method of.

@Signature({ @Arg("path"), @Arg(value = "mode", optional = @Optional("r")) })
public static Memory of(Environment env, Memory... args) throws Throwable {
    String path = args[0].toString();
    String protocol = "file";
    int pos = path.indexOf("://");
    if (pos > -1) {
        protocol = path.substring(0, pos);
        path = path.substring(pos + 3);
    }
    String className = env.getUserValue(Stream.class.getName() + "#" + protocol, String.class);
    if (className == null) {
        throw new IOException("Unregistered protocol - " + protocol + "://");
    }
    ClassEntity classEntity = env.fetchClass(className);
    if (classEntity.getNativeClass().getAnnotation(UsePathWithProtocols.class) != null) {
        path = protocol + "://" + path;
    }
    return new ObjectMemory(classEntity.newObject(env, env.trace(), true, new StringMemory(path), args[1]));
}
Also used : ClassEntity(php.runtime.reflection.ClassEntity) ObjectMemory(php.runtime.memory.ObjectMemory) StringMemory(php.runtime.memory.StringMemory)

Aggregations

ObjectMemory (php.runtime.memory.ObjectMemory)55 ArrayMemory (php.runtime.memory.ArrayMemory)24 Memory (php.runtime.Memory)19 ClassEntity (php.runtime.reflection.ClassEntity)17 StringMemory (php.runtime.memory.StringMemory)14 IObject (php.runtime.lang.IObject)11 Invoker (php.runtime.invoke.Invoker)6 LongMemory (php.runtime.memory.LongMemory)6 Environment (php.runtime.env.Environment)5 MethodEntity (php.runtime.reflection.MethodEntity)5 Calendar (java.util.Calendar)4 Closure (php.runtime.lang.Closure)4 Locale (java.util.Locale)3 Test (org.junit.Test)3 WrapLocale (php.runtime.ext.core.classes.util.WrapLocale)3 PropertyEntity (php.runtime.reflection.PropertyEntity)3 AbstractFunctionEntity (php.runtime.reflection.support.AbstractFunctionEntity)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Date (java.util.Date)2 TimeZone (java.util.TimeZone)2