This is an automated email from the ASF dual-hosted git repository.
xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git
The following commit(s) were added to refs/heads/main by this push:
new 4958c845e feat: setup the integrate with PHP binding (#2726)
4958c845e is described below
commit 4958c845e4875f03c12da91453a3d4eab1cce9e3
Author: Lianbo <[email protected]>
AuthorDate: Wed Aug 2 23:31:54 2023 +0800
feat: setup the integrate with PHP binding (#2726)
* Add PHP bindings for OpenDAL library
A new subdirectory `bindings/php` has been created in order to have PHP
bindings for the OpenDAL library. This includes new PHP tests, stdlib stubs for
the PHP interface, and addition of composer configuration for dependency
management. as well as the initial source code written in Rust to provide PHP
bindings. The 'debug' function is used as a test to check the binding. The
README has been added to guide users and developers in building and testing the
PHP bindings.
* Format License
---
bindings/php/.cargo/config.toml | 25 +++++++++++++++++++++++++
bindings/php/.gitignore | 3 +++
bindings/php/Cargo.toml | 35 +++++++++++++++++++++++++++++++++++
bindings/php/README.md | 32 ++++++++++++++++++++++++++++++++
bindings/php/composer.json | 21 +++++++++++++++++++++
bindings/php/opendal-php.stubs.php | 25 +++++++++++++++++++++++++
bindings/php/phpunit.xml | 32 ++++++++++++++++++++++++++++++++
bindings/php/src/lib.rs | 31 +++++++++++++++++++++++++++++++
bindings/php/tests/Unit/BasicTest.php | 27 +++++++++++++++++++++++++++
9 files changed, 231 insertions(+)
diff --git a/bindings/php/.cargo/config.toml b/bindings/php/.cargo/config.toml
new file mode 100644
index 000000000..31296cd0c
--- /dev/null
+++ b/bindings/php/.cargo/config.toml
@@ -0,0 +1,25 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+[target.'cfg(not(target_os = "windows"))']
+rustflags = ["-C", "link-arg=-Wl,-undefined,dynamic_lookup"]
+
+[target.x86_64-pc-windows-msvc]
+linker = "rust-lld"
+
+[target.i686-pc-windows-msvc]
+linker = "rust-lld"
diff --git a/bindings/php/.gitignore b/bindings/php/.gitignore
new file mode 100644
index 000000000..612c60167
--- /dev/null
+++ b/bindings/php/.gitignore
@@ -0,0 +1,3 @@
+/vendor
+composer.lock
+.phpunit.result.cache
diff --git a/bindings/php/Cargo.toml b/bindings/php/Cargo.toml
new file mode 100644
index 000000000..ec9f0a2d3
--- /dev/null
+++ b/bindings/php/Cargo.toml
@@ -0,0 +1,35 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+[package]
+name = "opendal-php"
+version = "0.1.0"
+
+edition.workspace = true
+homepage.workspace = true
+license.workspace = true
+repository.workspace = true
+rust-version.workspace = true
+
+# See more keys and their definitions at
https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[lib]
+crate-type = ["cdylib"]
+
+[dependencies]
+ext-php-rs = "0.10.1"
+opendal = {version = "0.38.1", path = "../../core" }
diff --git a/bindings/php/README.md b/bindings/php/README.md
new file mode 100644
index 000000000..1c04c8629
--- /dev/null
+++ b/bindings/php/README.md
@@ -0,0 +1,32 @@
+# OpenDAL PHP Binding (WIP)
+
+## Requirements
+
+* PHP 8.1+
+
+## Development
+
+### Install Cargo PHP
+
+we use
[cargo-php](https://davidcole1340.github.io/ext-php-rs/getting-started/hello_world.html)
to build the PHP extension.
+
+```bash
+cargo install cargo-php
+```
+
+### Build
+
+Move to the `bindings/php` directory and run the following command, the
extension will be built in `target/debug` directory and enable the extension in
`php.ini` file.
+
+```bash
+cargo build
+cargo php install
+```
+
+### Test
+
+```bash
+composer install
+composer test
+```
+
diff --git a/bindings/php/composer.json b/bindings/php/composer.json
new file mode 100644
index 000000000..1f8157703
--- /dev/null
+++ b/bindings/php/composer.json
@@ -0,0 +1,21 @@
+{
+ "authors": [
+ {
+ "name": "OpenDAL Contributors",
+ "email": "[email protected]"
+ }
+ ],
+ "require-dev": {
+ "php": ">=8.1",
+ "pestphp/pest": "^2.9"
+ },
+ "license": "Apache-2.0",
+ "scripts": {
+ "test": "vendor/bin/pest"
+ },
+ "config": {
+ "allow-plugins": {
+ "pestphp/pest-plugin": false
+ }
+ }
+}
diff --git a/bindings/php/opendal-php.stubs.php
b/bindings/php/opendal-php.stubs.php
new file mode 100644
index 000000000..c8e44df26
--- /dev/null
+++ b/bindings/php/opendal-php.stubs.php
@@ -0,0 +1,25 @@
+<?php
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+// Stubs for opendal-php
+
+namespace {
+ function debug(): string {}
+}
diff --git a/bindings/php/phpunit.xml b/bindings/php/phpunit.xml
new file mode 100644
index 000000000..a8612bd43
--- /dev/null
+++ b/bindings/php/phpunit.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+-->
+<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
+ bootstrap="vendor/autoload.php"
+ colors="true"
+>
+ <testsuites>
+ <testsuite name="Test Suite">
+ <directory suffix="Test.php">./tests</directory>
+ </testsuite>
+ </testsuites>
+</phpunit>
diff --git a/bindings/php/src/lib.rs b/bindings/php/src/lib.rs
new file mode 100644
index 000000000..288faeb33
--- /dev/null
+++ b/bindings/php/src/lib.rs
@@ -0,0 +1,31 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use ext_php_rs::prelude::*;
+use opendal::{EntryMode, Metadata};
+
+#[php_function]
+pub fn debug() -> String {
+ let metadata = Metadata::new(EntryMode::FILE);
+
+ format!("{:?}", metadata)
+}
+
+#[php_module]
+pub fn get_module(module: ModuleBuilder) -> ModuleBuilder {
+ module
+}
diff --git a/bindings/php/tests/Unit/BasicTest.php
b/bindings/php/tests/Unit/BasicTest.php
new file mode 100644
index 000000000..503f1c972
--- /dev/null
+++ b/bindings/php/tests/Unit/BasicTest.php
@@ -0,0 +1,27 @@
+<?php
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+it('opendal-php extension loaded', function () {
+ expect(extension_loaded('opendal-php'))->toBeTrue();
+});
+
+it('debug function works', function () {
+ expect(debug())->toStartWith('Metadata');
+});