Skip to content

Commit

Permalink
build: Add PHP binding (#1860)
Browse files Browse the repository at this point in the history
* Update README.md

* Create php.md

* Create .gitignore

* Add files via upload

* Update composer.json

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update composer.json

* Update Compiler.php

* Update prql-php/.gitignore

Co-authored-by: Maximilian Roos <5635139+max-sixty@users.noreply.github.com>

* Add composer lock file

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Create test-php.yaml

* Update test-php.yaml

* Update test-php.yaml

* Update composer.json

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update composer.json

* Update test-php.yaml

* Update test-php.yaml

* Update test-php.yaml

* Update test-php.yaml

* Update test-php.yaml

* Uncomment unit tests

* Pass test dir as args

* Bootstrap the autoloader

* Build library and copy library file

* Update test-php.yaml

* Update test-php.yaml

* Update test-php.yaml

* Update test-php.yaml

* Update test-php.yaml

* Update test-php.yaml

* Update test-php.yaml

* Add more unit tests

* Update CompilerTest.php

* Update test-php.yaml

* Update CompilerTest.php

* Update test-php.yaml

* Add test-php

* Add concurrency thing

Co-authored-by: Maximilian Roos <5635139+max-sixty@users.noreply.github.com>

* Remove php-actions/phpunit

* Update .github/workflows/test-php.yaml

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Maximilian Roos <5635139+max-sixty@users.noreply.github.com>
Co-authored-by: Maximilian Roos <m@maxroos.com>
  • Loading branch information
4 people authored Feb 20, 2023
1 parent cab50cc commit 4a8b915
Show file tree
Hide file tree
Showing 11 changed files with 1,846 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/test-all.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ jobs:
os: ${{ matrix.os }}
target_option: ${{ matrix.target_option }}

test-php:
uses: ./.github/workflows/test-php.yaml

test-python:
uses: ./.github/workflows/test-python.yaml

Expand Down
42 changes: 42 additions & 0 deletions .github/workflows/test-php.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: test-php

on:
pull_request:
paths:
- "prql-php/**"
- ".github/workflows/test-php.yaml"
workflow_call:

concurrency:
# See notes in `pull-request.yaml`
group: ${{ github.workflow }}-${{ github.ref }}-php
cancel-in-progress: true

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
steps:
- name: 📂 Checkout code
uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
- run: cargo build
working-directory: prql-lib
- run: |
mv ../target/debug/libprql_lib.so ../prql-php/src/libprql_lib.so
ls -l ../target/debug/
uname -a
ls -lR ../prql-php/
working-directory: prql-lib
- name: 📦 Install dependencies using Composer
uses: php-actions/composer@v6
with:
args: --working-dir=prql-php
php_extensions: FFI
- name: 🧪 Run tests using PHPUnit
run: vendor/bin/phpunit tests
working-directory: prql-php
1 change: 1 addition & 0 deletions book/src/bindings/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ PRQL has bindings for many languages. These include:

- [Java](./java.md)
- [JavaScript](./javascript.md)
- [PHP](./php.md)
- [Python](./python.md)
- [R](./r.md)
- [Rust](./rust.md)
Expand Down
1 change: 1 addition & 0 deletions book/src/bindings/php.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{#include ../../../prql-php/README.md}}
1 change: 1 addition & 0 deletions prql-php/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/vendor
25 changes: 25 additions & 0 deletions prql-php/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# prql-php

`prql-php` offers PHP bindings through FFI.

It provides the `Compiler` class which contains the `toJson` and `toSql`
methods.

It's still at an early stage, and isn't published to Composer. Contributions are
welcome.

## Installation

The [PHP FFI extension](https://www.php.net/manual/en/book.ffi.php) needs to be
enabled. Set `ffi.enable` in your php.ini configuration file to `"true"`.

## Usage

```php
<?php

use Prql\Compiler\Compiler;

$prql = new Compiler();
$result = $prql->toSql("from employees");
```
37 changes: 37 additions & 0 deletions prql-php/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "prql/compiler",
"description": "PRQL compiler bindings.",
"keywords": [
"prql",
"sql"
],
"homepage": "https://prql-lang.org/",
"type": "library",
"license": "Apache-2.0",
"autoload": {
"psr-4": {
"Prql\\Compiler\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Prql\\Tests\\": "tests/"
}
},
"authors": [
{
"name": "Jonathan"
}
],
"support": {
"issues": "https://github.com/PRQL/prql/issues",
"source": "https://github.com/PRQL/prql",
"docs": "https://prql-lang.org/book/"
},
"require": {
"ext-ffi": "*"
},
"require-dev": {
"phpunit/phpunit": "^10"
}
}
Loading

0 comments on commit 4a8b915

Please sign in to comment.