Skip to content

Commit

Permalink
Fix #183 bug: file_put_contents throws a cast exception.
Browse files Browse the repository at this point in the history
  • Loading branch information
dim-s committed Apr 19, 2015
1 parent 6deea8f commit 9177e1b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 19 deletions.
17 changes: 2 additions & 15 deletions jphp-runtime/src/php/runtime/ext/core/classes/stream/Stream.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import php.runtime.common.Messages;
import php.runtime.common.Modifier;
import php.runtime.env.Environment;
import php.runtime.env.TraceInfo;
import php.runtime.lang.BaseObject;
import php.runtime.lang.Resource;
import php.runtime.memory.BinaryMemory;
Expand Down Expand Up @@ -109,20 +108,8 @@ public void setMode(String mode) {
@Signature
abstract public Memory close(Environment env, Memory... args) throws IOException;

public static Stream create(Environment env, TraceInfo trace, String path, String mode) throws Throwable {
String protocol = "file";
int pos = path.indexOf("://");
if (pos > -1) {
protocol = path.substring(0, pos);
path = path.substring(pos + 3);
}

ClassEntity classEntity = env.getUserValue(Stream.class.getName() + "#" + protocol, ClassEntity.class);
if (classEntity == null){
return null;
}

return (Stream)classEntity.newObject(env, trace, true, new StringMemory(path), new StringMemory(mode));
public static Stream create(Environment env, String path, String mode) throws Throwable {
return of(env, StringMemory.valueOf(path), StringMemory.valueOf(mode)).toObject(Stream.class);
}

@Signature({@Arg("path"), @Arg(value = "mode", optional = @Optional("r"))})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static boolean chown(String fileName, String owner){
}

public static boolean copy(Environment env, TraceInfo trace, String source, String dest) throws Throwable {
Stream stream = Stream.create(env, trace, source, "r");
Stream stream = Stream.create(env, source, "r");
if (stream == null) {
env.warning("copy(): Invalid source path");
return false;
Expand Down Expand Up @@ -136,7 +136,7 @@ public static Memory file(Environment env, TraceInfo trace, String path) throws
public static Memory file(Environment env, TraceInfo trace, String path, int flags, Memory context) throws Throwable {
Stream stream = null;
try {
stream = Stream.create(env, trace, path, "r");
stream = Stream.create(env, path, "r");
if (stream == null){
env.warning(trace, "file(): failed to open stream");
return Memory.FALSE;
Expand Down Expand Up @@ -188,7 +188,7 @@ public static Memory file_get_contents(Environment env, TraceInfo trace, String
Memory context, Memory offset, Memory maxLength) throws Throwable {
Stream stream = null;
try {
stream = Stream.create(env, trace, path, "r");
stream = Stream.create(env, path, "r");
if (stream == null){
env.warning(trace, "file_get_contents(): failed to open stream");
return Memory.FALSE;
Expand Down Expand Up @@ -243,7 +243,7 @@ public static Memory file_put_contents(Environment env, TraceInfo trace, String
if ((flags & FileConstants.FILE_APPEND) == FileConstants.FILE_APPEND)
mode = "a";

stream = Stream.create(env, trace, path, mode);
stream = Stream.create(env, path, mode);
if (stream == null){
env.warning(trace, "file_put_contents(): failed to open stream");
return Memory.FALSE;
Expand Down

0 comments on commit 9177e1b

Please sign in to comment.