Skip to content

Commit 9e4dc1d

Browse files
Merge pull request #1 from sqlitecloud/polish-sdk-for-composer
Polish sdk for composer, github workflow and PHP code standard
2 parents 41fdd74 + 6027cb5 commit 9e4dc1d

46 files changed

Lines changed: 4536 additions & 2527 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.devcontainer/Dockerfile‎

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,36 @@
1-
FROM mcr.microsoft.com/devcontainers/php:7-bullseye
1+
FROM php:7.0-stretch
22

33
ADD https://dl.yarnpkg.com/debian/pubkey.gpg /etc/apt/trusted.gpg.d/yarn.asc
44

55
RUN chmod +r /etc/apt/trusted.gpg.d/*.asc && \
66
echo "deb http://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list
7+
8+
# Debian Stretch repository is archived, so we need to update the sources list
9+
RUN echo "deb http://archive.debian.org/debian stretch main" > /etc/apt/sources.list \
10+
&& echo "deb http://archive.debian.org/debian-security stretch/updates main" >> /etc/apt/sources.list
11+
12+
# Install xdebug latest version to support PHP 7.0
13+
RUN yes | pecl install xdebug-2.6.1 \
14+
&& echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini \
15+
# for xDebug 3.x
16+
# && echo "xdebug.mode = debug" >> /usr/local/etc/php/conf.d/xdebug.ini \
17+
# && echo "xdebug.start_with_request = yes" >> /usr/local/etc/php/conf.d/xdebug.ini \
18+
# && echo "xdebug.client_port = 9000" >> /usr/local/etc/php/conf.d/xdebug.ini \
19+
# for xDebug 2.x
20+
&& echo "xdebug.remote_enable = 1" >> /usr/local/etc/php/conf.d/xdebug.ini \
21+
&& echo "xdebug.remote_autostart = 1" >> /usr/local/etc/php/conf.d/xdebug.ini \
22+
&& echo "xdebug.remote_port = 9000" >> /usr/local/etc/php/conf.d/xdebug.ini \
23+
&& rm -rf /tmp/pear
24+
25+
26+
# Install composer
27+
RUN curl -sSL https://getcomposer.org/installer | php \
28+
&& chmod +x composer.phar \
29+
&& mv composer.phar /usr/local/bin/composer
30+
31+
# [Optional] Uncomment this section to install additional packages.
32+
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
33+
&& apt-get -y install python3-pip git zlib1g-dev unzip
34+
35+
# Pre-Commit to run pre-commit tools
36+
RUN pip3 install pre-commit

‎.devcontainer/devcontainer.json‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,20 @@
44
"name": "PHP",
55
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
66
"build": {
7-
"dockerfile": "Dockerfile"
7+
"dockerfile": "Dockerfile"
88
},
99

1010
// Configure tool-specific properties.
1111
"customizations": {
1212
"vscode": {
1313
"extensions": [
1414
"brapifra.phpserver",
15-
"emallin.phpunit",
16-
"eamodio.gitlens"
15+
"eamodio.gitlens",
16+
"junstyle.php-cs-fixer",
17+
"hbenl.vscode-test-explorer",
18+
"renandelmonico.vscode-php-test-explorer",
19+
"xdebug.php-debug",
20+
"bmewburn.vscode-intelephense-client"
1721
]
1822
}
1923
},
@@ -25,7 +29,7 @@
2529

2630
// Use 'postCreateCommand' to run commands after the container is created.
2731
"postCreateCommand": "sudo chmod a+x \"$(pwd)\" && sudo rm -rf /var/www/html && sudo ln -s \"$(pwd)\" /var/www/html",
28-
32+
2933
// Features to add to the dev container. More info: https://containers.dev/features.
3034
"features": {
3135
"ghcr.io/warrenbuckley/codespace-features/sqlite:1": {}

‎.github/workflows/deploy.yaml‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# This workflow will install Composer dependencies,
2+
# run tests and code quality checks with a variety of PHP versions.
3+
4+
name: Test and QA
5+
6+
on:
7+
push:
8+
workflow_dispatch:
9+
10+
jobs:
11+
tests:
12+
runs-on: ubuntu-20.04
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
php-version: ["7.0", "7.4", "8.3"]
17+
18+
steps:
19+
- uses: actions/checkout@v4
20+
- name: Set up PHP ${{ matrix.php-version }}
21+
uses: shivammathur/setup-php@v2
22+
with:
23+
php-version: ${{ matrix.php-version }}
24+
tools: composer
25+
- name: Install dependencies
26+
run: |
27+
# Install specific PHP version dependencies
28+
composer update
29+
- name: Quality Assurance
30+
# only in the minimum supported version
31+
if: matrix.php-version == '7.0'
32+
run: |
33+
composer cs
34+
composer csfixer-ci
35+
- name: Tests
36+
env:
37+
SQLITE_CONNECTION_STRING: ${{ vars.SQLITE_CONNECTION_STRING }}
38+
SQLITE_USER: ${{ secrets.SQLITE_USER }}
39+
SQLITE_PASSWORD: ${{ secrets.SQLITE_PASSWORD }}
40+
SQLITE_API_KEY: ${{ secrets.SQLITE_API_KEY }}
41+
SQLITE_HOST: ${{ vars.SQLITE_HOST }}
42+
SQLITE_DB: ${{ vars.SQLITE_DB }}
43+
SQLITE_PORT: ${{ vars.SQLITE_PORT }}
44+
run: |
45+
composer test-suite-codecov
46+
- name: Upload coverage reports to Codecov
47+
uses: codecov/codecov-action@v4.0.1
48+
with:
49+
token: ${{ secrets.CODECOV_TOKEN }}

‎.github/workflows/release.yaml‎

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# Create an incremental tag on Github using SemVer https://semver.org: x.y.z
2+
# A tag is a release version on Packagist.org, which is
3+
# automatically notified by its webook on tag changes.
24

35
name: Release
46

@@ -7,23 +9,34 @@ on:
79
inputs:
810
choice:
911
type: choice
10-
description: Release type
12+
description: "Release types (x.y.patch / x.minor.z / major.y.z)"
1113
options:
12-
- patch (x.y.Z)
13-
- minor (x.Y.z)
14-
- major (X.y.z)
14+
- patch
15+
- minor
16+
- major
1517

1618
jobs:
1719
release:
1820
if: ${{ github.ref == 'refs/heads/main' }}
1921
runs-on: ubuntu-latest
2022
name: Tag for release
21-
2223
steps:
23-
- name: Create tag as version for package on Packagist.org
24-
id: create-tag
25-
uses: GregoryGost/version-tagger@latest
26-
with:
27-
token: ${{ secrets.GITHUB_TOKEN }}
28-
uselasttag: true
29-
releasetype: ${{ inputs.choice }}
24+
- name: Checkout code
25+
uses: actions/checkout@v2
26+
with:
27+
fetch-depth: 0
28+
- name: Last version
29+
id: last-version
30+
run: echo "::set-output name=tag::$(git describe --tags `git rev-list --tags --max-count=1`)"
31+
- name: Bump version
32+
id: bump-version
33+
uses: olegsu/semver-action@v1
34+
with:
35+
version: ${{ steps.last-version.outputs.tag }}
36+
bump: ${{ inputs.choice }}
37+
- name: Create tag as version for the package on Packagist.org
38+
run: |
39+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
40+
git config --global user.name "GitHub Actions"
41+
git tag ${{ steps.bump-version.outputs.version }}
42+
git push origin ${{ steps.bump-version.outputs.version }}

‎.gitignore‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@ vendor
55
.phpunit.result.cache
66

77
.env
8+
9+
# cache
10+
.php_cs.cache
11+
.php-cs-fixer.cache

‎.php-cs-fixer.php‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
$finder = (new PhpCsFixer\Finder())
4+
->in(__DIR__)
5+
;
6+
7+
return (new PhpCsFixer\Config())
8+
->setRules([
9+
'@PHP70Migration' => true,
10+
'@PSR12' => true,
11+
// PHP >= 7.1 required for const
12+
'visibility_required' => [
13+
'elements' => ['property', 'method']
14+
],
15+
])
16+
->setFinder($finder)
17+
;

‎.pre-commit-config.yaml‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Pre-Commit
2+
# https://pre-commit.com
3+
# Run formatter and more before git commit.
4+
repos:
5+
- repo: https://github.com/pre-commit/pre-commit-hooks
6+
rev: v2.3.0
7+
hooks:
8+
- id: trailing-whitespace
9+
- id: end-of-file-fixer
10+
- id: detect-private-key
11+
- id: check-merge-conflict
12+
- repo: local
13+
hooks:
14+
- id: php-cs-fixer
15+
name: php-cs-fixer
16+
language: script
17+
entry: vendor/bin/php-cs-fixer
18+
args:
19+
- fix
20+
- --config=.php-cs-fixer.php
21+
files: \.php$
22+
require_serial: true
23+
- repo: local
24+
hooks:
25+
- id: php-code-sniffer
26+
name: php-code-sniffer
27+
language: script
28+
entry: vendor/bin/phpcs
29+
args:
30+
- --standard=PSR12
31+
- --warning-severity=0
32+
- --runtime-set
33+
- ignore_warnings_on_exit 1
34+
- --ignore=^admin/.*$
35+
require_serial: true

‎.vscode/launch.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@
4545
}
4646
}
4747
]
48-
}
48+
}

‎.vscode/settings.json‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@
22
"php.suggest.basic": false,
33
"phpserver.relativePath": "./admin",
44
"intelephense.environment.phpVersion": "7.0.0",
5-
"intelephense.telemetry.enabled": false
6-
}
5+
"intelephense.telemetry.enabled": false,
6+
"php-cs-fixer.executablePath": "${workspaceFolder}/vendor/bin/php-cs-fixer",
7+
"phpunit.logpanel": true,
8+
}

‎README.md‎

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,54 @@
1-
# sqlitecloud-php
1+
# Driver for SQLite Cloud
2+
3+
<p align="center">
4+
<img src="https://sqlitecloud.io/social/logo.png" height="300" alt="SQLite Cloud logo">
5+
</p>
6+
7+
8+
[![Test and QA](https://github.com/sqlitecloud/sqlitecloud-php/actions/workflows/deploy.yaml/badge.svg?branch=main)](https://github.com/sqlitecloud/sqlitecloud-php/actions/workflows/deploy.yaml)
9+
[![codecov](https://codecov.io/gh/sqlitecloud/sqlitecloud-php/graph/badge.svg?token=3FFHULGCOY)](https://codecov.io/gh/sqlitecloud/sqlitecloud-php)
10+
![PHP](https://img.shields.io/packagist/dependency-v/sqlitecloud/sqlitecloud/php)
11+
12+
13+
- [Driver for SQLite Cloud](#driver-for-sqlite-cloud)
14+
- [Example](#example)
15+
16+
---
17+
18+
[SQLite Cloud](https://sqlitecloud.io) is a powerful Python package that allows you to interact with the SQLite Cloud database seamlessly. It provides methods for various database operations. This package is designed to simplify database operations in PHP applications, making it easier than ever to work with SQLite Cloud.
19+
20+
21+
- Documentation: [https://docs.sqlitecloud.io/docs/sdk/php/admin](https://docs.sqlitecloud.io/docs/sdk/php/admin)
22+
- Source: [https://github.com/sqlitecloud/sqlitecloud-php](https://github.com/sqlitecloud/sqlitecloud-php)
23+
- Site: [https://sqlitecloud.io](https://sqlitecloud.io/developers)
24+
25+
## Example
26+
27+
```bash
28+
$ composer install sqlitecloud/sqlitecloud
29+
```
30+
31+
```php
32+
use use SQLiteCloud\SQLiteCloudClient;
33+
use SQLiteCloud\SQLiteCloudRowset;
34+
35+
# Open the connection to SQLite Cloud
36+
$sqlite = new SQLiteCloud();
37+
$sqlite->connectWithString('sqlitecloud://myhost.sqlite.cloud:8860?apikey=myapikey');
38+
39+
# You can autoselect the database during the connect call
40+
# by adding the database name as path of the SQLite Cloud
41+
# connection string, eg:
42+
# $sqlite->connectWithString("sqlitecloud://myhost.sqlite.cloud:8860/mydatabase?apikey=myapikey");
43+
$db_name = 'chinook.sqlite';
44+
$sqlite->execute("USE DATABASE {$db_name}");
45+
46+
/** @var SQLiteCloudRowset */
47+
$rowset = $sqlite->execute('SELECT * FROM albums WHERE AlbumId = 1');
48+
49+
print('First colum, first row: ' . $rowset->value(0, 0));
50+
print('Second colum, first row: ' . $rowset->value(0, 1));
51+
print('column name: ' . $rowset->name(1));
52+
53+
$sqlite->disconnect()
54+
```

0 commit comments

Comments
 (0)