Merge branch 'master' into product-image-handling

This commit is contained in:
arti0090 2021-07-28 11:09:51 +02:00 committed by arti0090
commit 17afb9f7d4
6 changed files with 15 additions and 7 deletions

View file

@ -14,6 +14,7 @@
+ "media_path": "/media/image/uo/product.jpg"
}
```
To change the prefix you need to set parameter in ``app/config/packages/_sylius.yaml``:
```yaml

View file

@ -11,7 +11,7 @@
declare(strict_types=1);
namespace Sylius\Bundle\ApiBundle\Doctrine\Filters;
namespace Sylius\Bundle\ApiBundle\Doctrine\Filter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\AbstractContextAwareFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryNameGeneratorInterface;

View file

@ -11,7 +11,7 @@
declare(strict_types=1);
namespace Sylius\Bundle\ApiBundle\Doctrine\Filters;
namespace Sylius\Bundle\ApiBundle\Doctrine\Filter;
use ApiPlatform\Core\Bridge\Doctrine\Common\Filter\OrderFilterInterface;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\AbstractContextAwareFilter;

View file

@ -97,12 +97,12 @@
<tag name="api_platform.filter" />
</service>
<service id="sylius.api.exchange_rate_filter" class="Sylius\Bundle\ApiBundle\Doctrine\Filters\ExchangeRateFilter">
<service id="sylius.api.exchange_rate_filter" class="Sylius\Bundle\ApiBundle\Doctrine\Filter\ExchangeRateFilter">
<argument type="service" id="doctrine" />
<tag name="api_platform.filter" />
</service>
<service id="sylius.api.translation_order_name_and_locale_filter" class="Sylius\Bundle\ApiBundle\Doctrine\Filters\TranslationOrderNameAndLocaleFilter">
<service id="sylius.api.translation_order_name_and_locale_filter" class="Sylius\Bundle\ApiBundle\Doctrine\Filter\TranslationOrderNameAndLocaleFilter">
<argument type="service" id="doctrine" />
<tag name="api_platform.filter" />
</service>

View file

@ -36,6 +36,11 @@
<tag name="serializer.normalizer" priority="64" />
</service>
<service id="Sylius\Bundle\ApiBundle\Serializer\ProductImageNormalizer">
<argument type="string">%sylius_api.product_image_prefix%</argument>
<tag name="serializer.normalizer" priority="64" />
</service>
<service id="Sylius\Bundle\ApiBundle\Serializer\CommandNormalizer">
<argument type="service" id="serializer.normalizer.object" />
<tag name="serializer.normalizer" priority="64" />

View file

@ -9,6 +9,8 @@
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Sylius\Bundle\ApiBundle\Serializer;
use Sylius\Component\Core\Model\ProductImageInterface;
@ -32,7 +34,7 @@ class ProductImageNormalizer implements ContextAwareNormalizerInterface, Normali
$this->prefix = $this->validatePrefix($prefix);
}
public function normalize($object, string $format = null, array $context = [])
public function normalize($object, $format = null, array $context = [])
{
Assert::isInstanceOf($object, ProductImageInterface::class);
Assert::keyNotExists($context, self::ALREADY_CALLED);
@ -46,7 +48,7 @@ class ProductImageNormalizer implements ContextAwareNormalizerInterface, Normali
return $data;
}
public function supportsNormalization($data, string $format = null, array $context = []): bool
public function supportsNormalization($data, $format = null, $context = []): bool
{
if (isset($context[self::ALREADY_CALLED])) {
return false;
@ -57,7 +59,7 @@ class ProductImageNormalizer implements ContextAwareNormalizerInterface, Normali
private function validatePrefix(string $prefix): string
{
if ('/' !== substr($prefix, 0)) {
if ('/' !== substr($prefix, 0, 1)) {
$prefix = '/'.$prefix;
}