Skip to content

Commit a84e3f1

Browse files
authored
Merge branch 'master' into master
2 parents 78d0c9f + 480c077 commit a84e3f1

32 files changed

+758
-141
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 0 additions & 13 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 2.6.0
4+
5+
* MongoDB: Possibility to add execute options (aggregate command fields) for a resource, like `allowDiskUse` (#3144)
6+
37
## 2.5.0
48

59
* Fix BC-break when using short-syntax notation for `access_control`

CONTRIBUTING.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@ Then, if it appears that it's a real bug, you may report it using GitHub by foll
1818

1919
> _NOTE:_ Don't hesitate giving as much information as you can (OS, PHP version extensions...)
2020
21-
### Security Issues
22-
23-
If you find a security issue, send a mail to Kévin Dunglas <dunglas@gmail.com>. **Please do not report security problems
24-
publicly**. We will disclose details of the issue and credit you after having released a new version including a fix.
25-
2621
## Pull Requests
2722

2823
### Writing a Pull Request

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
},
127127
"extra": {
128128
"branch-alias": {
129-
"dev-master": "2.5.x-dev"
129+
"dev-master": "2.6.x-dev"
130130
}
131131
}
132132
}

features/bootstrap/JsonApiContext.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,26 @@ public function theJsonNodeShouldNotBeAnEmptyString($node)
107107
}
108108
}
109109

110+
/**
111+
* @Then the JSON node :node should be sorted
112+
* @Then the JSON should be sorted
113+
*/
114+
public function theJsonNodeShouldBeSorted($node = '')
115+
{
116+
$actual = (array) $this->getValueOfNode($node);
117+
118+
if (!is_array($actual)) {
119+
throw new \Exception(sprintf('The "%s" node value is not an array', $node));
120+
}
121+
122+
$expected = $actual;
123+
ksort($expected);
124+
125+
if ($actual !== $expected) {
126+
throw new ExpectationFailedException(sprintf('The json node "%s" is not sorted by keys', $node));
127+
}
128+
}
129+
110130
/**
111131
* @Given there is a RelatedDummy
112132
*/

features/hydra/entrypoint.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Feature: Entrypoint support
88
Then the response status code should be 200
99
And the response should be in JSON
1010
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
11+
And the JSON should be sorted
1112
And the JSON node "@context" should be equal to "/contexts/Entrypoint"
1213
And the JSON node "@id" should be equal to "/"
1314
And the JSON node "@type" should be equal to "Entrypoint"

src/Annotation/ApiResource.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,6 @@ final class ApiResource
123123
];
124124

125125
/**
126-
* @see https://api-platform.com/docs/core/operations
127-
*
128126
* @var array
129127
*/
130128
public $collectionOperations;

src/Bridge/Doctrine/MongoDbOdm/CollectionDataProvider.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use ApiPlatform\Core\DataProvider\CollectionDataProviderInterface;
1919
use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface;
2020
use ApiPlatform\Core\Exception\RuntimeException;
21+
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface;
2122
use Doctrine\Common\Persistence\ManagerRegistry;
2223
use Doctrine\ODM\MongoDB\DocumentManager;
2324
use Doctrine\ODM\MongoDB\Repository\DocumentRepository;
@@ -32,14 +33,16 @@
3233
final class CollectionDataProvider implements CollectionDataProviderInterface, RestrictedDataProviderInterface
3334
{
3435
private $managerRegistry;
36+
private $resourceMetadataFactory;
3537
private $collectionExtensions;
3638

3739
/**
3840
* @param AggregationCollectionExtensionInterface[] $collectionExtensions
3941
*/
40-
public function __construct(ManagerRegistry $managerRegistry, iterable $collectionExtensions = [])
42+
public function __construct(ManagerRegistry $managerRegistry, ResourceMetadataFactoryInterface $resourceMetadataFactory, iterable $collectionExtensions = [])
4143
{
4244
$this->managerRegistry = $managerRegistry;
45+
$this->resourceMetadataFactory = $resourceMetadataFactory;
4346
$this->collectionExtensions = $collectionExtensions;
4447
}
4548

@@ -72,6 +75,10 @@ public function getCollection(string $resourceClass, string $operationName = nul
7275
}
7376
}
7477

75-
return $aggregationBuilder->hydrate($resourceClass)->execute();
78+
$resourceMetadata = $this->resourceMetadataFactory->create($resourceClass);
79+
$attribute = $resourceMetadata->getCollectionOperationAttribute($operationName, 'doctrine_mongodb', [], true);
80+
$executeOptions = $attribute['execute_options'] ?? [];
81+
82+
return $aggregationBuilder->hydrate($resourceClass)->execute($executeOptions);
7683
}
7784
}

src/Bridge/Doctrine/MongoDbOdm/Extension/PaginationExtension.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use ApiPlatform\Core\Bridge\Doctrine\MongoDbOdm\Paginator;
1717
use ApiPlatform\Core\DataProvider\Pagination;
1818
use ApiPlatform\Core\Exception\RuntimeException;
19+
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface;
1920
use Doctrine\Common\Persistence\ManagerRegistry;
2021
use Doctrine\ODM\MongoDB\Aggregation\Builder;
2122
use Doctrine\ODM\MongoDB\DocumentManager;
@@ -33,11 +34,13 @@
3334
final class PaginationExtension implements AggregationResultCollectionExtensionInterface
3435
{
3536
private $managerRegistry;
37+
private $resourceMetadataFactory;
3638
private $pagination;
3739

38-
public function __construct(ManagerRegistry $managerRegistry, Pagination $pagination)
40+
public function __construct(ManagerRegistry $managerRegistry, ResourceMetadataFactoryInterface $resourceMetadataFactory, Pagination $pagination)
3941
{
4042
$this->managerRegistry = $managerRegistry;
43+
$this->resourceMetadataFactory = $resourceMetadataFactory;
4144
$this->pagination = $pagination;
4245
}
4346

@@ -113,7 +116,11 @@ public function getResult(Builder $aggregationBuilder, string $resourceClass, st
113116
throw new RuntimeException(sprintf('The manager for "%s" must be an instance of "%s".', $resourceClass, DocumentManager::class));
114117
}
115118

116-
return new Paginator($aggregationBuilder->execute(), $manager->getUnitOfWork(), $resourceClass, $aggregationBuilder->getPipeline());
119+
$resourceMetadata = $this->resourceMetadataFactory->create($resourceClass);
120+
$attribute = $resourceMetadata->getCollectionOperationAttribute($operationName, 'doctrine_mongodb', [], true);
121+
$executeOptions = $attribute['execute_options'] ?? [];
122+
123+
return new Paginator($aggregationBuilder->execute($executeOptions), $manager->getUnitOfWork(), $resourceClass, $aggregationBuilder->getPipeline());
117124
}
118125

119126
private function addCountToContext(Builder $aggregationBuilder, array $context): array

src/Bridge/Doctrine/MongoDbOdm/ItemDataProvider.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use ApiPlatform\Core\Identifier\IdentifierConverterInterface;
2323
use ApiPlatform\Core\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
2424
use ApiPlatform\Core\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface;
25+
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface;
2526
use Doctrine\Common\Persistence\ManagerRegistry;
2627
use Doctrine\ODM\MongoDB\DocumentManager;
2728
use Doctrine\ODM\MongoDB\Repository\DocumentRepository;
@@ -38,14 +39,16 @@ final class ItemDataProvider implements DenormalizedIdentifiersAwareItemDataProv
3839
use IdentifierManagerTrait;
3940

4041
private $managerRegistry;
42+
private $resourceMetadataFactory;
4143
private $itemExtensions;
4244

4345
/**
4446
* @param AggregationItemExtensionInterface[] $itemExtensions
4547
*/
46-
public function __construct(ManagerRegistry $managerRegistry, PropertyNameCollectionFactoryInterface $propertyNameCollectionFactory, PropertyMetadataFactoryInterface $propertyMetadataFactory, iterable $itemExtensions = [])
48+
public function __construct(ManagerRegistry $managerRegistry, ResourceMetadataFactoryInterface $resourceMetadataFactory, PropertyNameCollectionFactoryInterface $propertyNameCollectionFactory, PropertyMetadataFactoryInterface $propertyMetadataFactory, iterable $itemExtensions = [])
4749
{
4850
$this->managerRegistry = $managerRegistry;
51+
$this->resourceMetadataFactory = $resourceMetadataFactory;
4952
$this->propertyNameCollectionFactory = $propertyNameCollectionFactory;
5053
$this->propertyMetadataFactory = $propertyMetadataFactory;
5154
$this->itemExtensions = $itemExtensions;
@@ -95,6 +98,10 @@ public function getItem(string $resourceClass, $id, string $operationName = null
9598
}
9699
}
97100

98-
return $aggregationBuilder->hydrate($resourceClass)->execute()->current() ?: null;
101+
$resourceMetadata = $this->resourceMetadataFactory->create($resourceClass);
102+
$attribute = $resourceMetadata->getItemOperationAttribute($operationName, 'doctrine_mongodb', [], true);
103+
$executeOptions = $attribute['execute_options'] ?? [];
104+
105+
return $aggregationBuilder->hydrate($resourceClass)->execute($executeOptions)->current() ?: null;
99106
}
100107
}

0 commit comments

Comments
 (0)