-
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 expression to return correct format for product association in Pr…
…oductMedialFile endpoint
- Loading branch information
Showing
2 changed files
with
45 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
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,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Kiboko\Component\ExpressionLanguage\Akeneo; | ||
|
||
use Symfony\Component\ExpressionLanguage\ExpressionFunction; | ||
|
||
final class WithProductValueMediaFile extends ExpressionFunction | ||
{ | ||
public function __construct($name) | ||
{ | ||
parent::__construct( | ||
$name, | ||
$this->compile(...)->bindTo($this), | ||
$this->evaluate(...)->bindTo($this) | ||
); | ||
} | ||
|
||
private function compile(string $code, string $attribute, string $locale = 'null', string $scope = 'null'): string | ||
{ | ||
return <<<PHP | ||
([ | ||
'identifier' => ({$code}), | ||
'attribute' => ({$attribute}), | ||
'locale' => {$locale}, | ||
'scope' => {$scope}, | ||
]) | ||
PHP; | ||
} | ||
|
||
/** | ||
* @return array<int, string> | ||
*/ | ||
private function evaluate(array $context, string $code, string $attribute, string $locale = 'null', string $scope = 'null'): array | ||
{ | ||
return [ | ||
Check failure on line 37 in src/WithProductValueMediaFile.php GitHub Actions / phpstan5
|
||
'identifier' => $code, | ||
'attribute' => $attribute, | ||
'locale' => $locale, | ||
'scope' => $scope, | ||
]; | ||
} | ||
} |