Skip to content

Commit cfc9ead

Browse files
authored
Merge pull request #3 from Delivery-Direto/master
Merge contributions from Delivery-Direto fork
2 parents 158dab3 + 851446a commit cfc9ead

30 files changed

Lines changed: 1315 additions & 170 deletions

.github/pull-request.yml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: Pull Request
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
build:
8+
runs-on: ubuntu-latest
9+
strategy:
10+
matrix:
11+
operating-system: [ ubuntu-20.04 ]
12+
php-versions: ['8.0', '8.1']
13+
14+
name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }}
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v2
18+
19+
- name: Setup PHP
20+
uses: shivammathur/setup-php@v2
21+
with:
22+
php-version: ${{ matrix.php-versions }}
23+
extensions: mbstring, intl, xdebug
24+
25+
- name: PHP Version
26+
run: php -v
27+
28+
- name: Install dependencies
29+
if: steps.composer-cache.outputs.cache-hit != 'true'
30+
run: |
31+
composer self-update
32+
composer validate
33+
composer install --prefer-dist --no-progress
34+
35+
- name: Test Suite (8.0 only)
36+
if: ${{ matrix.php-versions == '8.0' }}
37+
run: |
38+
composer test
39+
echo ${{ matrix.php-versions }}
40+
41+
- name: Test Suite + Static Analysis (8.1 only)
42+
if: ${{ matrix.php-versions == '8.1' }}
43+
env:
44+
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
45+
run: |
46+
composer analyze
47+
echo ${{ matrix.php-versions }}
48+
49+
# TODO:
50+
# - name: Upload coverage results to Coveralls (8.1 only)
51+
# if: ${{ matrix.php-versions == '8.1' }}
52+
# env:
53+
# COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
54+
# run: |
55+
# composer global require php-coveralls/php-coveralls
56+
# export CODECOVERAGE=1 && vendor/bin/phpunit --verbose --coverage-clover=clover.xml
57+
# php-coveralls --coverage_clover=clover.xml -v
58+
#
59+
# CakePHP version compatability
60+
#
61+
compatibility:
62+
runs-on: ubuntu-latest
63+
strategy:
64+
matrix:
65+
version: ['~4.2.0', '^4.3']
66+
steps:
67+
- name: Checkout
68+
uses: actions/checkout@v2
69+
70+
- name: Setup PHP
71+
uses: shivammathur/setup-php@v2
72+
with:
73+
php-version: '8.1'
74+
extensions: mbstring, intl
75+
76+
- name: PHP Version
77+
run: php -v
78+
79+
- name: CakePHP ${{matrix.version}} Compatability
80+
run: |
81+
composer self-update
82+
rm -rf composer.lock
83+
composer require cakephp/cakephp:${{matrix.version}} --no-update
84+
composer install --prefer-dist --no-progress
85+
composer test

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ composer.lock
55
.php_cs*
66
/coverage
77
rr
8+
.phpunit.result.cache

README.md

Lines changed: 63 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,76 @@
1-
Roadrunner for CakePHP
2-
===================
1+
# Roadrunner for CakePHP
32

4-
[![Downloads](https://poser.pugx.org/cakedc/cakephp-roadrunner/d/total.png)](https://packagist.org/packages/cakedc/cakephp-roadrunner)
5-
[![Latest Version](https://poser.pugx.org/cakedc/cakephp-roadrunner/v/stable.png)](https://packagist.org/packages/cakedc/cakephp-roadrunner)
6-
[![License](https://poser.pugx.org/cakedc/cakephp-roadrunner/license.svg)](https://packagist.org/packages/cakedc/cakephp-roadrunner)
3+
[RoadRunner](https://roadrunner.dev/) is a high-performance PHP application server, load-balancer, and process
4+
manager written in Golang. Using Roadrunner you can replace php-fpm a long with nginx or apache.
75

6+
## Requirements
87

9-
Requirements
10-
------------
8+
* CakePHP ^4.4
9+
* PHP ^8.1
10+
* Roadrunner ^2023.1.4
1111

12-
* CakePHP 3.6.0+
13-
* PHP 7.1+
12+
## Table of Contents
13+
14+
- [Install](#install)
15+
- [Sessions](#sessions)
16+
- [Static Assets](#static-assets)
1417

15-
Setup
16-
-----
18+
## Install
1719

18-
* `composer require cakedc/cakephp-roadrunner`
19-
* Download roadrunner binary and place the file in your filesystem, for example under `/usr/local/bin/rr`
20-
* Create a RoadRunner worker file, or use the example worker provided
20+
Install via composer:
2121

22-
```bash
22+
```console
23+
composer require cakedc/cakephp-roadrunner
24+
```
25+
26+
Unlike most CakePHP plugins you won't be needing to load the plugin in your `src/Application.php`.
27+
28+
### Installing Roadrunner
29+
30+
Roadrunner ships as a single go binary. Download the Roadrunner binary from the
31+
[release page](https://github.com/roadrunner-server/roadrunner/releases) and copy the file to your
32+
filesystem, for example under `/usr/local/bin/rr` or `/usr/bin/rr`.
33+
34+
If your project uses Docker you can easily add the binary to your Dockerfile:
35+
36+
```dockerfile
37+
FROM spiralscout/roadrunner:2.12 as roadrunner
38+
COPY --from=roadrunner /usr/bin/rr /usr/bin/rr
39+
```
40+
41+
Be sure to check the Roadrunner documentation for up-to-date [docker images](https://roadrunner.dev/docs/docker-images).
42+
43+
### Configuring Roadrunner
44+
45+
In a typical PHP application your webserver forwards `*.php` requests to php-fpm, which in turn calls the CakePHP
46+
front controller `webroot/index.php`. With Roadrunner, the worker file gets called by active workers to handle
47+
incoming requests to your application.
48+
49+
Create a Roadrunner worker file, or use the [example worker](worker/cakephp-worker.php) provided:
50+
51+
```console
2352
cp vendor/cakedc/cakephp-roadrunner/worker/cakephp-worker.php .
24-
cp vendor/cakedc/cakephp-roadrunner/worker/.rr.json .
2553
```
2654

27-
Note the configuration is stored in .rr.json file, check all possible keys here
28-
https://github.com/spiral/roadrunner/wiki/Configuration
55+
Next we need to instruct Roadrunner to use our worker a long with a few other configs. Create a
56+
[Roadrunner config](https://roadrunner.dev/docs/intro-config) file, or use the [example config](worker/rr.yaml)
57+
provided:
2958

30-
* Start the server, either using your own configuration or the sample configuration provided in the plugin
59+
```console
60+
cp vendor/cakedc/cakephp-roadrunner/worker/rr.yaml .
61+
```
3162

32-
`/usr/local/bin/rr serve`
63+
Start the server:
3364

34-
* If you need sessions
35-
* Ensure you add the following to your session config in your CakePHP `config/app.php`
65+
```console
66+
/usr/local/bin/rr serve -d -c rr.yaml
67+
```
68+
69+
You should now be able to browse to http://localhost:8080
70+
71+
## Sessions
72+
73+
If you need sessions ensure you add the following to your session config in your CakePHP `config/app.php`
3674

3775
```php
3876
'Session' => [
@@ -53,7 +91,7 @@ https://github.com/spiral/roadrunner/wiki/Configuration
5391
->add(new \Relay\Middleware\SessionHeadersHandler())
5492
```
5593

56-
* Nginx proxy
94+
## Static Assets
5795

5896
You'll possibly need to configure a webserver to handle requests, serve static assets etc.
5997
Use this sample config virtualhost for nginx:
@@ -76,33 +114,7 @@ server {
76114
proxy_set_header X-Forwarded-Host $server_name;
77115
}
78116
}
79-
80117
```
81-
82-
Documentation
83-
-------------
84-
85-
For documentation, as well as tutorials, see the [Docs](Docs/Home.md) directory of this repository.
86-
87-
Support
88-
-------
89-
90-
For bugs and feature requests, please use the [issues](https://github.com/cakedc/cakephp-roadrunner/issues) section of this repository.
91-
92-
Commercial support is also available, [contact us](https://www.cakedc.com/contact) for more information.
93-
94-
Contributing
95-
------------
96-
97-
This repository follows the [CakeDC Plugin Standard](https://www.cakedc.com/plugin-standard). If you'd like to contribute new features, enhancements or bug fixes to the plugin, please read our [Contribution Guidelines](https://www.cakedc.com/contribution-guidelines) for detailed instructions.
98-
99-
License
100-
-------
101-
102-
Copyright 2019 Cake Development Corporation (CakeDC). All rights reserved.
103-
104-
Licensed under the [MIT](http://www.opensource.org/licenses/mit-license.php) License. Redistributions of the source code included in this repository must retain the copyright notice found in each file.
105118

106-
Todo
107-
----
108-
* Existing issue setting cookies like $this->response = $this->response->withHeader('head', 'one'); conflicts with session cookie generation
119+
Roadrunner also supports [serving static assets](https://roadrunner.dev/docs/http-static) natively. Check the
120+
[worker/rr.yaml](worker/rr.yaml) file that ships with this project for an example.

cloudbuild.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
steps:
2+
- id: Install dependencies
3+
name: nixos/nix:2.3
4+
entrypoint: nix-shell
5+
args:
6+
- --run
7+
- composer install
8+
9+
- id: Run linter, static analysis and tests
10+
name: nixos/nix:2.3
11+
entrypoint: nix-shell
12+
args:
13+
- --run
14+
- composer analyze
15+
16+
options:
17+
volumes:
18+
- name: nix-store
19+
path: /nix

composer.json

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@
44
"type": "cakephp-plugin",
55
"license": "MIT",
66
"require": {
7-
"cakephp/cakephp": "^3.6",
8-
"spiral/roadrunner": "^1.3",
9-
"relay/middleware": "^1.2"
7+
"php": "^8.1",
8+
"cakephp/cakephp": "^4.4",
9+
"spiral/roadrunner": "^2023.1.4",
10+
"laminas/laminas-diactoros": "^2.21",
11+
"spiral/roadrunner-http": "^3.0.1"
1012
},
1113
"require-dev": {
12-
"phpunit/phpunit": "^5.7|^6.0"
14+
"cakephp/cakephp-codesniffer": "^4.2",
15+
"phpunit/phpunit": "~8.5.0 || ^9.3",
16+
"phpstan/phpstan": "^1.4"
1317
},
1418
"autoload": {
1519
"psr-4": {
@@ -19,7 +23,25 @@
1923
"autoload-dev": {
2024
"psr-4": {
2125
"CakeDC\\Roadrunner\\Test\\": "tests",
26+
"App\\": "tests/test_app/src",
2227
"Cake\\Test\\": "./vendor/cakephp/cakephp/tests"
2328
}
29+
},
30+
"scripts": {
31+
"analyze": [
32+
"@test",
33+
"@phpcs",
34+
"@phpstan"
35+
],
36+
"test": "phpunit --colors=always",
37+
"phpcs": "phpcs --colors -p --standard=phpcs.xml src/ worker/cakephp-worker.php",
38+
"phpcbf": "phpcbf --colors --standard=phpcs.xml src/ worker/cakephp-worker.php",
39+
"phpstan": "phpstan analyse src/ worker/cakephp-worker.php",
40+
"coverage": "phpunit --coverage-html coverage/"
41+
},
42+
"config": {
43+
"allow-plugins": {
44+
"dealerdirect/phpcodesniffer-composer-installer": true
45+
}
2446
}
2547
}

phpcs.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="App">
3+
<config name="installed_paths" value="../../cakephp/cakephp-codesniffer" />
4+
<rule ref="CakePHP"/>
5+
</ruleset>

phpstan-baseline.neon

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
parameters:
2+
ignoreErrors:
3+

phpstan.neon

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
includes:
2+
- phpstan-baseline.neon
3+
4+
parameters:
5+
level: 6
6+
checkMissingIterableValueType: false
7+
checkGenericClassInNonGenericObjectType: false
8+
treatPhpDocTypesAsCertain: false
9+
bootstrapFiles:
10+
- tests/bootstrap.php
11+
paths:
12+
- src
13+
earlyTerminatingMethodCalls:
14+
Cake\Console\Shell:
15+
- abort

phpunit.xml.dist

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
colors="true"
4+
processIsolation="false"
5+
stopOnFailure="false"
6+
bootstrap="tests/bootstrap.php"
7+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
8+
<coverage>
9+
<include>
10+
<directory suffix=".php">src/</directory>
11+
</include>
12+
</coverage>
13+
<php>
14+
<ini name="memory_limit" value="-1"/>
15+
<ini name="apc.enable_cli" value="1"/>
16+
</php>
17+
<!-- Add any additional test suites you want to run here -->
18+
<testsuites>
19+
<testsuite name="app">
20+
<directory>tests/TestCase/</directory>
21+
</testsuite>
22+
<!-- Add plugin test suites here. -->
23+
</testsuites>
24+
<!-- Load extension for fixtures -->
25+
<extensions>
26+
<extension class="Cake\TestSuite\Fixture\PHPUnitExtension"/>
27+
</extensions>
28+
<!-- Ignore vendor tests in code coverage reports -->
29+
</phpunit>

shell.nix

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{ pkgs ? import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/c8a17ce7abc03c50cd072e9e6c9b389c5f61836b.tar.gz") {} }:
2+
with pkgs; let
3+
php = php81.withExtensions ({ enabled, all }: enabled);
4+
in
5+
mkShell {
6+
buildInputs = [
7+
php
8+
php.packages.composer
9+
];
10+
}

0 commit comments

Comments
 (0)