Search in sources :

Example 11 with StringMemory

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

the class OutputBuffer method doFlush.

protected void doFlush(boolean flush) throws Throwable {
    /*if (buffer.size() == 0)
            return;*/
    if (flush) {
        isFlushed = true;
        if (status != HANDLER_START && status != HANDLER_FLUSH)
            status = HANDLER_WRITE;
    } else {
        if (status == HANDLER_FINAL)
            status |= HANDLER_CLEAN;
        else
            status = HANDLER_CLEAN;
    }
    if (invoker != null) {
        invoker.setTrace(trace == null ? TraceInfo.UNKNOWN : trace);
        Memory[] args;
        if (!binaryInBuffer) {
            args = new Memory[] { new StringMemory(buffer.toString(environment.getDefaultCharset().name())), null };
        } else
            args = new Memory[] { new BinaryMemory(buffer.toByteArray()), null };
        args[1] = LongMemory.valueOf(status);
        invoker.setTrace(trace == null ? TraceInfo.UNKNOWN : trace);
        Memory result;
        incLock();
        try {
            result = invoker.call(args).toValue();
        } finally {
            decLock();
        }
        if (result != Memory.FALSE) {
            byte[] data = result instanceof BinaryMemory ? result.getBinaryBytes(environment.getDefaultCharset()) : result.toString().getBytes(environment.getDefaultCharset());
            if (flush) {
                if (output == null)
                    parentOutput.write(data);
                else
                    output.write(data);
                reset();
                status = HANDLER_FLUSH;
            }
            return;
        }
    }
    if (flush) {
        status |= HANDLER_FLUSH;
        if (output == null)
            parentOutput.write(buffer.toByteArray());
        else
            buffer.writeTo(output);
        reset();
    }
}
Also used : BinaryMemory(php.runtime.memory.BinaryMemory) Memory(php.runtime.Memory) BinaryMemory(php.runtime.memory.BinaryMemory) LongMemory(php.runtime.memory.LongMemory) StringMemory(php.runtime.memory.StringMemory) StringMemory(php.runtime.memory.StringMemory)

Example 12 with StringMemory

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

the class ClassEntity method issetProperty.

public Memory issetProperty(Environment env, TraceInfo trace, IObject object, String property, PropertyCallCache callCache, int cacheIndex) throws Throwable {
    PropertyEntity entity = callCache == null || env instanceof ConcurrentEnvironment ? null : callCache.get(env, cacheIndex);
    if (entity == null) {
        ClassEntity contex = env.getLastClassOnStack();
        entity = isInstanceOf(contex) ? contex.properties.get(property) : properties.get(property);
        if (entity != null && callCache != null) {
            callCache.put(env, cacheIndex, entity);
        }
    }
    int accessFlag = entity == null ? 0 : entity.canAccess(env);
    ArrayMemory props = object.getProperties();
    Memory tmp = props == null || accessFlag != 0 ? null : props.getByScalar(entity == null ? property : entity.specificName);
    if (tmp != null)
        return tmp.isNull() ? tmp : Memory.TRUE;
    if (methodMagicIsset != null) {
        Memory result;
        ClassEntity contex = env.getLastClassOnStack();
        if (contex != null && contex.getId() == methodMagicIsset.getClazz().getId())
            if (env.peekCall(0).flags == FLAG_ISSET) {
                return object.getProperties().getByScalar(property) != null ? Memory.TRUE : Memory.NULL;
            }
        try {
            Memory[] args = new Memory[] { new StringMemory(property) };
            env.pushCall(trace, object, args, methodMagicIsset.getName(), methodMagicIsset.getClazz().getName(), name);
            env.peekCall(0).flags = FLAG_ISSET;
            InvokeArgumentHelper.checkType(env, trace, methodMagicIsset, new StringMemory(property));
            result = methodMagicIsset.invokeDynamic(object, env, new StringMemory(property)).toBoolean() ? Memory.TRUE : Memory.NULL;
        } finally {
            env.popCall();
        }
        return result;
    }
    return Memory.NULL;
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) ConcurrentEnvironment(php.runtime.env.ConcurrentEnvironment) ArrayMemory(php.runtime.memory.ArrayMemory) Memory(php.runtime.Memory) ReferenceMemory(php.runtime.memory.ReferenceMemory) StringMemory(php.runtime.memory.StringMemory) StringMemory(php.runtime.memory.StringMemory)

Example 13 with StringMemory

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

the class ClassEntity method unsetProperty.

public Memory unsetProperty(Environment env, TraceInfo trace, IObject object, String property, PropertyCallCache callCache, int index) throws Throwable {
    ClassEntity context = env.getLastClassOnStack();
    PropertyEntity entity = isInstanceOf(context) ? context.properties.get(property) : properties.get(property);
    int accessFlag = entity == null ? 0 : entity.canAccess(env);
    if (entity == null) {
        PropertyEntity staticEntity = staticProperties.get(property);
        if (staticEntity != null) {
            invalidAccessToProperty(env, trace, staticEntity, staticEntity.canAccess(env));
        }
    }
    ArrayMemory props = object.getProperties();
    if (props == null || accessFlag != 0 || props.removeByScalar(entity == null ? property : entity.specificName) == null) {
        if (methodMagicUnset != null) {
            if (context != null && context.getId() == methodMagicUnset.getClazz().getId()) {
                if (env.peekCall(0).flags == FLAG_UNSET) {
                    return Memory.NULL;
                }
            }
            try {
                Memory[] args = new Memory[] { new StringMemory(property) };
                env.pushCall(trace, object, args, methodMagicUnset.getName(), methodMagicUnset.getClazz().getName(), name);
                env.peekCall(0).flags = FLAG_UNSET;
                InvokeArgumentHelper.checkType(env, trace, methodMagicUnset, args);
                methodMagicUnset.invokeDynamic(object, env, args);
            } finally {
                env.popCall();
            }
            return Memory.NULL;
        }
    }
    if (accessFlag != 0)
        invalidAccessToProperty(env, trace, entity, accessFlag);
    entity = staticProperties.get(property);
    if (entity != null) {
        env.error(trace, ErrorType.E_STRICT, Messages.ERR_ACCESSING_STATIC_PROPERTY_AS_NON_STATIC, entity.getClazz().getName(), entity.getName());
    }
    return Memory.NULL;
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) ArrayMemory(php.runtime.memory.ArrayMemory) Memory(php.runtime.Memory) ReferenceMemory(php.runtime.memory.ReferenceMemory) StringMemory(php.runtime.memory.StringMemory) StringMemory(php.runtime.memory.StringMemory)

Example 14 with StringMemory

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

the class Environment method autoloadCall.

public ClassEntity autoloadCall(String name, String lowerName) {
    synchronized (autoloadLocks) {
        // detect recursion in autoload
        if (StringUtils.isValidClassName(name) && autoloadLocks.add(lowerName)) {
            StringMemory tmp = new StringMemory(name);
            for (SplClassLoader loader : classLoaders) {
                loader.load(tmp);
                ClassEntity classEntity = fetchClass(name, false);
                if (classEntity != null) {
                    autoloadLocks.remove(lowerName);
                    return classEntity;
                }
            }
            if (defaultAutoLoader != null) {
                defaultAutoLoader.load(tmp);
            }
            autoloadLocks.remove(lowerName);
            return fetchClass(name, false);
        } else {
            return null;
        }
    }
}
Also used : StringMemory(php.runtime.memory.StringMemory)

Example 15 with StringMemory

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

the class Environment method exception.

public void exception(TraceInfo trace, BaseError e, String message, Object... args) {
    __clearSilent();
    if (args == null || args.length == 0) {
        e.__construct(this, new StringMemory(message));
    } else {
        e.__construct(this, new StringMemory(String.format(message, args)));
    }
    e.setTraceInfo(this, trace);
    throw e;
}
Also used : StringMemory(php.runtime.memory.StringMemory)

Aggregations

StringMemory (php.runtime.memory.StringMemory)47 ArrayMemory (php.runtime.memory.ArrayMemory)14 Memory (php.runtime.Memory)11 ObjectMemory (php.runtime.memory.ObjectMemory)8 ReferenceMemory (php.runtime.memory.ReferenceMemory)7 BigDecimal (java.math.BigDecimal)5 Invoker (php.runtime.invoke.Invoker)4 ClassEntity (php.runtime.reflection.ClassEntity)4 TraceInfo (php.runtime.env.TraceInfo)3 IObject (php.runtime.lang.IObject)3 LongMemory (php.runtime.memory.LongMemory)3 StringWriter (java.io.StringWriter)2 ComponentProperties (org.develnext.jphp.swing.ComponentProperties)2 UIReader (org.develnext.jphp.swing.loader.UIReader)2 Signature (php.runtime.annotation.Reflection.Signature)2 CallStackItem (php.runtime.env.CallStackItem)2 ConcurrentEnvironment (php.runtime.env.ConcurrentEnvironment)2 CriticalException (php.runtime.exceptions.CriticalException)2 MethodEntity (php.runtime.reflection.MethodEntity)2 BigInteger (java.math.BigInteger)1