Skip to content

Commit 0c284a5

Browse files
committed
Update from internal 0.19.0 changes
1 parent 4aad5a4 commit 0c284a5

21 files changed

+112
-43
lines changed

CHANGELOG.md

+35-1
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,46 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
66

77
## Unreleased
88

9+
## [0.19.0] 2021-03-25
10+
11+
### Added
12+
- Support for Doctrine common v3
13+
14+
### Changed
15+
- CI now uses the Symfony binary for `security:check` instead of the deprecated composer package
16+
- CI "latest" build now runs on PHP 7.4
17+
18+
### Fixed
19+
- Compliance with newer version of php cs fixer
20+
21+
## [0.18.0] 2020-12-09
22+
23+
### Added
24+
- Support for multi-level filters
25+
26+
### Changed
27+
- CI removes created images & volumes when finished
28+
29+
## [0.17.7] 2020-02-14
30+
31+
### Added
32+
- Support for Doctrine bundle v2
33+
34+
### Fixed
35+
- Specified includes now get properly included on create requests
36+
- Headers argument being unintentionally cleared in when creating response
37+
38+
## [0.17.6] 2020-01-21
39+
40+
### Added
41+
- Support for empty data attribute to `ResponseBodyDecoder`
42+
943
### Changed
1044
- Form validation errors now generate pointers from cause instead of origin
1145

1246
### Fixed
1347
- Form validation errors pointers now correctly target deep properties
14-
- Specified includes now get properly included on create requests
48+
- Failing tests in newer PHPUnit bridge version
1549

1650
## [0.17.5] 2019-11-15
1751

composer.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"symfony/monolog-bundle": "^3.4",
1818
"neomerx/json-api": "^1.0",
1919
"doctrine/orm": "^2.4",
20-
"doctrine/common": "^2",
20+
"doctrine/common": "^2|^3",
2121
"doctrine/doctrine-bundle": "^1.11|^2.0",
2222
"ext-json": "*",
2323
"symfony/property-access": "^3.4|^4.4"
@@ -29,7 +29,6 @@
2929
"justinrainbow/json-schema": "^1.6",
3030
"doctrine/doctrine-fixtures-bundle": "^3.3",
3131
"fzaninotto/faker": "^1.5",
32-
"sensiolabs/security-checker": "^5",
3332
"symfony/twig-bundle": "^3.4|^4.4",
3433
"doctrine/cache": "^1.6",
3534
"symfony/debug-bundle": "^3.4|^4.4",

src/CompilerPass/SchemaAutoMapCompilerPass.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -113,43 +113,43 @@ private function getClassFQNFromFileName($file): string
113113
$class = false;
114114
$namespace = false;
115115
$tokens = token_get_all(file_get_contents($file));
116-
if (1 === \count($tokens) && T_INLINE_HTML === $tokens[0][0]) {
116+
if (1 === \count($tokens) && \T_INLINE_HTML === $tokens[0][0]) {
117117
return false;
118118
}
119119
for ($i = 0; isset($tokens[$i]); ++$i) {
120120
$token = $tokens[$i];
121121
if (!isset($token[1])) {
122122
continue;
123123
}
124-
if (true === $class && T_STRING === $token[0]) {
124+
if (true === $class && \T_STRING === $token[0]) {
125125
return $namespace . '\\' . $token[1];
126126
}
127-
if (true === $namespace && T_STRING === $token[0]) {
127+
if (true === $namespace && \T_STRING === $token[0]) {
128128
$namespace = $token[1];
129-
while (isset($tokens[++$i][1]) && \in_array($tokens[$i][0], [T_NS_SEPARATOR, T_STRING])) {
129+
while (isset($tokens[++$i][1]) && \in_array($tokens[$i][0], [\T_NS_SEPARATOR, \T_STRING])) {
130130
$namespace .= $tokens[$i][1];
131131
}
132132
$token = $tokens[$i];
133133
}
134-
if (T_CLASS === $token[0]) {
134+
if (\T_CLASS === $token[0]) {
135135
// Skip usage of ::class constant and anonymous classes
136136
$skipClassToken = false;
137137
for ($j = $i - 1; $j > 0; --$j) {
138138
if (!isset($tokens[$j][1])) {
139139
break;
140140
}
141-
if (T_DOUBLE_COLON === $tokens[$j][0] || T_NEW === $tokens[$j][0]) {
141+
if (\T_DOUBLE_COLON === $tokens[$j][0] || \T_NEW === $tokens[$j][0]) {
142142
$skipClassToken = true;
143143
break;
144-
} elseif (!\in_array($tokens[$j][0], [T_WHITESPACE, T_DOC_COMMENT, T_COMMENT])) {
144+
} elseif (!\in_array($tokens[$j][0], [\T_WHITESPACE, \T_DOC_COMMENT, \T_COMMENT])) {
145145
break;
146146
}
147147
}
148148
if (!$skipClassToken) {
149149
$class = true;
150150
}
151151
}
152-
if (T_NAMESPACE === $token[0]) {
152+
if (\T_NAMESPACE === $token[0]) {
153153
$namespace = true;
154154
}
155155
}

src/Listener/KernelListener.php

-5
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,10 @@ private function getResponseFromControllerResult($controllerResult, array $resul
157157
switch (true) {
158158
// if you have response from controller, check if it is valid
159159
case $controllerResult instanceof Response:
160-
161160
// TODO - this should never happen here? Response is called in kernelResponse
162161

163162
break;
164163
case $controllerResult instanceof DataResponse:
165-
166164
$resultMeta = array_merge($resultMeta, $controllerResult->getMeta());
167165
$resultLinks = array_merge($resultLinks, $controllerResult->getLinks());
168166

@@ -194,7 +192,6 @@ private function getResponseFromControllerResult($controllerResult, array $resul
194192

195193
// if we got our collection encode it and package it in response
196194
case $controllerResult instanceof ObjectListCollectionInterface:
197-
198195
// append total from collection
199196
$resultMeta['total'] = $controllerResult->getTotal();
200197

@@ -210,7 +207,6 @@ private function getResponseFromControllerResult($controllerResult, array $resul
210207

211208
// if you got array or object, try to encode it and package in response
212209
case \is_array($controllerResult) || \is_object($controllerResult):
213-
214210
$response = $this->responseFactory->createResponse($this->encode($controllerResult, $resultMeta,
215211
$resultLinks));
216212

@@ -220,7 +216,6 @@ private function getResponseFromControllerResult($controllerResult, array $resul
220216

221217
// no content response?
222218
case null === $controllerResult:
223-
224219
$response = $this->responseFactory->createNoContent();
225220

226221
return $response;

src/Resources/doc/getting_started/examples/ExampleController.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
*/
2222
class ExampleController extends JsonApiController
2323
{
24+
use CreateActionTrait;
25+
use DeleteActionTrait;
2426
use IndexActionTrait;
2527
use ShowActionTrait;
26-
use CreateActionTrait;
2728
use UpdateActionTrait;
28-
use DeleteActionTrait;
2929
use UpdateRelationshipActionTrait;
3030
}

src/Services/ModelInput/AbstractFormModelInputHandler.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
namespace Trikoder\JsonApiBundle\Services\ModelInput;
44

5-
use Doctrine\Common\Persistence\Proxy;
5+
use Doctrine\Common\Persistence\Proxy as LegacyProxy;
6+
use Doctrine\Persistence\Proxy;
67
use Symfony\Component\Form\Extension\Validator\Constraints\Form;
78
use Symfony\Component\Form\FormErrorIterator;
89
use Symfony\Component\Form\FormInterface;
@@ -46,7 +47,7 @@ public function forModel($model)
4647
$this->model = $model;
4748

4849
// make sure we are not working with doctrine proxy
49-
if ($this->model instanceof Proxy) {
50+
if ($this->model instanceof Proxy || $this->model instanceof LegacyProxy) {
5051
$this->modelClass = get_parent_class($this->model);
5152
} else {
5253
$this->modelClass = \get_class($this->model);

src/Services/ModelInput/DoctrineModelMetaData.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,21 @@
44

55
namespace Trikoder\JsonApiBundle\Services\ModelInput;
66

7-
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
7+
use Doctrine\Common\Persistence\Mapping\ClassMetadata as LegacyClassMetadata;
8+
use Doctrine\Persistence\Mapping\ClassMetadata;
89
use Trikoder\JsonApiBundle\Contracts\ModelTools\ModelMetaDataInterface;
910

1011
final class DoctrineModelMetaData implements ModelMetaDataInterface
1112
{
1213
/**
13-
* @var ClassMetadata
14+
* @var ClassMetadata|LegacyClassMetadata
1415
*/
1516
private $classMetaData;
1617

17-
public function __construct(ClassMetadata $classMetaData)
18+
/**
19+
* @param ClassMetadata|LegacyClassMetadata $classMetaData
20+
*/
21+
public function __construct($classMetaData)
1822
{
1923
$this->classMetaData = $classMetaData;
2024
}

src/Services/ModelInput/ModelMetaDataFactory.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,21 @@
44

55
namespace Trikoder\JsonApiBundle\Services\ModelInput;
66

7-
use Doctrine\Common\Persistence\ObjectManager;
7+
use Doctrine\Common\Persistence\ObjectManager as LegacyObjectManager;
8+
use Doctrine\Persistence\ObjectManager;
89
use Trikoder\JsonApiBundle\Contracts\ModelTools\ModelMetaDataInterface;
910

1011
final class ModelMetaDataFactory
1112
{
1213
/**
13-
* @var ObjectManager
14+
* @var ObjectManager|LegacyObjectManager
1415
*/
1516
private $objectManager;
1617

17-
public function __construct(ObjectManager $objectManager)
18+
/**
19+
* @param ObjectManager|LegacyObjectManager $objectManager
20+
*/
21+
public function __construct($objectManager)
1822
{
1923
$this->objectManager = $objectManager;
2024
}

src/Services/Neomerx/Container.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
namespace Trikoder\JsonApiBundle\Services\Neomerx;
44

5-
use Doctrine\Common\Persistence\Proxy;
5+
use Doctrine\Common\Persistence\Proxy as LegacyProxy;
6+
use Doctrine\Persistence\Proxy;
67
use InvalidArgumentException;
78
use Neomerx\JsonApi\Contracts\Schema\SchemaFactoryInterface;
89
use Neomerx\JsonApi\Contracts\Schema\SchemaProviderInterface;
@@ -43,7 +44,7 @@ public function __construct(
4344
*/
4445
protected function getResourceType($resource)
4546
{
46-
if ($resource instanceof Proxy) {
47+
if ($resource instanceof Proxy || $resource instanceof LegacyProxy) {
4748
return get_parent_class($resource);
4849
}
4950

src/Services/Neomerx/EncoderService.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ private function buildEncoderOptions()
112112
{
113113
$options = 0;
114114
if (true === $this->configurationEncodingPrettyPrint) {
115-
$options += JSON_PRETTY_PRINT;
115+
$options += \JSON_PRETTY_PRINT;
116116
}
117117
$this->encoderOptions = new EncoderOptions($options, '');
118118
}

tests/Integration/ExtensionTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function testKernelEventListenerEventPriorities()
3333
-10,
3434
$eventDispatcher->getListenerPriority(
3535
KernelEvents::CONTROLLER_ARGUMENTS,
36-
[$listener, 'onKernelControllerarguments']
36+
[$listener, 'onKernelControllerArguments']
3737
)
3838
);
3939

tests/Resources/Controller/Api/Test/VersionedUserController.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
*/
2323
class VersionedUserController extends JsonApiController
2424
{
25+
use CreateActionTrait;
26+
use DeleteActionTrait;
2527
use IndexActionTrait;
2628
use ShowActionTrait;
27-
use CreateActionTrait;
2829
use UpdateActionTrait;
29-
use DeleteActionTrait;
3030
}

tests/Resources/Controller/Api/User/ConfigRestrictionsUserController.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
*/
3131
class ConfigRestrictionsUserController extends JsonApiController
3232
{
33-
use IndexActionTrait;
3433
use CreateActionTrait;
35-
use UpdateActionTrait;
34+
use IndexActionTrait;
3635
use ShowActionTrait;
36+
use UpdateActionTrait;
3737
}

tests/Resources/Controller/Api/User/PostController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
*/
2020
class PostController extends JsonApiController
2121
{
22+
use CreateActionTrait;
2223
use IndexActionTrait;
2324
use ShowActionTrait;
24-
use CreateActionTrait;
2525
use UpdateActionTrait;
2626
}

tests/Resources/Controller/Api/User/ProductController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
*/
2020
class ProductController extends JsonApiController
2121
{
22+
use CreateActionTrait;
2223
use IndexActionTrait;
2324
use ShowActionTrait;
24-
use CreateActionTrait;
2525
use UpdateActionTrait;
2626
}

tests/Resources/Controller/Api/User/UserController.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
*/
2929
class UserController extends JsonApiController
3030
{
31+
use CreateActionTrait;
32+
use DeleteActionTrait;
3133
use IndexActionTrait;
3234
use ShowActionTrait;
33-
use CreateActionTrait;
3435
use UpdateActionTrait;
35-
use DeleteActionTrait;
3636
use UpdateRelationshipActionTrait;
3737
}

tests/Resources/app/AppKernel.php

+10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
use Doctrine\Common\Persistence\ObjectManager as LegacyObjectManager;
4+
use Doctrine\Persistence\ObjectManager;
35
use Symfony\Component\Config\Loader\LoaderInterface;
46
use Symfony\Component\HttpKernel\Kernel;
57

@@ -38,4 +40,12 @@ public function registerContainerConfiguration(LoaderInterface $loader)
3840
{
3941
$loader->load(__DIR__ . '/config/config.yml');
4042
}
43+
44+
public function boot()
45+
{
46+
if (!$this->booted && !interface_exists(LegacyObjectManager::class)) {
47+
class_alias(ObjectManager::class, LegacyObjectManager::class);
48+
}
49+
parent::boot();
50+
}
4151
}

tests/Resources/docker/bin/test.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ docker-compose run --no-deps --rm php rm -rf tests/Resources/app/cache/test/* va
66

77
docker-compose run --no-deps --rm php vendor/bin/phpunit --debug --coverage-text=php://stdout --coverage-html=logs/coverage
88

9-
docker-compose run --no-deps --rm php php vendor/bin/security-checker security:check composer.lock
9+
docker-compose run --no-deps --rm php symfony security:check

tests/Resources/docker/docker-compose.yml

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ services:
66
build:
77
context: php
88
dockerfile: Dockerfile
9+
args:
10+
PHP_VERSION_MAJOR: ${PHP_VERSION_MAJOR:-7}
11+
PHP_VERSION_MINOR: ${PHP_VERSION_MINOR:-2}
912
volumes:
1013
- ../../../:/usr/src/bundle #mount bundle root
1114
links:

0 commit comments

Comments
 (0)