diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 5362e5c..43baff3 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -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: @@ -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 \ No newline at end of file diff --git a/.gitignore b/.gitignore index a010241..488e398 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .DS_Store vendor/ +docs/phpdoc/ *.phar .phpunit.result.cache .phpdoc \ No newline at end of file diff --git a/README.md b/README.md index 2e83a57..b15668d 100644 --- a/README.md +++ b/README.md @@ -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) ## Features @@ -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 @@ -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 diff --git a/docs/README.md b/docs/README.md index d7cfeff..d261615 100644 --- a/docs/README.md +++ b/docs/README.md @@ -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) ## Features @@ -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 @@ -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} */ ``` diff --git a/docs/_sidebar.md b/docs/_sidebar.md index 1d22e38..0bb45ec 100644 --- a/docs/_sidebar.md +++ b/docs/_sidebar.md @@ -100,8 +100,3 @@ * [parsePhpDoc](phpdoc/#serverparsephpdoc) * [argumentName](phpdoc/#serverargumentname) * [findRoute](phpdoc/#serverfindroute) - - - - - diff --git a/docs/index.html b/docs/index.html index 765c3a2..7b064e3 100644 --- a/docs/index.html +++ b/docs/index.html @@ -28,7 +28,7 @@