-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor #730 Grid aware operation (loic425)
This PR was merged into the 1.11 branch. Discussion ---------- | Q | A | --------------- | ----- | Bug fix? | yes (kind of) | New feature? | no | BC breaks? | no (yes on 1.11 alpha only) | Deprecations? | no | Related tickets | | License | MIT Commits ------- e014bb2 Grid aware operation
- Loading branch information
Showing
22 changed files
with
220 additions
and
131 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
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,26 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Sylius Sp. z o.o. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Component\Resource\Metadata; | ||
|
||
/** | ||
* The Operation has a grid. | ||
* | ||
* @experimental | ||
*/ | ||
interface GridAwareOperationInterface | ||
{ | ||
public function getGrid(): ?string; | ||
|
||
public function withGrid(string $grid): self; | ||
} |
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
71 changes: 71 additions & 0 deletions
71
src/Component/Metadata/Resource/Factory/ProviderResourceMetadataCollectionFactory.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,71 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Sylius Sp. z o.o. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Component\Resource\Metadata\Resource\Factory; | ||
|
||
use Sylius\Component\Resource\Grid\State\RequestGridProvider; | ||
use Sylius\Component\Resource\Metadata\GridAwareOperationInterface; | ||
use Sylius\Component\Resource\Metadata\Operation; | ||
use Sylius\Component\Resource\Metadata\Operations; | ||
use Sylius\Component\Resource\Metadata\Resource as ResourceMetadata; | ||
use Sylius\Component\Resource\Metadata\Resource\ResourceMetadataCollection; | ||
use Sylius\Component\Resource\Symfony\Request\State\Provider; | ||
|
||
final class ProviderResourceMetadataCollectionFactory implements ResourceMetadataCollectionFactoryInterface | ||
{ | ||
public function __construct( | ||
private ResourceMetadataCollectionFactoryInterface $decorated, | ||
) { | ||
} | ||
|
||
public function create(string $resourceClass): ResourceMetadataCollection | ||
{ | ||
$resourceCollectionMetadata = $this->decorated->create($resourceClass); | ||
|
||
/** @var ResourceMetadata $resource */ | ||
foreach ($resourceCollectionMetadata->getIterator() as $i => $resource) { | ||
$operations = $resource->getOperations() ?? new Operations(); | ||
|
||
/** @var Operation $operation */ | ||
foreach ($operations as $operation) { | ||
/** @var string $key */ | ||
$key = $operation->getName(); | ||
|
||
$operations->add($key, $this->addDefaults($operation)); | ||
} | ||
|
||
$resource = $resource->withOperations($operations); | ||
|
||
$resourceCollectionMetadata[$i] = $resource; | ||
} | ||
|
||
return $resourceCollectionMetadata; | ||
} | ||
|
||
private function addDefaults(Operation $operation): Operation | ||
{ | ||
if ( | ||
null === $operation->getProvider() && | ||
$operation instanceof GridAwareOperationInterface && | ||
null !== $operation->getGrid() | ||
) { | ||
$operation = $operation->withProvider(RequestGridProvider::class); | ||
} | ||
|
||
if (null === $operation->getProvider()) { | ||
$operation = $operation->withProvider(Provider::class); | ||
} | ||
|
||
return $operation; | ||
} | ||
} |
Oops, something went wrong.