godruoyi commented on code in PR #2782:
URL: 
https://github.com/apache/incubator-opendal/pull/2782#discussion_r1284980699


##########
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:
   > By default, all methods are renamed in PHP to the camel-case variant of 
the Rust method name
   
   use `#[php_impl(rename_methods = "none")]` to disable rename now.



-- 
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]

Reply via email to