-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add create capacity for productMedialFile endpoint on Akeneo Loader
- Loading branch information
Showing
2 changed files
with
48 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Kiboko\Plugin\Akeneo\Capacity\Loader; | ||
|
||
use Kiboko\Plugin\Akeneo; | ||
use PhpParser\Builder; | ||
use PhpParser\Node; | ||
use Symfony\Component\ExpressionLanguage\ExpressionLanguage; | ||
use function Kiboko\Component\SatelliteToolbox\Configuration\compileValueWhenExpression; | ||
|
||
final class Create implements Akeneo\Capacity\CapacityInterface | ||
{ | ||
private static array $endpoints = [ | ||
'productMediaFile', | ||
]; | ||
|
||
public function __construct(private readonly ExpressionLanguage $interpreter) {} | ||
|
||
public function applies(array $config): bool | ||
{ | ||
return isset($config['type']) | ||
&& \in_array($config['type'], self::$endpoints) | ||
&& isset($config['method']) | ||
&& 'create' === $config['method']; | ||
} | ||
|
||
public function getBuilder(array $config): Builder | ||
{ | ||
$builder = (new Akeneo\Builder\Capacity\Loader\Upsert()) | ||
->withEndpoint(endpoint: new Node\Identifier(sprintf('get%sApi', ucfirst((string) $config['type'])))) | ||
->withCode(code: compileValueWhenExpression($this->interpreter, $config['code'], 'line')) | ||
->withData(line: new Node\Expr\Variable('line')) | ||
; | ||
|
||
if (\array_key_exists('reference_entity', $config)) { | ||
$builder->withReferenceEntity(referenceEntity: new Node\Scalar\String_($config['reference_entity'])); | ||
} | ||
|
||
if (\array_key_exists('reference_entity_attribute', $config)) { | ||
$builder->withReferenceEntityAttribute(referenceEntityAttribute: compileValueWhenExpression($this->interpreter, $config['reference_entity_attribute'], 'line')); | ||
} | ||
|
||
return $builder; | ||
} | ||
} |
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