Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Tests

on:
push:
branches:
- main
pull_request:

jobs:
tests:
name: Playground against the Appwrite API stub
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
# appwrite/appwrite 32.x requires PHP 8.5.
php-version: '8.5'
extensions: curl, json
tools: composer:v2

- name: Install dependencies
run: composer install --no-interaction --no-progress --prefer-dist

- name: Lint
run: find . -path ./vendor -prune -o -name '*.php' -print0 | xargs -0 -n1 php -l

- name: Test
run: composer test
23 changes: 12 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
FROM composer AS composer
FROM php:8.5-cli

COPY composer.json composer.json
COPY composer.lock composer.lock
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer

RUN composer install --no-dev --no-interaction --no-progress --no-scripts --optimize-autoloader
RUN apt-get update \
&& apt-get install -y --no-install-recommends unzip \
&& rm -rf /var/lib/apt/lists/*

FROM php:8.1.11-alpine3.16
WORKDIR /app

COPY --from=composer /app/vendor /app/vendor
COPY global.inc.php /app/global.inc.php
COPY playground.php /app/playground.php
COPY test.txt /app/test.txt
COPY composer.json ./
RUN composer install --no-dev --no-interaction --no-progress --no-scripts --optimize-autoloader

WORKDIR /app
CMD php playground.php
COPY global.inc.php playground.php test.txt ./
COPY resources ./resources

CMD ["php", "playground.php"]
29 changes: 23 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,44 @@ Appwrite playground is a simple way to explore the Appwrite API & Appwrite PHP S
This playground doesn't include any PHP best practices but rather intended to show some of the most simple examples and use cases of using the Appwrite API in your PHP application and server.

## System Requirements
* A system with PHP installed.
* PHP 8.5 or newer, with the `curl` and `json` extensions. The Appwrite PHP SDK
(`appwrite/appwrite` 32.x) requires PHP 8.5.
* You have readily available Appwrite running instance (localhost in most cases).
* Create a project in Appwrite instance using console.
* Generate a secret key in the Appwrite instance using console.

### Installation
1. Clone this repository.
2. cd into to repository.
3. Copy the project_id, endpoint, and secret key from your Appwrite Console into the global.inc.php file.
3. Copy the project_id, endpoint, and secret key from your Appwrite Console into the global.inc.php file, or pass them through the `APPWRITE_ENDPOINT`, `APPWRITE_PROJECT_ID` and `APPWRITE_API_KEY` environment variables.
4. Install dependencies using composer (`composer install`).
5. Execute the command `php playground.php`
6. You will see the JSON response in the console.

### API Covered in Playground.
* Create Collection
* List Collection
* Add Document
* List Documents
* Create Database
* Create Table
* List Tables
* Add Row
* List Rows
* Upload File
* List Files
* Create User
* List User
* Create Function
* Create Deployment
* Create Execution

Databases now hold tables of rows. The older collections and documents API is
deprecated since Appwrite 1.8, so the playground uses the `TablesDB` service.

### Tests
`composer test` drives every example against a stub of the Appwrite API, so it
needs no running instance:

```
composer test
```

## Contributing

Expand Down
11 changes: 9 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,21 @@
}
],
"require": {
"php": ">=8.0",
"php": ">=8.5",
"ext-curl": "*",
"appwrite/appwrite": "^12.0.0"
"ext-json": "*",
"appwrite/appwrite": "^32.2.0"
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist"
},
"scripts": {
"test": [
"@php tests/smoke.php",
"@php tests/playground-run.php"
]
},
"support": {
"email": "team@appwrite.io",
"issues": "https://github.com/appwrite/playground-for-php/issues",
Expand Down
14 changes: 9 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
version: '3.9'

services:
playground-for-php:
build: .
# Mount the files worth editing rather than the whole directory, so the
# dependencies installed into the image stay in place.
volumes:
- "./:/app"
working_dir: /app
command: "php playground.php"
- "./playground.php:/app/playground.php"
- "./global.inc.php:/app/global.inc.php"
environment:
- APPWRITE_ENDPOINT
- APPWRITE_PROJECT_ID
- APPWRITE_API_KEY
command: "php playground.php"
10 changes: 7 additions & 3 deletions global.inc.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
<?php
require_once __DIR__ . '/vendor/autoload.php';

// Every constant can also be provided through the environment, which keeps the
// credentials out of the working tree and lets the playground be pointed at
// another instance without editing this file.

if (!\defined('ENDPOINT')) {
\define('ENDPOINT', 'https://localhost/v1');
\define('ENDPOINT', \getenv('APPWRITE_ENDPOINT') ?: 'https://localhost/v1');
}

if (!\defined('PROJECT_ID')) {
\define('PROJECT_ID', '<Your Project ID />');
\define('PROJECT_ID', \getenv('APPWRITE_PROJECT_ID') ?: '<Your Project ID />');
}

if (!\defined('API_KEY')) {
\define('API_KEY', '<Your Project Secret Api key />');
\define('API_KEY', \getenv('APPWRITE_API_KEY') ?: '<Your Project Secret Api key />');
}

// Helper functions
Expand Down
Loading
Loading