-
-
Notifications
You must be signed in to change notification settings - Fork 892
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add a second hook for resource to entity or document transforma…
…tion
- Loading branch information
Showing
12 changed files
with
132 additions
and
84 deletions.
There are no files selected for viewing
43 changes: 0 additions & 43 deletions
43
src/Doctrine/Common/State/ModelTransformerLocatorTrait.php
This file was deleted.
Oops, something went wrong.
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
61 changes: 61 additions & 0 deletions
61
src/Doctrine/Common/State/ResourceTransformerLocatorTrait.php
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,61 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <[email protected]> | ||
* | ||
* 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\Doctrine\Common\State; | ||
|
||
use ApiPlatform\Metadata\Operation; | ||
use Psr\Container\ContainerInterface; | ||
|
||
/** | ||
* Maybe merge this and LinksHandlerLocatorTrait into a OptionsHooksLocatorTrait or something similar? | ||
*/ | ||
trait ResourceTransformerLocatorTrait | ||
{ | ||
private ?ContainerInterface $resourceTransformerLocator; | ||
|
||
protected function getToResourceTransformer(Operation $operation): ?callable | ||
{ | ||
if (!($options = $operation->getStateOptions()) || !$options instanceof Options) { | ||
return null; | ||
} | ||
|
||
$transformer = $options->getToResourceTransformer(); | ||
if (\is_callable($transformer)) { | ||
return $transformer; | ||
} | ||
|
||
if ($this->resourceTransformerLocator && \is_string($transformer) && $this->resourceTransformerLocator->has($transformer)) { | ||
return [$this->resourceTransformerLocator->get($transformer), 'toResource']; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
protected function getFromResourceTransformer(Operation $operation): ?callable | ||
{ | ||
if (!($options = $operation->getStateOptions()) || !$options instanceof Options) { | ||
return null; | ||
} | ||
|
||
$transformer = $options->getFromResourceTransformer(); | ||
if (\is_callable($transformer)) { | ||
return $transformer; | ||
} | ||
|
||
if ($this->resourceTransformerLocator && \is_string($transformer) && $this->resourceTransformerLocator->has($transformer)) { | ||
return [$this->resourceTransformerLocator->get($transformer), 'fromResource']; | ||
} | ||
|
||
return null; | ||
} | ||
} |
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
Oops, something went wrong.