Xuanwo commented on code in PR #2782:
URL:
https://github.com/apache/incubator-opendal/pull/2782#discussion_r1284567630
##########
bindings/php/src/lib.rs:
##########
@@ -15,14 +15,165 @@
// specific language governing permissions and limitations
// under the License.
+use std::collections::HashMap;
+use std::str::FromStr;
use ext_php_rs::prelude::*;
-use opendal::{EntryMode, Metadata};
+use ext_php_rs::{exception::PhpException, zend::ce};
+use ext_php_rs::convert::FromZval;
+use ext_php_rs::flags::DataType;
+use ext_php_rs::types::Zval;
+use ::opendal as od;
-#[php_function]
-pub fn debug() -> String {
- let metadata = Metadata::new(EntryMode::FILE);
+#[php_class(name = "OpenDAL\\Operator")]
Review Comment:
Does php has concept about async operations?
##########
bindings/php/src/lib.rs:
##########
@@ -15,14 +15,165 @@
// specific language governing permissions and limitations
// under the License.
+use std::collections::HashMap;
+use std::str::FromStr;
use ext_php_rs::prelude::*;
-use opendal::{EntryMode, Metadata};
+use ext_php_rs::{exception::PhpException, zend::ce};
+use ext_php_rs::convert::FromZval;
+use ext_php_rs::flags::DataType;
+use ext_php_rs::types::Zval;
+use ::opendal as od;
-#[php_function]
-pub fn debug() -> String {
- let metadata = Metadata::new(EntryMode::FILE);
+#[php_class(name = "OpenDAL\\Operator")]
+pub struct Operator(od::BlockingOperator);
- format!("{:?}", metadata)
+#[php_impl]
+impl Operator {
+ pub fn __construct(scheme_str: String, mp: HashMap<String, String>) ->
PhpResult<Self> {
Review Comment:
How about using API like: `__construct(scheme: String, config:
HashMap<String, String>)`
##########
bindings/php/src/lib.rs:
##########
@@ -15,14 +15,165 @@
// specific language governing permissions and limitations
// under the License.
+use std::collections::HashMap;
+use std::str::FromStr;
use ext_php_rs::prelude::*;
-use opendal::{EntryMode, Metadata};
+use ext_php_rs::{exception::PhpException, zend::ce};
+use ext_php_rs::convert::FromZval;
+use ext_php_rs::flags::DataType;
+use ext_php_rs::types::Zval;
+use ::opendal as od;
-#[php_function]
-pub fn debug() -> String {
- let metadata = Metadata::new(EntryMode::FILE);
+#[php_class(name = "OpenDAL\\Operator")]
+pub struct Operator(od::BlockingOperator);
- format!("{:?}", metadata)
+#[php_impl]
+impl Operator {
+ pub fn __construct(scheme_str: String, mp: HashMap<String, String>) ->
PhpResult<Self> {
+ let scheme =
od::Scheme::from_str(&scheme_str).map_err(format_php_err)?;
+ let op = od::Operator::via_map(scheme, mp).map_err(format_php_err)?;
+
+ Ok(Operator(op.blocking()))
+ }
+
+ /// Write bytes into given path.
+ pub fn write(&self, path: &str, content: String) -> PhpResult<()> {
Review Comment:
Does php has concept lile `Bytes` or `Vec<u8>`? It's incorrect to assume
that all content are `UTF-8` string.
##########
bindings/php/src/lib.rs:
##########
@@ -15,14 +15,165 @@
// specific language governing permissions and limitations
// under the License.
+use std::collections::HashMap;
+use std::str::FromStr;
use ext_php_rs::prelude::*;
-use opendal::{EntryMode, Metadata};
+use ext_php_rs::{exception::PhpException, zend::ce};
+use ext_php_rs::convert::FromZval;
+use ext_php_rs::flags::DataType;
+use ext_php_rs::types::Zval;
+use ::opendal as od;
-#[php_function]
-pub fn debug() -> String {
- let metadata = Metadata::new(EntryMode::FILE);
+#[php_class(name = "OpenDAL\\Operator")]
+pub struct Operator(od::BlockingOperator);
- format!("{:?}", metadata)
+#[php_impl]
+impl Operator {
+ pub fn __construct(scheme_str: String, mp: HashMap<String, String>) ->
PhpResult<Self> {
+ let scheme =
od::Scheme::from_str(&scheme_str).map_err(format_php_err)?;
+ let op = od::Operator::via_map(scheme, mp).map_err(format_php_err)?;
+
+ Ok(Operator(op.blocking()))
+ }
+
+ /// Write bytes into given path.
+ pub fn write(&self, path: &str, content: String) -> PhpResult<()> {
+ self.0.write(path, content).map_err(format_php_err)
+ }
+
+ /// Read the whole path into bytes.
+ pub fn read(&self, path: &str) -> PhpResult<String> {
Review Comment:
The same.
##########
bindings/php/src/lib.rs:
##########
@@ -15,14 +15,165 @@
// specific language governing permissions and limitations
// under the License.
+use std::collections::HashMap;
+use std::str::FromStr;
use ext_php_rs::prelude::*;
-use opendal::{EntryMode, Metadata};
+use ext_php_rs::{exception::PhpException, zend::ce};
+use ext_php_rs::convert::FromZval;
+use ext_php_rs::flags::DataType;
+use ext_php_rs::types::Zval;
+use ::opendal as od;
-#[php_function]
-pub fn debug() -> String {
- let metadata = Metadata::new(EntryMode::FILE);
+#[php_class(name = "OpenDAL\\Operator")]
+pub struct Operator(od::BlockingOperator);
- format!("{:?}", metadata)
+#[php_impl]
+impl Operator {
+ pub fn __construct(scheme_str: String, mp: HashMap<String, String>) ->
PhpResult<Self> {
+ let scheme =
od::Scheme::from_str(&scheme_str).map_err(format_php_err)?;
+ let op = od::Operator::via_map(scheme, mp).map_err(format_php_err)?;
+
+ Ok(Operator(op.blocking()))
+ }
+
+ /// Write bytes into given path.
+ pub fn write(&self, path: &str, content: String) -> PhpResult<()> {
+ self.0.write(path, content).map_err(format_php_err)
+ }
+
+ /// Read the whole path into bytes.
+ pub fn read(&self, path: &str) -> PhpResult<String> {
+ self.0
+ .read(path)
+ .map(|res| String::from_utf8(res).unwrap())
+ .map_err(format_php_err)
+ }
+
+ /// Check if this path exists or not.
+ pub fn exist(&self, path: &str) -> PhpResult<u8> {
Review Comment:
Does php has `bool`? And I prefer to call it `is_exist`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]