Skip to content

Commit

Permalink
Merge branch '2.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
dunglas committed Aug 28, 2019
2 parents b6ddb27 + 4373de6 commit 6e9ccf7
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 15 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,7 @@

## 2.5.0 beta 1

* GraphQL: **BC Break** Separate `item_query` and `collection_query` operations so user can use different security and serialization groups for them
* GraphQL: Add support for custom queries and mutations
* GraphQL: Add support for custom types
* GraphQL: Better pagination support (backwards pagination)
Expand All @@ -12,8 +13,10 @@
* GraphQL: Allow to use a search and an exist filter on the same resource
* GraphQL: Refactor the architecture of the whole system to allow the decoration of useful services (`TypeConverter` to manage custom types, `SerializerContextBuilder` to modify the (de)serialization context dynamically, etc.)

**BC Break**
* GraphQL: Separate item_query and collection_query operations so user can use different security and serialization groups for them
## 2.4.7

* Fix passing context to data persisters' `remove` method
* Doctrine: ensure that `EntityManagerInterface` is used in data providers

## 2.4.6

Expand Down
2 changes: 1 addition & 1 deletion src/Action/ExceptionAction.php
Expand Up @@ -57,7 +57,7 @@ public function __construct(SerializerInterface $serializer, array $errorFormats
}

/**
* Converts a an exception to a JSON response.
* Converts an exception to a JSON response.
*/
public function __invoke(FlattenException $exception, Request $request): Response
{
Expand Down
3 changes: 2 additions & 1 deletion src/Bridge/Doctrine/Orm/CollectionDataProvider.php
Expand Up @@ -21,6 +21,7 @@
use ApiPlatform\Core\Exception\RuntimeException;
use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\EntityManagerInterface;

/**
* Collection data provider for the Doctrine ORM.
Expand All @@ -45,7 +46,7 @@ public function __construct(ManagerRegistry $managerRegistry, iterable $collecti

public function supports(string $resourceClass, string $operationName = null, array $context = []): bool
{
return null !== $this->managerRegistry->getManagerForClass($resourceClass);
return $this->managerRegistry->getManagerForClass($resourceClass) instanceof EntityManagerInterface;
}

/**
Expand Down
7 changes: 3 additions & 4 deletions src/Bridge/Doctrine/Orm/ItemDataProvider.php
Expand Up @@ -25,7 +25,6 @@
use ApiPlatform\Core\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface;
use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\QueryBuilder;

Expand Down Expand Up @@ -56,7 +55,7 @@ public function __construct(ManagerRegistry $managerRegistry, PropertyNameCollec

public function supports(string $resourceClass, string $operationName = null, array $context = []): bool
{
return null !== $this->managerRegistry->getManagerForClass($resourceClass);
return $this->managerRegistry->getManagerForClass($resourceClass) instanceof EntityManagerInterface;
}

/**
Expand All @@ -68,7 +67,7 @@ public function supports(string $resourceClass, string $operationName = null, ar
*/
public function getItem(string $resourceClass, $id, string $operationName = null, array $context = [])
{
/** @var ObjectManager $manager */
/** @var EntityManagerInterface $manager */
$manager = $this->managerRegistry->getManagerForClass($resourceClass);

if ((\is_int($id) || \is_string($id)) && !($context[IdentifierConverterInterface::HAS_IDENTIFIER_CONVERTER] ?? false)) {
Expand All @@ -83,7 +82,7 @@ public function getItem(string $resourceClass, $id, string $operationName = null
$identifiers = $id;

$fetchData = $context['fetch_data'] ?? true;
if (!$fetchData && $manager instanceof EntityManagerInterface) {
if (!$fetchData) {
return $manager->getReference($resourceClass, $identifiers);
}

Expand Down
6 changes: 3 additions & 3 deletions src/DataTransformer/DataTransformerInterface.php
Expand Up @@ -31,9 +31,9 @@ interface DataTransformerInterface
public function transform($object, string $to, array $context = []);

/**
* Checks whether the transformation is supported for a given object and context.
* Checks whether the transformation is supported for a given data and context.
*
* @param object $object
* @param object|array $data object on normalize / array on denormalize
*/
public function supportsTransformation($object, string $to, array $context = []): bool;
public function supportsTransformation($data, string $to, array $context = []): bool;
}
2 changes: 1 addition & 1 deletion src/EventListener/WriteListener.php
Expand Up @@ -106,7 +106,7 @@ public function onKernelView(GetResponseForControllerResultEvent $event): void

break;
case 'DELETE':
$this->dataPersister->remove($controllerResult);
$this->dataPersister->remove($controllerResult, $attributes);
$event->setControllerResult(null);
break;
}
Expand Down
6 changes: 4 additions & 2 deletions src/Serializer/AbstractItemNormalizer.php
Expand Up @@ -605,11 +605,13 @@ protected function normalizeRelation(PropertyMetadata $propertyMetadata, $relate

/**
* Finds the first supported data transformer if any.
*
* @param object|array $data object on normalize / array on denormalize
*/
protected function getDataTransformer($object, string $to, array $context = []): ?DataTransformerInterface
protected function getDataTransformer($data, string $to, array $context = []): ?DataTransformerInterface
{
foreach ($this->dataTransformers as $dataTransformer) {
if ($dataTransformer->supportsTransformation($object, $to, $context)) {
if ($dataTransformer->supportsTransformation($data, $to, $context)) {
return $dataTransformer;
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/EventListener/WriteListenerTest.php
Expand Up @@ -172,7 +172,7 @@ public function testOnKernelViewWithControllerResultAndRemove()

$dataPersisterProphecy = $this->prophesize(DataPersisterInterface::class);
$dataPersisterProphecy->supports($dummy, Argument::type('array'))->willReturn(true)->shouldBeCalled();
$dataPersisterProphecy->remove($dummy)->shouldBeCalled();
$dataPersisterProphecy->remove($dummy, Argument::type('array'))->shouldBeCalled();

$iriConverterProphecy = $this->prophesize(IriConverterInterface::class);
$iriConverterProphecy->getIriFromItem($dummy)->shouldNotBeCalled();
Expand Down

0 comments on commit 6e9ccf7

Please sign in to comment.