| @@ 13-75 (lines=63) @@ | ||
| 10 | use Actualys\Bundle\DrupalCommerceConnectorBundle\Normalizer\AttributeNormalizer; |
|
| 11 | use Actualys\Bundle\DrupalCommerceConnectorBundle\Item\DrupalItemStep; |
|
| 12 | ||
| 13 | class AttributeProcessor extends DrupalItemStep implements ItemProcessorInterface |
|
| 14 | { |
|
| 15 | /** |
|
| 16 | * @var AttributeNormalizer $attributeNormalizer |
|
| 17 | */ |
|
| 18 | protected $attributeNormalizer; |
|
| 19 | ||
| 20 | /** |
|
| 21 | * @var array |
|
| 22 | */ |
|
| 23 | protected $globalContext = array(); |
|
| 24 | ||
| 25 | /** |
|
| 26 | * @param AttributeNormalizer $attributeNormalizer The entity manager |
|
| 27 | */ |
|
| 28 | public function __construct(AttributeNormalizer $attributeNormalizer) |
|
| 29 | { |
|
| 30 | $this->attributeNormalizer = $attributeNormalizer; |
|
| 31 | } |
|
| 32 | ||
| 33 | /** |
|
| 34 | * @param mixed $attribute |
|
| 35 | * @return array|mixed |
|
| 36 | * @throws InvalidItemException |
|
| 37 | */ |
|
| 38 | public function process($attribute) |
|
| 39 | { |
|
| 40 | return $this->normalizeAttribute($attribute, $this->globalContext); |
|
| 41 | } |
|
| 42 | ||
| 43 | /** |
|
| 44 | * @param Attribute $attribute |
|
| 45 | * @param array $context |
|
| 46 | * @return array |
|
| 47 | * @throws InvalidItemException |
|
| 48 | */ |
|
| 49 | protected function normalizeAttribute(Attribute $attribute, array $context) |
|
| 50 | { |
|
| 51 | try { |
|
| 52 | $processedItem = $this->attributeNormalizer->normalize( |
|
| 53 | $attribute, |
|
| 54 | $context |
|
| 55 | ); |
|
| 56 | } catch (NormalizeException $e) { |
|
| 57 | throw new InvalidItemException($e->getMessage(), [$attribute]); |
|
| 58 | } |
|
| 59 | ||
| 60 | return $processedItem; |
|
| 61 | } |
|
| 62 | ||
| 63 | public function getConfigurationFields() |
|
| 64 | { |
|
| 65 | return parent::getConfigurationFields(); |
|
| 66 | } |
|
| 67 | ||
| 68 | /** |
|
| 69 | * @param StepExecution $stepExecution |
|
| 70 | */ |
|
| 71 | public function setStepExecution(StepExecution $stepExecution) |
|
| 72 | { |
|
| 73 | $this->stepExecution = $stepExecution; |
|
| 74 | } |
|
| 75 | } |
|
| 76 | ||
| @@ 13-76 (lines=64) @@ | ||
| 10 | use Actualys\Bundle\DrupalCommerceConnectorBundle\Normalizer\FamilyNormalizer; |
|
| 11 | use Actualys\Bundle\DrupalCommerceConnectorBundle\Item\DrupalItemStep; |
|
| 12 | ||
| 13 | class FamilyProcessor extends DrupalItemStep implements ItemProcessorInterface |
|
| 14 | { |
|
| 15 | /** |
|
| 16 | * @var FamilyNormalizer |
|
| 17 | */ |
|
| 18 | protected $familyNormalizer; |
|
| 19 | ||
| 20 | /** |
|
| 21 | * @var array |
|
| 22 | */ |
|
| 23 | protected $globalContext = array(); |
|
| 24 | ||
| 25 | /** |
|
| 26 | * @param FamilyNormalizer $familyNormalizer The entity manager |
|
| 27 | */ |
|
| 28 | public function __construct(FamilyNormalizer $familyNormalizer) |
|
| 29 | { |
|
| 30 | $this->familyNormalizer = $familyNormalizer; |
|
| 31 | } |
|
| 32 | ||
| 33 | /** |
|
| 34 | * @param mixed $family |
|
| 35 | * @return array|mixed |
|
| 36 | * @throws InvalidItemException |
|
| 37 | */ |
|
| 38 | public function process($family) |
|
| 39 | { |
|
| 40 | return $this->normalizeFamily($family, $this->globalContext); |
|
| 41 | } |
|
| 42 | ||
| 43 | /** |
|
| 44 | * @param Family $family |
|
| 45 | * @param array $context |
|
| 46 | * @return array|\Symfony\Component\Serializer\Normalizer\scalar |
|
| 47 | * @throws InvalidItemException |
|
| 48 | */ |
|
| 49 | protected function normalizeFamily(Family $family, array $context) |
|
| 50 | { |
|
| 51 | try { |
|
| 52 | $processedItem = $this->familyNormalizer->normalize( |
|
| 53 | $family, |
|
| 54 | null, |
|
| 55 | $this->getConfiguration() |
|
| 56 | ); |
|
| 57 | } catch (NormalizeException $e) { |
|
| 58 | throw new InvalidItemException($e->getMessage(), [$family]); |
|
| 59 | } |
|
| 60 | ||
| 61 | return $processedItem; |
|
| 62 | } |
|
| 63 | ||
| 64 | public function getConfigurationFields() |
|
| 65 | { |
|
| 66 | return parent::getConfigurationFields(); |
|
| 67 | } |
|
| 68 | ||
| 69 | /** |
|
| 70 | * @param StepExecution $stepExecution |
|
| 71 | */ |
|
| 72 | public function setStepExecution(StepExecution $stepExecution) |
|
| 73 | { |
|
| 74 | $this->stepExecution = $stepExecution; |
|
| 75 | } |
|
| 76 | } |
|
| 77 | ||
| @@ 13-75 (lines=63) @@ | ||
| 10 | use Actualys\Bundle\DrupalCommerceConnectorBundle\Normalizer\GroupNormalizer; |
|
| 11 | use Actualys\Bundle\DrupalCommerceConnectorBundle\Item\DrupalItemStep; |
|
| 12 | ||
| 13 | class GroupProcessor extends DrupalItemStep implements ItemProcessorInterface |
|
| 14 | { |
|
| 15 | /** |
|
| 16 | * @var GroupNormalizer |
|
| 17 | */ |
|
| 18 | protected $groupNormalizer; |
|
| 19 | ||
| 20 | /** |
|
| 21 | * @var array |
|
| 22 | */ |
|
| 23 | protected $globalContext = array(); |
|
| 24 | ||
| 25 | /** |
|
| 26 | * @param GroupNormalizer $groupNormalizer |
|
| 27 | */ |
|
| 28 | public function __construct(GroupNormalizer $groupNormalizer) |
|
| 29 | { |
|
| 30 | $this->groupNormalizer = $groupNormalizer; |
|
| 31 | } |
|
| 32 | ||
| 33 | /** |
|
| 34 | * @param mixed $group |
|
| 35 | * @return array|mixed |
|
| 36 | * @throws InvalidItemException |
|
| 37 | */ |
|
| 38 | public function process($group) |
|
| 39 | { |
|
| 40 | return $this->normalizeGroup($group, $this->globalContext); |
|
| 41 | } |
|
| 42 | ||
| 43 | /** |
|
| 44 | * @param Group $group |
|
| 45 | * @param array $context |
|
| 46 | * @return array|\Symfony\Component\Serializer\Normalizer\scalar |
|
| 47 | * @throws InvalidItemException |
|
| 48 | */ |
|
| 49 | protected function normalizeGroup(Group $group, array $context) |
|
| 50 | { |
|
| 51 | try { |
|
| 52 | $processedItem = $this->groupNormalizer->normalize( |
|
| 53 | $group, |
|
| 54 | $context |
|
| 55 | ); |
|
| 56 | } catch (NormalizeException $e) { |
|
| 57 | throw new InvalidItemException($e->getMessage(), [$group]); |
|
| 58 | } |
|
| 59 | ||
| 60 | return $processedItem; |
|
| 61 | } |
|
| 62 | ||
| 63 | public function getConfigurationFields() |
|
| 64 | { |
|
| 65 | return parent::getConfigurationFields(); |
|
| 66 | } |
|
| 67 | ||
| 68 | /** |
|
| 69 | * @param StepExecution $stepExecution |
|
| 70 | */ |
|
| 71 | public function setStepExecution(StepExecution $stepExecution) |
|
| 72 | { |
|
| 73 | $this->stepExecution = $stepExecution; |
|
| 74 | } |
|
| 75 | } |
|
| 76 | ||