Skip to content

Commit

Permalink
Merge pull request #12 from SupraSmooth/master
Browse files Browse the repository at this point in the history
Update to Symfony 5.3 + Fix deprecation message on getMasterRequest() call
  • Loading branch information
markuspoerschke authored Jun 25, 2021
2 parents 819eb6c + d09987b commit 52e7763
Show file tree
Hide file tree
Showing 13 changed files with 1,010 additions and 1,036 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,12 @@
/var/
/vendor/
###< symfony/framework-bundle ###

###> friendsofphp/php-cs-fixer ###
# 2.x
/.php_cs
/.php_cs.cache
# 3.x
/.php-cs-fixer.php
/.php-cs-fixer.cache
###< friendsofphp/php-cs-fixer ###
13 changes: 5 additions & 8 deletions .php_cs.dist → .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<?php

return PhpCsFixer\Config::create()
return (new PhpCsFixer\Config())
->setRiskyAllowed(true)
->setRules([
'@PHP56Migration' => true,
'@PHPUnit60Migration:risky' => false,
'@Symfony' => true,
'@Symfony:risky' => false,
'align_multiline_comment' => true,
Expand All @@ -17,16 +15,15 @@
'compact_nullable_typehint' => true,
'final_class' => false,
'final_public_method_for_abstract_class' => false,
'final_static_access' => true,
'function_typehint_space' => true,
'heredoc_to_nowdoc' => true,
'is_null' => true,
'list_syntax' => ['syntax' => 'long'],
'method_argument_space' => ['ensure_fully_multiline' => true],
'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline'],
'native_function_type_declaration_casing' => true,
'no_extra_consecutive_blank_lines' => ['tokens' => ['break', 'continue', 'extra', 'return', 'throw', 'use', 'parenthesis_brace_block', 'square_brace_block', 'curly_brace_block']],
'no_extra_blank_lines' => ['tokens' => ['break', 'continue', 'extra', 'return', 'throw', 'use', 'parenthesis_brace_block', 'square_brace_block', 'curly_brace_block']],
'no_null_property_initialization' => true,
'no_short_echo_tag' => true,
'echo_tag_syntax' => ['format' => 'long'],
'no_superfluous_elseif' => true,
'no_superfluous_phpdoc_tags' => false,
'no_unneeded_curly_braces' => true,
Expand Down Expand Up @@ -57,7 +54,7 @@
'single_trait_insert_per_statement' => true,
'strict_comparison' => false,
'strict_param' => false,
'yoda_style' => null,
'yoda_style' => false,
])
->setFinder(
PhpCsFixer\Finder::create()
Expand Down
18 changes: 9 additions & 9 deletions Annotation/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@
*/
class Filter
{
const COMPARISON_EQUALS = 'eq';
public const COMPARISON_EQUALS = 'eq';

const COMPARISON_NOTEQUALS = 'neq';
public const COMPARISON_NOTEQUALS = 'neq';

const COMPARISON_GREATERTHAN = 'gt';
public const COMPARISON_GREATERTHAN = 'gt';

const COMPARISON_GREATERTHANEQUALS = 'gteq';
public const COMPARISON_GREATERTHANEQUALS = 'gteq';

const COMPARISON_LESSTHAN = 'lt';
public const COMPARISON_LESSTHAN = 'lt';

const COMPARISON_LESSTHANEQUALS = 'lteq';
public const COMPARISON_LESSTHANEQUALS = 'lteq';

const COMPARISON_IN = 'in';
public const COMPARISON_IN = 'in';

const COMPARISON_NOTIN = 'nin';
public const COMPARISON_NOTIN = 'nin';

const COMPARISON_LIKE = 'like';
public const COMPARISON_LIKE = 'like';

/**
* Specify the name of this filter.
Expand Down
4 changes: 2 additions & 2 deletions Annotation/Sort.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
*/
class Sort
{
const ASCENDING = 'asc';
public const ASCENDING = 'asc';

const DESCENDING = 'desc';
public const DESCENDING = 'desc';

/**
* Specify the name of this sort field.
Expand Down
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [2.1.0] - 2021-06-25

### Fixed

- Deprecation message with Symfony 5.3 where `getMasterRequest()` is renamed to `getMainRequest()`
- Fixed backwards compatible utilizing the RequestUtil which decides what method to call
- Changed some variable names accordingly

### Updated

- Upgrade to Symfony 5.3
- Updated php cs fixer 3.0

## [2.0.6] - 2021-05-20

### Changed
Expand Down
6 changes: 3 additions & 3 deletions EventListener/AnnotationListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class AnnotationListener
/**
* @var bool
*/
private $masterRequest = true;
private $mainRequest = true;

/**
* @var ApiService
Expand Down Expand Up @@ -60,10 +60,10 @@ public function __construct(Reader $reader, ApiService $apiService)
public function onKernelController(ControllerEvent $event): void
{
// Only parse annotations on original action
if (!$this->masterRequest) {
if (!$this->mainRequest) {
return;
}
$this->masterRequest = false;
$this->mainRequest = false;

$controller = $event->getController();

Expand Down
11 changes: 6 additions & 5 deletions Service/FilterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Shopping\ApiTKUrlBundle\Annotation as Api;
use Shopping\ApiTKUrlBundle\Exception\FilterException;
use Shopping\ApiTKUrlBundle\Input\FilterField;
use Shopping\ApiTKUrlBundle\Util\RequestUtil;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpKernel\Kernel;
Expand Down Expand Up @@ -170,12 +171,12 @@ private function getFilterByName(string $name): ?Api\Filter
*/
private function loadFiltersFromQuery(): void
{
$masterRequest = $this->requestStack->getMasterRequest() ?? Request::createFromGlobals();
$request = RequestUtil::getMainRequest($this->requestStack) ?? Request::createFromGlobals();

if (Kernel::VERSION_ID >= 50100) {
$requestFilters = $masterRequest->query->all('filter');
$requestFilters = $request->query->all('filter');
} else {
$requestFilters = $masterRequest->query->get('filter');
$requestFilters = $request->query->get('filter');
}

if (is_array($requestFilters)) {
Expand All @@ -198,8 +199,8 @@ private function loadFiltersFromQuery(): void
*/
private function loadFiltersFromAttributes(): void
{
$masterRequest = $this->requestStack->getMasterRequest() ?? Request::createFromGlobals();
foreach ($masterRequest->attributes->getIterator() as $key => $value) {
$request = RequestUtil::getMainRequest($this->requestStack) ?? Request::createFromGlobals();
foreach ($request->attributes->getIterator() as $key => $value) {
$key = (string) $key;
if ($this->getFilterByName($key) === null) {
continue;
Expand Down
5 changes: 3 additions & 2 deletions Service/PaginationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Shopping\ApiTKHeaderBundle\Service\HeaderInformation;
use Shopping\ApiTKUrlBundle\Annotation as Api;
use Shopping\ApiTKUrlBundle\Exception\PaginationException;
use Shopping\ApiTKUrlBundle\Util\RequestUtil;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;

Expand Down Expand Up @@ -103,15 +104,15 @@ public function applyPaginationToQueryBuilder(QueryBuilder $queryBuilder): void
*/
private function parsePagination(): void
{
$request = $this->requestStack->getMasterRequest() ?? Request::createFromGlobals();
$request = RequestUtil::getMainRequest($this->requestStack) ?? Request::createFromGlobals();
$parameter = $request->query->get('limit', null);

if ($parameter !== null) {
if ($this->pagination === null) {
throw new PaginationException('Limit parameter not available in current request.');
}

$parts = explode(',', $parameter);
$parts = explode(',', (string) $parameter);
if (count($parts) === 1) {
$this->paginationLimit = (int) $parts[0];
} elseif (count($parts) === 2) {
Expand Down
3 changes: 2 additions & 1 deletion Service/SortTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Shopping\ApiTKUrlBundle\Annotation as Api;
use Shopping\ApiTKUrlBundle\Exception\SortException;
use Shopping\ApiTKUrlBundle\Input\SortField;
use Shopping\ApiTKUrlBundle\Util\RequestUtil;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpKernel\Kernel;
Expand Down Expand Up @@ -111,7 +112,7 @@ private function loadSortsFromQuery(): void
{
$this->sortFields = [];

$request = $this->requestStack->getMasterRequest() ?? Request::createFromGlobals();
$request = RequestUtil::getMainRequest($this->requestStack) ?? Request::createFromGlobals();

if (Kernel::VERSION_ID >= 50100) {
$requestSorts = $request->query->all('sort');
Expand Down
28 changes: 28 additions & 0 deletions Util/RequestUtil.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Shopping\ApiTKUrlBundle\Util;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;

/**
* Class RequestUtil.
*
* @package Shopping\ApiTKUrlBundle\Util
*/
class RequestUtil
{
/**
* @param RequestStack $requestStack
*
* @return Request
*/
public static function getMainRequest(RequestStack $requestStack): ?Request
{
return method_exists($requestStack, 'getMainRequest')
? $requestStack->getMainRequest() // symfony >= 5.3
: $requestStack->getMasterRequest(); // symfony <= 5.2 @phpstan-ignore-line
}
}
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "check24/apitk-url-bundle",
"version": "2.0.6",
"version": "2.1.0",
"license": "MIT",
"type": "symfony-bundle",
"description": "This bundle provides filter, sorting and pagination for RESTful API's",
Expand Down Expand Up @@ -45,7 +45,7 @@
"captainhook/plugin-composer": "^5.1",
"doctrine/orm": "^2.6",
"doctrine/doctrine-bundle": ">=1.8 <3.0",
"friendsofphp/php-cs-fixer": "^2.13",
"friendsofphp/php-cs-fixer": "^3.0",
"phpmd/phpmd": "^2.6",
"phpstan/phpstan": "^0.12.0",
"phpstan/phpstan-deprecation-rules": "^0.12.5"
Expand Down
Loading

0 comments on commit 52e7763

Please sign in to comment.