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();
}
}
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;
}
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;
}
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;
}
}
}
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;
}
Aggregations