Skip to content

Instantly share code, notes, and snippets.

@Steveb-p
Created October 16, 2021 19:26
Show Gist options
  • Save Steveb-p/ec0c83e52dce844c01ced0e37847ff21 to your computer and use it in GitHub Desktop.
Save Steveb-p/ec0c83e52dce844c01ced0e37847ff21 to your computer and use it in GitHub Desktop.
<?php
declare(strict_types=1);
namespace Denkwerk\IbexaConnector\Core\Load\Actions\Location;
use Ibexa\Platform\Migration\ValueObject\Step\Action;
final class AssignContentLocations implements Action
{
public const TYPE = 'assign_content_locations';
/**
* @var bool|null
*/
private $value;
public function __construct(?bool $value = null)
{
$this->value = $value;
}
/**
* @return bool|null
*/
public function getValue()
{
return $this->value;
}
public function getSupportedType(): string
{
return self::TYPE;
}
}
<?php
declare(strict_types=1);
namespace Denkwerk\IbexaConnector\Core\Load\Actions\Location;
use Ibexa\Platform\Migration\ValueObject\Step\Action;
use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface;
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareTrait;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use Webmozart\Assert\Assert;
final class AssignContentLocationsActionDenormalizer implements DenormalizerInterface, CacheableSupportsMethodInterface
{
/**
* @var DenormalizerInterface
*/
protected $denormalizer;
/**
* @var array<string, class-string>
*/
private $map;
/**
* @param array<array{
* action: string,
* class: class-string,
* }> $supportedActions
*/
public function __construct(array $supportedActions)
{
$this->map = $this->mapSupportedActions($supportedActions);
dump( $this->map);
}
private function mapSupportedActions(array $supportedActions): array
{
return array_column($supportedActions, 'class', 'action');
}
public function denormalize($data, string $type, string $format = null, array $context = [])
{
dump($type);
dd($data);
Assert::keyExists($data, 'value');
return new AssignContentLocations($data['value']);
}
public function hasCacheableSupportsMethod(): bool
{
return true;
}
public function supportsDenormalization($data, string $type, string $format = null)
{
dump($type);
return Action::class === $type;
}
}
#Custom Excecutor to assign content to many locations
Denkwerk\IbexaConnector\Core\Load\Actions\Location\AssignContentLocationsExecutor:
autoconfigure: true
tags:
- { name: 'ibexa.migrations.executor.action.content', key: !php/const \Denkwerk\IbexaConnector\Core\Load\Actions\Location\AssignContentLocations::TYPE }
Denkwerk\IbexaConnector\Core\Load\Actions\Location\AssignContentLocationsActionDenormalizer:
arguments:
-
-
action: !php/const \Denkwerk\IbexaConnector\Core\Load\Actions\Location\AssignContentLocations::TYPE
class: Denkwerk\IbexaConnector\Core\Load\Actions\Location\AssignContentLocations
tags:
- { name: 'ibexa.migrations.serializer.normalizer', priority: 10 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment