Skip to content

Commit

Permalink
Updated CI to automatically test using the latest versions of PHP; ad…
Browse files Browse the repository at this point in the history
…ded GitHub Pages deployment; updated package name references, including build status icons; added phpDoc output to gitignore (should be generated during CI build)
  • Loading branch information
d-miles committed Aug 12, 2024
1 parent f83965c commit b0d5487
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 1,808 deletions.
60 changes: 46 additions & 14 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,29 @@ on: [push]
# branches: [ "main" ]
#pull_request:
# branches: [ "main" ]

permissions:
contents: read

jobs:
build-test:

supported-php-versions:
runs-on: ubuntu-latest

name: Get supported PHP versions
outputs:
php-versions: ${{ steps.versions.outputs.range }}
steps:
- uses: tighten/phpreleases-action@v1
id: versions

test:
needs: supported-php-versions
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
operating-system: [ubuntu-latest]
php-versions: ['8.1', '8.2', '8.3', '8.4']
#php-versions: ['8.1', '8.2', '8.3', '8.4']
php-versions: ${{ fromJSON(needs.supported-php-versions.outputs.php-versions) }}

name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }}
steps:
Expand All @@ -29,21 +40,42 @@ jobs:

- name: Validate composer.json and composer.lock
run: composer validate --strict

- name: Cache Composer packages
- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache Composer packages
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
${{ runner.os }}-composer-
- name: Install dependencies
run: composer install --prefer-dist --no-progress

# Add a test script to composer.json, for instance: "test": "vendor/bin/phpunit"
# Docs: https://getcomposer.org/doc/articles/scripts.md

- name: Run test suite
- name: Run tests
run: composer run-script test

deploy:
needs: test
runs-on: ubuntu-latest

name: Deploy to GitHub Pages
steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: composer install --prefer-dist --no-progress
- name: Generate phpDoc
run: composer run-script phpdoc

- name: Upload GitHub Pages artifact
uses: actions/upload-pages-artifact@v3
with:
path: docs/

- name: Deploy GitHub Pages site
id: deployment
uses: actions/deploy-pages@v4
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.DS_Store
vendor/
docs/phpdoc/
*.phar
.phpunit.result.cache
.phpdoc
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

PHP REST Service is a simple and fast PHP class for RESTful JSON APIs.

[![Build Status](https://img.shields.io/circleci/build/github/cdgco/php-rest-service?style=flat-square)](https://app.circleci.com/pipelines/github/cdgco/php-rest-service)
[![PHP Version](https://img.shields.io/packagist/php-v/cdgco/php-rest-service?style=flat-square)](https://www.php.net/downloads)
[![Package Version](https://img.shields.io/packagist/v/cdgco/php-rest-service?style=flat-square)](https://packagist.org/packages/cdgco/php-rest-service)
[![License](https://img.shields.io/github/license/cdgco/php-rest-service?style=flat-square)](https://github.com/cdgco/php-rest-service/blob/master/LICENSE)
[![Build Status](https://img.shields.io/github/actions/workflow/status/d-miles/php-rest-service/php.yml?logo=php&logoColor=%23777BB4&logoSize=auto&labelColor=%23efefef)](https://github.com/d-miles/php-rest-service/actions/workflows/php.yml)
[![PHP Version](https://img.shields.io/packagist/php-v/d-miles/php-rest-service?style=flat-square)](https://www.php.net/downloads)
[![Package Version](https://img.shields.io/packagist/v/d-miles/php-rest-service?style=flat-square)](https://packagist.org/packages/d-miles/php-rest-service)
[![License](https://img.shields.io/github/license/d-miles/php-rest-service?style=flat-square)](https://github.com/d-miles/php-rest-service/blob/master/LICENSE)

[https://cdgco.github.io/php-rest-service](https://cdgco.github.io/php-rest-service)
[https://d-miles.github.io/php-rest-service](https://d-miles.github.io/php-rest-service)
</div>

## Features
Expand All @@ -31,7 +31,7 @@ PHP REST Service is a simple and fast PHP class for RESTful JSON APIs.
## Requirements
* PHP 8.1+ (Tested on PHP 8.1 - 8.4)
## Installation
`php composer require cdgco/php-rest-service`
`php composer require d-miles/php-rest-service`

## Demo

Expand Down Expand Up @@ -93,7 +93,7 @@ Both methods will generate the following endpoints:

# Documentation

Read the full documentation at [https://cdgco.github.io/php-rest-service](https://cdgco.github.io/php-rest-service).
Read the full documentation at [https://d-miles.github.io/php-rest-service](https://d-miles.github.io/php-rest-service).

## License

Expand Down
22 changes: 11 additions & 11 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

PHP REST Service is a simple and fast PHP class for RESTful JSON APIs.

[![Build Status](https://img.shields.io/circleci/build/github/cdgco/php-rest-service?style=flat-square)](https://app.circleci.com/pipelines/github/cdgco/php-rest-service)
[![PHP Version](https://img.shields.io/packagist/php-v/cdgco/php-rest-service?style=flat-square)](https://www.php.net/downloads)
[![Package Version](https://img.shields.io/packagist/v/cdgco/php-rest-service?style=flat-square)](https://packagist.org/packages/cdgco/php-rest-service)
[![License](https://img.shields.io/github/license/cdgco/php-rest-service?style=flat-square)](https://github.com/cdgco/php-rest-service/blob/master/LICENSE)
[![Build Status](https://img.shields.io/github/actions/workflow/status/d-miles/php-rest-service/php.yml?logo=php&logoColor=%23777BB4&logoSize=auto&labelColor=%23efefef)](https://github.com/d-miles/php-rest-service/actions/workflows/php.yml)
[![PHP Version](https://img.shields.io/packagist/php-v/d-miles/php-rest-service?style=flat-square)](https://www.php.net/downloads)
[![Package Version](https://img.shields.io/packagist/v/d-miles/php-rest-service?style=flat-square)](https://packagist.org/packages/d-miles/php-rest-service)
[![License](https://img.shields.io/github/license/d-miles/php-rest-service?style=flat-square)](https://github.com/d-miles/php-rest-service/blob/master/LICENSE)
</div>

## Features
Expand All @@ -30,8 +30,8 @@ PHP REST Service is a simple and fast PHP class for RESTful JSON APIs.

PHP REST Service is a lightweight API framework for PHP. It is very easy to learn, use, and integrate with existing PHP projects.

This package is a fork of `marcj/php-rest-service` with the following changes:
* Support for PHP 7.4+
This package is a fork of `marcj/php-rest-service`/`cdgco/php-rest-service` with the following changes:
* Support for PHP 8.1+
* Support for plain text responses
* Support for custom response formats
* Support for pre-response control functions
Expand Down Expand Up @@ -327,27 +327,27 @@ To enable OpenAPI generation, simply use the [`setApiSpec()`](phpdoc/#serverseta

```php
Server::create('test')
-->setApiSpec("My New API", "1.2.3", "This is my new API", "https://example.com/api", true)
->setApiSpec("My New API", "1.2.3", "This is my new API", "https://example.com/api", true)
->addGetRoute('', function($test) {
return "Hello ". $test;
})
```

This will generate an OpenAPI specification in JSON format, accessible at the `/spec` GET endpoint of your API, including all endpoints in child controllers.
This will generate an OpenAPI specification in JSON format, accessible at the `/openapi` GET endpoint of your API, including all endpoints in child controllers.

!> Note: If there is another endpoint named `/spec`, it will take priority over the OpenAPI specification.
!> Note: If there is another endpoint named `/openapi`, it will take priority over the OpenAPI specification.

Request and response types and descriptions will be pulled from the comment blocks of your endpoint functions.
If no comment annotations are detected, the request / respone types will default to `AnyValue`.

If your URL contains regex, REST API Service will attempt to scan your string and replace any regex capture groups with the corresponding argument name, and delete any non-capture groups, however, it is unable to process regex commands outside of capture groups. In order to specify the correct URL that will be used in the specification, you can provide the `@openapiurl` annotation on your endpoint function.
If your URL contains regex, REST API Service will attempt to scan your string and replace any regex capture groups with the corresponding argument name, and delete any non-capture groups, however, it is unable to process regex commands outside of capture groups. In order to specify the correct URL that will be used in the specification, you can provide the `@openapi-url` annotation on your endpoint function.

For example, say you already have an endpoint at `/foo/(\d+)` and you want to add an endpoint at `/foo/\d+/(\w+)`. While you could rewrite this to use non-capture groups like `/foo/(?:\d+)/(\w+)`, you can also add the following annotation to the endpoint function:

```php
/**
* @url /foo/\d+/(\w+)
* @openapiurl /foo/{var1}/{var2}
* @openapi-url /foo/{var1}/{var2}
*/
```

Expand Down
5 changes: 0 additions & 5 deletions docs/_sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,3 @@
* [parsePhpDoc](phpdoc/#serverparsephpdoc)
* [argumentName](phpdoc/#serverargumentname)
* [findRoute](phpdoc/#serverfindroute)


2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<script>
window.$docsify = {
name: 'PHP REST Service',
repo: 'https://github.com/cdgco/php-rest-service',
repo: 'https://github.com/d-miles/php-rest-service',
loadSidebar: true,
search: {
paths: ['/',
Expand Down
Loading

0 comments on commit b0d5487

Please # to comment.