forked from jphp-group/jphp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
jphp-httpserver-ext: Add support for http parts
This commit adds a wrapper around javax.servlet.http.Part, which makes it easy to work with files transmitted via POST
Showing
8 changed files
with
113 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...php-httpserver-ext/src/main/java/org/develnext/jphp/ext/httpserver/classes/PHttpPart.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package org.develnext.jphp.ext.httpserver.classes; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
import org.develnext.jphp.ext.httpserver.HttpServerExtension; | ||
import php.runtime.annotation.Reflection; | ||
import php.runtime.env.Environment; | ||
import php.runtime.ext.core.classes.stream.DataStream; | ||
import php.runtime.ext.core.classes.stream.MemoryStream; | ||
import php.runtime.ext.core.classes.stream.ResourceStream; | ||
import php.runtime.lang.BaseWrapper; | ||
import php.runtime.reflection.ClassEntity; | ||
|
||
import javax.servlet.http.Part; | ||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
|
||
@Reflection.Name("HttpPart") | ||
@Reflection.Namespace(HttpServerExtension.NS) | ||
public class PHttpPart extends BaseWrapper<Part> { | ||
public PHttpPart(Environment env, Part wrappedObject) { | ||
super(env, wrappedObject); | ||
} | ||
|
||
public PHttpPart(Environment env, ClassEntity clazz) { | ||
super(env, clazz); | ||
} | ||
|
||
@Reflection.Signature | ||
public byte[] readAll() throws IOException { | ||
ByteArrayInputStream inputStream = (ByteArrayInputStream) getWrappedObject().getInputStream(); | ||
return inputStream.readAllBytes(); | ||
} | ||
|
||
@Reflection.Signature | ||
public String getName() { | ||
return getWrappedObject().getName(); | ||
} | ||
|
||
@Reflection.Signature | ||
public String getContentType() { | ||
return getWrappedObject().getContentType(); | ||
} | ||
|
||
@Reflection.Signature | ||
public String getSubmittedFileName() { | ||
return getWrappedObject().getSubmittedFileName(); | ||
} | ||
|
||
@Reflection.Signature | ||
public long getSize() { | ||
return getWrappedObject().getSize(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
exts/jphp-httpserver-ext/src/main/resources/JPHP-INF/sdk/php/http/HttpPart.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace php\http; | ||
|
||
use php\io\Stream; | ||
|
||
class HttpPart | ||
{ | ||
/** | ||
* @return string | ||
*/ | ||
public function readAll(): string {} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getName(): string {} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getContentType(): string {} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getSubmittedFileName(): string {} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getSize(): int {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters