Skip to content

Commit

Permalink
Moved to SF 5.3 and PHP8 (#12)
Browse files Browse the repository at this point in the history
* Support PHP 8.0 and Symfony 5
* Use github workflows
* Removed unused security check
  • Loading branch information
Thomas Jarrand authored Feb 25, 2022
1 parent c3bdb2c commit 4a6459e
Show file tree
Hide file tree
Showing 14 changed files with 304 additions and 112 deletions.
115 changes: 115 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
name: 'CI'

on:
push:
branches:
- master
pull_request:

jobs:

lint:
name: 'Lint'
runs-on: ubuntu-latest
timeout-minutes: 5

steps:
- name: 'Checkout'
uses: actions/checkout@v2

- name: 'Setup PHP'
uses: shivammathur/setup-php@v2
with:
coverage: "none"
extensions: "json"
ini-values: "memory_limit=-1"
php-version: "8.0"

- name: 'Determine composer cache directory'
id: composer-cache
run: echo "::set-output name=directory::$(composer config cache-dir)"

- name: 'Cache composer dependencies'
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.directory }}
key: 7.4-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: 7.4-composer-

- name: 'Install dependencies'
id: deps
run: |
echo "::group::composer update"
composer update --no-progress --ansi
echo "::endgroup::"
echo "::group::install phpunit"
# Required for PhpStan
vendor/bin/simple-phpunit install
echo "::endgroup::"
- name: 'Composer validate'
if: always() && steps.deps.outcome == 'success'
run: composer validate --strict

- name: 'PHP CS Fixer'
if: always() && steps.deps.outcome == 'success'
run: vendor/bin/php-cs-fixer fix --dry-run --diff

- name: 'PhpStan'
if: always() && steps.deps.outcome == 'success'
run: vendor/bin/phpstan analyse

tests:
name: 'Tests'
runs-on: ubuntu-latest
timeout-minutes: 5

strategy:
fail-fast: false # don't cancel other matrix jobs on failure
matrix:
php: [ '7.4', '8.0' ]

steps:
- name: 'Checkout'
uses: actions/checkout@v2

- name: 'Setup PHP'
uses: shivammathur/setup-php@v2
with:
coverage: "none"
extensions: "json"
ini-values: "memory_limit=-1"
php-version: "${{ matrix.php }}"

- name: 'Determine composer cache directory'
id: composer-cache
run: echo "::set-output name=directory::$(composer config cache-dir)"

- name: 'Cache composer dependencies'
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.directory }}
key: ${{ matrix.php }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ matrix.php }}-composer-

#- name: 'Fixup Composer'
# if: matrix.php == 8.0
# run: |
# echo "::group::Fixup Composer platform config for third-parties deps not PHP 8 ready yet"
# composer config platform.php 7.4.99
# echo "::endgroup::"

- name: 'Install dependencies'
run: |
echo "::group::composer update"
composer update --no-progress --ansi
echo "::endgroup::"
echo "::group::install phpunit"
vendor/bin/simple-phpunit install
echo "::endgroup::"
- name: 'Run tests'
run: vendor/bin/simple-phpunit --testdox

13 changes: 12 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
/vendor/*
###> symfony/phpunit-bridge ###
.phpunit
.phpunit.result.cache
/phpunit.xml
###< symfony/phpunit-bridge ######

###> friendsofphp/php-cs-fixer ###
/.php-cs-fixer.php
/.php-cs-fixer.cache
###< friendsofphp/php-cs-fixer ###

/vendor/
composer.lock
29 changes: 29 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

$finder = (new PhpCsFixer\Finder())->in([
__DIR__
]);

return (new PhpCsFixer\Config())
->setFinder($finder)
->setCacheFile('.php-cs-fixer.cache') // forward compatibility with 3.x line
->setRiskyAllowed(true)
->setRules([
'@PSR12' => true,
'@Symfony' => true,
'strict_param' => true,
'array_syntax' => ['syntax' => 'short'],
'concat_space' => ['spacing' => 'one'],
'declare_strict_types' => true,
'native_function_invocation' => ['include' => ['@compiler_optimized']],
'no_superfluous_phpdoc_tags' => true,
'ordered_imports' => true,
'phpdoc_annotation_without_dot' => false,
'phpdoc_order' => true,
'phpdoc_summary' => false,
'simplified_null_return' => false,
'single_line_throw' => false,
'void_return' => true,
'yoda_style' => false,
])
;
35 changes: 0 additions & 35 deletions .travis.yml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Elao\Bundle\JsonHttpFormBundle\DependencyInjection\Compiler;

use Elao\Bundle\JsonHttpFormBundle\Form\RequestHandler\JsonHttpFoundationRequestHandler;
Expand Down
4 changes: 3 additions & 1 deletion ElaoJsonHttpFormBundle.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?php

declare(strict_types=1);

namespace Elao\Bundle\JsonHttpFormBundle;

use Elao\Bundle\JsonHttpFormBundle\DependencyInjection\Compiler\OverrideRequestHandlerCompilerPass;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;

class ElaoJsonHttpFormBundle extends Bundle
{
Expand Down
23 changes: 10 additions & 13 deletions Form/RequestHandler/JsonHttpFoundationRequestHandler.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Elao\Bundle\JsonHttpFormBundle\Form\RequestHandler;

use Symfony\Component\Form\Exception\UnexpectedTypeException;
Expand All @@ -17,15 +19,14 @@
*/
class JsonHttpFoundationRequestHandler extends HttpFoundationRequestHandler
{
/** @var ServerParams */
private $serverParams;

/**
* Methods that have a body
*
* @var array
* @var array<string>
*/
private static $bodyMethods = ['POST', 'PUT', 'PATCH', 'DELETE'];
private static array $bodyMethods = ['POST', 'PUT', 'PATCH', 'DELETE'];

private ServerParams $serverParams;

public function __construct(ServerParams $serverParams = null)
{
Expand All @@ -34,6 +35,9 @@ public function __construct(ServerParams $serverParams = null)
$this->serverParams = $serverParams ?: new ServerParams();
}

/**
* @param mixed $request Support old versions of RequestHandlerInterface
*/
public function handleRequest(FormInterface $form, $request = null): void
{
if (!$request instanceof Request) {
Expand All @@ -42,7 +46,7 @@ public function handleRequest(FormInterface $form, $request = null): void

if (
'json' === $request->getContentType()
&& in_array($request->getMethod(), static::$bodyMethods, false)
&& \in_array($request->getMethod(), static::$bodyMethods, false)
) {
$this->handleJsonRequest($form, $request);

Expand All @@ -54,9 +58,6 @@ public function handleRequest(FormInterface $form, $request = null): void

/**
* Handle Json Request
*
* @param FormInterface $form
* @param Request $request
*/
protected function handleJsonRequest(FormInterface $form, Request $request): void
{
Expand Down Expand Up @@ -98,10 +99,6 @@ protected function handleJsonRequest(FormInterface $form, Request $request): voi
*
* Code from {@link HttpFoundationRequestHandler} max size verification.
*
* @param FormInterface $form
*
* @return boolean
*
* @author Bernhard Schussek <[email protected]>
*/
protected function isContentSizeValid(FormInterface $form): bool
Expand Down
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 élao

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
29 changes: 29 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
###########
# Install #
###########

install:
composer update

########
# Lint #
########

lint: lint.php-cs-fixer lint.phpstan lint.composer

lint.php-cs-fixer:
vendor/bin/php-cs-fixer fix

lint.phpstan:
vendor/bin/phpstan analyse .

lint.composer:
composer validate --strict

########
# Test #
########

## Test
test:
vendor/bin/simple-phpunit
36 changes: 8 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Elao JSON HTTP Form Bundle ![](https://img.shields.io/badge/Symfony-3.0-blue.svg)
==========================
# Elao JSON HTTP Form Bundle ![](https://img.shields.io/badge/Symfony-5.3-blue.svg)

[![Build Status](https://travis-ci.org/Elao/ElaoJsonHttpFormBundle.svg)](https://travis-ci.org/Elao/ElaoJsonHttpFormBundle)

Expand All @@ -11,34 +10,15 @@ The `JsonHttpFoundationRequestHandler` handles the request: If the request conte

Otherwise, it lets the default behaviour operate: the `HttpFoundationRequestHandler` will handle the request. So all your non-json form request will be treated just the way they've always been.

Installation:
-------------
## Installation

Add _ElaoJsonHttpFormBundle_ to your composer.json:
Require _ElaoJsonHttpFormBundle_:

```bash
$ php composer.phar require elao/json-http-form-bundle
```shell
composer require elao/json-http-form-bundle
```

Register the bundle in the kernel:

```php
<?php
// app/AppKernel.php

public function registerBundles()
{
$bundles = array(
// ...
new Elao\Bundle\JsonHttpFormBundle\ElaoJsonHttpFormBundle(),
);
}
```

That's it. You're good. Get some well deserved rest.

Usage:
---------
## Usage

Given a `Rocket` entity with two attributes: `name` (a string) and `colors` (an array of strings).

Expand Down Expand Up @@ -111,9 +91,9 @@ Content-Length: 43
{"name":"Melies","colors":["pink","brown"]}
```
\o/
It works \o/

License
## License
-------

MIT
Expand Down
Loading

0 comments on commit 4a6459e

Please sign in to comment.