-
-
Notifications
You must be signed in to change notification settings - Fork 893
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(serializer): child definition context creation
Also fixes the item_uri_template usage * fix(symfony): fix Symfony IriConverter with item_uri_template Co-authored-by: soyuka <soyuka@users.noreply.github.com>
- Loading branch information
1 parent
07c9989
commit e3e6a0d
Showing
15 changed files
with
302 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <dunglas@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ApiPlatform\Serializer; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
trait OperationContextTrait | ||
{ | ||
/** | ||
* This context is created when working on a relation context or items of a collection. It cleans the previously given | ||
* context as the operation changes. | ||
*/ | ||
protected function createOperationContext(array $context, string $resourceClass = null): array | ||
{ | ||
if (isset($context['operation']) && !isset($context['root_operation'])) { | ||
$context['root_operation'] = $context['operation']; | ||
} | ||
|
||
if (isset($context['operation_name']) || isset($context['graphql_operation_name'])) { | ||
$context['root_operation_name'] = $context['operation_name'] ?? $context['graphql_operation_name']; | ||
} | ||
|
||
unset($context['iri'], $context['uri_variables'], $context['item_uri_template'], $context['force_resource_class']); | ||
|
||
if (!$resourceClass) { | ||
return $context; | ||
} | ||
|
||
if (($operation = $context['operation'] ?? null) && method_exists($operation, 'getItemUriTemplate')) { | ||
$context['item_uri_template'] = $operation->getItemUriTemplate(); | ||
} | ||
|
||
unset($context['operation'], $context['operation_name']); | ||
$context['resource_class'] = $resourceClass; | ||
|
||
return $context; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.