diff --git a/src/AkeneoBuilderProvider.php b/src/AkeneoBuilderProvider.php index a6f2905..08029e8 100644 --- a/src/AkeneoBuilderProvider.php +++ b/src/AkeneoBuilderProvider.php @@ -17,6 +17,7 @@ public function getFunctions(): array new WithReferenceEntitySimpleOption('withReferenceEntitySimpleOption'), new WithSimpleOption('withSimpleOption'), new WithMultipleOption('withMultipleOption'), + new WithProductValueMediaFile('withProductValueMediaFile'), ]; } } diff --git a/src/DateTime.php b/src/DateTime.php index 67220c9..be90f60 100644 --- a/src/DateTime.php +++ b/src/DateTime.php @@ -17,7 +17,7 @@ public function __construct($name) ); } - private function compile(string $date, string|null $format = null): string + private function compile(string $date, ?string $format = null): string { if (null === $format) { return sprintf('new \DateTimeImmutable(%s, new \DateTimeZone("UTC"))', $date); @@ -26,7 +26,7 @@ private function compile(string $date, string|null $format = null): string return sprintf('\DateTimeImmutable::createFromFormat(%s, %s, new \DateTimeZone("UTC"))', $date, $format); } - private function evaluate(array $context, string $date, string|null $format = null): \DateTimeInterface + private function evaluate(array $context, string $date, ?string $format = null): \DateTimeInterface { if (null === $format) { return new \DateTimeImmutable($date, new \DateTimeZone('UTC')); diff --git a/src/DateTimeZone.php b/src/DateTimeZone.php index 9d0392c..6cf0335 100644 --- a/src/DateTimeZone.php +++ b/src/DateTimeZone.php @@ -17,7 +17,7 @@ public function __construct($name) ); } - private function compile(string $date, string $zone, string|null $format = null): string + private function compile(string $date, string $zone, ?string $format = null): string { if (null === $format) { return sprintf('new \DateTimeImmutable(%s, new \DateTimeZone(%s))', $date, $zone); @@ -26,7 +26,7 @@ private function compile(string $date, string $zone, string|null $format = null) return sprintf('\DateTimeImmutable::createFromFormat(%s, %s, new \DateTimeZone(%s))', $date, $format, $zone); } - private function evaluate(array $context, string $date, string $zone, string|null $format = null): \DateTimeInterface + private function evaluate(array $context, string $date, string $zone, ?string $format = null): \DateTimeInterface { if (null === $format) { return new \DateTimeImmutable($date, new \DateTimeZone($zone)); diff --git a/src/FormatMetric.php b/src/FormatMetric.php index 3232489..1ffc42a 100644 --- a/src/FormatMetric.php +++ b/src/FormatMetric.php @@ -171,7 +171,7 @@ private function compile($attribute, $locale): string PHP; } - private function evaluate(array $context, array $attribut, string $locale): string|null + private function evaluate(array $context, array $attribut, string $locale): ?string { return !\is_array($attribut) || !\array_key_exists('amount', $attribut) || !\array_key_exists('unit', $attribut) ? null : (function ($unit, $amount, $locale) { diff --git a/src/MetricAmount.php b/src/MetricAmount.php index c4709e7..69f0ea6 100644 --- a/src/MetricAmount.php +++ b/src/MetricAmount.php @@ -24,7 +24,7 @@ private function compile(string $value, int $decimalRound = 4): string PATTERN; } - private function evaluate(array $context, array $value, int $decimalRound): float|null + private function evaluate(array $context, array $value, int $decimalRound): ?float { return !\is_array($value) || !\array_key_exists('amount', $value) ? null : round((float) $value['amount'], $decimalRound); } diff --git a/src/MetricUnit.php b/src/MetricUnit.php index d0986f6..49f1dfd 100644 --- a/src/MetricUnit.php +++ b/src/MetricUnit.php @@ -24,7 +24,7 @@ private function compile(string $value): string PATTERN; } - private function evaluate(array $context, array $value): string|null + private function evaluate(array $context, array $value): ?string { return !\is_array($value) || !\array_key_exists('unit', $value) ? null : $value['unit']; } diff --git a/src/WithMultipleOption.php b/src/WithMultipleOption.php index 8466408..07b68d3 100644 --- a/src/WithMultipleOption.php +++ b/src/WithMultipleOption.php @@ -23,7 +23,7 @@ private function compile(string $codes, string $attribute, string $labels, strin (function() use(\$input) { \$linkedData = array_map( function (string \$code) use(\$input) { - static \$labels = {$labels}; + \$labels = {$labels}; return [ 'attribute' => {$attribute}, @@ -48,7 +48,7 @@ function (string \$code) use(\$input) { /** * @return array> */ - private function evaluate(array $context, array $codes, string $attribute, array $labels, string|null $locale = null, string|null $scope = null): array + private function evaluate(array $context, array $codes, string $attribute, array $labels, ?string $locale = null, ?string $scope = null): array { return [[ 'locale' => $locale, diff --git a/src/WithProductValueMediaFile.php b/src/WithProductValueMediaFile.php new file mode 100644 index 0000000..69c9724 --- /dev/null +++ b/src/WithProductValueMediaFile.php @@ -0,0 +1,44 @@ +compile(...)->bindTo($this), + $this->evaluate(...)->bindTo($this) + ); + } + + private function compile(string $code, string $attribute, string $locale = 'null', string $scope = 'null'): string + { + return << {$code}, + 'attribute' => {$attribute}, + 'locale' => {$locale}, + 'scope' => {$scope}, + ] + PHP; + } + + /** + * @return array + */ + private function evaluate(array $context, string $code, string $attribute, ?string $locale = null, ?string $scope = null): array + { + return [ + 'identifier' => $code, + 'attribute' => $attribute, + 'locale' => $locale, + 'scope' => $scope, + ]; + } +} diff --git a/src/WithReferenceEntitySimpleOption.php b/src/WithReferenceEntitySimpleOption.php index 6c34a1a..62cb37a 100644 --- a/src/WithReferenceEntitySimpleOption.php +++ b/src/WithReferenceEntitySimpleOption.php @@ -32,7 +32,7 @@ private function compile(string $code, string $locale = 'null', string $channel PHP; } - private function evaluate(array $context, string $code, string|null $locale = null, string|null $channel = null): array + private function evaluate(array $context, string $code, ?string $locale = null, ?string $channel = null): array { return [[ 'locale' => $locale, diff --git a/src/WithReferenceEntityValue.php b/src/WithReferenceEntityValue.php index ef56e6c..86f1f7c 100644 --- a/src/WithReferenceEntityValue.php +++ b/src/WithReferenceEntityValue.php @@ -22,7 +22,7 @@ private function compile(string $value, string $locale = 'null', string $channel return sprintf('([["data" => (%s), "locale" => (%s), "channel" => (%s)]])', $value, $locale, $channel); } - private function evaluate(array $context, string $value, string|null $locale = null, string|null $channel = null): array + private function evaluate(array $context, string $value, ?string $locale = null, ?string $channel = null): array { return [[ 'locale' => $locale,