Skip to content

Commit

Permalink
Merge pull request #20 from Bukashk0zzz/symfony-5
Browse files Browse the repository at this point in the history
Symfony 5 support
  • Loading branch information
Bukashk0zzz authored May 14, 2020
2 parents 8d84cb3 + 61902d0 commit 00b0ec3
Show file tree
Hide file tree
Showing 16 changed files with 37 additions and 290 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ language: php
sudo: false

php:
- 7.1
- 7.2
- 7.4

before_script:
- composer self-update
- composer install --dev --prefer-dist --no-interaction

script:
- ./vendor/bin/phpcs ./ -p --standard=./ruleset.xml
- ./vendor/bin/php-cs-fixer fix --config=.php_cs -vvv --dry-run
- ./vendor/bin/phpunit -c phpunit.xml.dist --coverage-clover=coverage.xml

after_success:
Expand Down
24 changes: 0 additions & 24 deletions Annotation/LiipImagineSerializableField.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ public function getFilter()

/**
* @param string|string[] $filter
*
* @return LiipImagineSerializableField
*/
public function setFilter($filter): LiipImagineSerializableField
{
Expand All @@ -88,52 +86,30 @@ public function setFilter($filter): LiipImagineSerializableField
return $this;
}

/**
* @return string|null
*/
public function getVichUploaderField(): ?string
{
return $this->vichUploaderField;
}

/**
* @param string $vichUploaderField
*
* @return LiipImagineSerializableField
*/
public function setVichUploaderField(string $vichUploaderField): LiipImagineSerializableField
{
$this->vichUploaderField = $vichUploaderField;

return $this;
}

/**
* @return string|null
*/
public function getVirtualField(): ?string
{
return $this->virtualField;
}

/**
* @param string $virtualField
*
* @return LiipImagineSerializableField
*/
public function setVirtualField(string $virtualField): LiipImagineSerializableField
{
$this->virtualField = $virtualField;

return $this;
}

/**
* @param string $optionName
* @param bool $canBeArray
*
* @return bool
*/
private function checkOption(string $optionName, bool $canBeArray): bool
{
if (\array_key_exists($optionName, $this->options)) {
Expand Down
9 changes: 5 additions & 4 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ class Configuration implements ConfigurationInterface
{
/**
* Generates the configuration tree.
*
* @return \Symfony\Component\Config\Definition\Builder\NodeParentInterface
*/
public function getConfigTreeBuilder(): NodeParentInterface
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('bukashk0zzz_liip_imagine_serialization');
$treeBuilder = new TreeBuilder('bukashk0zzz_liip_imagine_serialization');

$rootNode = \method_exists($treeBuilder, 'getRootNode')
? $treeBuilder->getRootNode()
: $treeBuilder->root('bukashk0zzz_liip_imagine_serialization');

$rootNode
->children()
Expand Down
13 changes: 1 addition & 12 deletions Event/UrlNormalizerEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Bukashk0zzz\LiipImagineSerializationBundle\Event;

use Symfony\Component\EventDispatcher\Event;
use Symfony\Contracts\EventDispatcher\Event;

/**
* UrlNormalizerEvent
Expand All @@ -17,27 +17,16 @@ class UrlNormalizerEvent extends Event
*/
protected $url;

/**
* @param string $url
*/
public function __construct(string $url)
{
$this->url = $url;
}

/**
* @return string
*/
public function getUrl(): string
{
return $this->url;
}

/**
* @param string $url
*
* @return UrlNormalizerEvent
*/
public function setUrl(string $url): UrlNormalizerEvent
{
$this->url = $url;
Expand Down
35 changes: 5 additions & 30 deletions EventListener/JmsSerializeListenerAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,7 @@ class JmsSerializeListenerAbstract
/**
* JmsSerializeListenerAbstract constructor.
*
* @param RequestContext $requestContext
* @param CachedReader $annotationReader
* @param CacheManager $cacheManager
* @param StorageInterface $vichStorage
* @param EventDispatcherInterface $eventDispatcher
* @param mixed[] $config
* @param mixed[] $config
*/
public function __construct(
RequestContext $requestContext,
Expand Down Expand Up @@ -101,9 +96,8 @@ protected function getObject(ObjectEvent $event)
}

/**
* @param LiipImagineSerializableField $liipAnnotation
* @param mixed $object Serialized object
* @param string $value Value of field
* @param mixed $object Serialized object
* @param string $value Value of field
*
* @return mixed[]|string
*/
Expand Down Expand Up @@ -162,11 +156,6 @@ protected function getHostUrl(): string

/**
* Normalize url if needed
*
* @param string $url
* @param string $normalizer
*
* @return string
*/
protected function normalizeUrl(string $url, string $normalizer): string
{
Expand All @@ -185,10 +174,6 @@ protected function normalizeUrl(string $url, string $normalizer): string

/**
* If config demands, it will remove host and scheme (protocol) from passed url
*
* @param string $url
*
* @return string
*/
private function prepareFilteredUrl(string $url): string
{
Expand All @@ -201,10 +186,6 @@ private function prepareFilteredUrl(string $url): string

/**
* Removes host and scheme (protocol) from passed url
*
* @param string $url
*
* @return string
*/
private function stripHostFromUrl(string $url): string
{
Expand All @@ -216,20 +197,14 @@ private function stripHostFromUrl(string $url): string
throw new \InvalidArgumentException('Can\'t strip host from url, because can\'t parse url.');
}

/**
* @param string $type
* @param string $url
*
* @return string
*/
private function addPreNormalizeUrlEvent(string $type, string $url): string
{
/** @var UrlNormalizerEvent $event */
$event = $this->eventDispatcher->dispatch(
new UrlNormalizerEvent($url),
$type === UrlNormalizerInterface::TYPE_ORIGIN
? UrlNormalizerEvent::ORIGIN
: UrlNormalizerEvent::FILTERED,
new UrlNormalizerEvent($url)
: UrlNormalizerEvent::FILTERED
);

return $event->getUrl();
Expand Down
5 changes: 0 additions & 5 deletions Normalizer/UrlNormalizerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,5 @@ interface UrlNormalizerInterface
public const TYPE_ORIGIN = 'originUrlNormalizer';
public const TYPE_FILTERED = 'filteredUrlNormalizer';

/**
* @param string|null $url
*
* @return string
*/
public function normalize(?string $url): string;
}
1 change: 1 addition & 0 deletions Tests/Annotation/LiipImagineSerializableFieldTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php declare(strict_types = 1);

/*
* This file is part of the Bukashk0zzzLiipImagineSerializationBundle
*
Expand Down
15 changes: 3 additions & 12 deletions Tests/EventListener/JmsSerializeContextGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
namespace Bukashk0zzz\LiipImagineSerializationBundle\Tests\EventListener;

use Doctrine\Common\Annotations\AnnotationReader;
use JMS\Serializer\Construction\UnserializeObjectConstructor;
use JMS\Serializer\Accessor\DefaultAccessorStrategy;
use JMS\Serializer\DeserializationContext;
use JMS\Serializer\EventDispatcher\EventDispatcher;
use JMS\Serializer\GraphNavigator;
use JMS\Serializer\Handler\HandlerRegistry;
use JMS\Serializer\JsonSerializationVisitor;
Expand All @@ -22,23 +21,15 @@
use JMS\Serializer\Naming\SerializedNameAnnotationStrategy;
use Metadata\MetadataFactory;

/**
* JmsSerializeContextGenerator
*/
class JmsSerializeContextGenerator
{
/**
* Generate JMS context
*
* @return DeserializationContext
*/
public function generateContext(): DeserializationContext
{
$namingStrategy = new SerializedNameAnnotationStrategy(new CamelCaseNamingStrategy());

$context = DeserializationContext::create();
$factory = new MetadataFactory(new AnnotationDriver(new AnnotationReader()));
$context->initialize('json', new JsonSerializationVisitor($namingStrategy), new GraphNavigator($factory, new HandlerRegistry(), new UnserializeObjectConstructor(), new EventDispatcher()), $factory);
$factory = new MetadataFactory(new AnnotationDriver(new AnnotationReader(), $namingStrategy));
$context->initialize('json', new JsonSerializationVisitor(), new GraphNavigator\SerializationGraphNavigator($factory, new HandlerRegistry(), new DefaultAccessorStrategy()), $factory);

return $context;
}
Expand Down
15 changes: 2 additions & 13 deletions Tests/EventListener/JmsSerializeEventsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ public function __construct()

/**
* Add post & pre serialize event listeners
*
* @param RequestContext $requestContext
* @param CacheManager $cacheManager
* @param StorageInterface $vichStorage
*/
public function addEventListeners(RequestContext $requestContext, CacheManager $cacheManager, StorageInterface $vichStorage): void
{
Expand All @@ -70,10 +66,7 @@ public function addEventListeners(RequestContext $requestContext, CacheManager $
}

/**
* @param DeserializationContext $context
* @param User|UserPictures $user
*
* @return ObjectEvent
* @param User|UserPictures $user
*/
public function dispatchEvents(DeserializationContext $context, $user): ObjectEvent
{
Expand All @@ -88,11 +81,7 @@ public function dispatchEvents(DeserializationContext $context, $user): ObjectEv
/** @noinspection MoreThanThreeArgumentsInspection
* Add post & pre serialize event to dispatcher
*
* @param EventDispatcher $dispatcher
* @param RequestContext $requestContext
* @param CacheManager $cacheManager
* @param StorageInterface $vichStorage
* @param mixed[] $config JMS serializer listner config
* @param mixed[] $config JMS serializer listner config
*/
public function addEvents(EventDispatcher $dispatcher, RequestContext $requestContext, CacheManager $cacheManager, StorageInterface $vichStorage, array $config = []): void
{
Expand Down
17 changes: 5 additions & 12 deletions Tests/EventListener/JmsSerializeListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -418,10 +418,6 @@ protected function serializeObject($user, array $config = []): array
return \json_decode($result, true);
}

/**
* @param bool $https
* @param bool $port
*/
protected function generateRequestContext(bool $https = false, bool $port = false): void
{
$this->requestContext = $this->getMockBuilder(RequestContext::class)
Expand Down Expand Up @@ -455,17 +451,14 @@ protected function generateRequestContext(bool $https = false, bool $port = fals

/**
* Prepare mock of Liip cache manager
*
* @param string $urlPrefix
* @param bool $isStored
*/
protected function generateCacheManager(string $urlPrefix = 'http://example.com:8800/', bool $isStored = true): void
{
$resolver = $this->getMockBuilder(ResolverInterface::class)->getMock();
$resolver
->expects(static::any())
->method('isStored')
->will(static::returnValue($isStored))
->willReturn($isStored)
;
$resolver
->expects(static::any())
Expand All @@ -485,11 +478,11 @@ protected function generateCacheManager(string $urlPrefix = 'http://example.com:
$config = $this->getMockBuilder(FilterConfiguration::class)->getMock();
$config->expects(static::any())
->method('get')
->will(static::returnValue([
->willReturn([
'size' => [180, 180],
'mode' => 'outbound',
'cache' => null,
]))
])
;

$router = $this->getMockBuilder(RouterInterface::class)->getMock();
Expand Down Expand Up @@ -524,8 +517,8 @@ protected function generateVichStorage(): void
$this->vichStorage = $this->getMockBuilder(FileSystemStorage::class)
->disableOriginalConstructor()
->getMock();
$this->vichStorage->expects(static::any())
$this->vichStorage
->method('resolveUri')
->will(static::returnValue('/uploads/photo.jpg'));
->willReturn('/uploads/photo.jpg');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,11 @@ public static function getSubscribedEvents(): array
];
}

/**
* @param UrlNormalizerEvent $event
*/
public function normalizeOrigin(UrlNormalizerEvent $event): void
{
$event->setUrl(\str_replace('photo', 'newPhoto', $event->getUrl()));
}

/**
* @param UrlNormalizerEvent $event
*/
public function normalizeFiltered(UrlNormalizerEvent $event): void
{
$event->setUrl(\str_replace('example.com', 'img.example.com', $event->getUrl()));
Expand Down
Loading

0 comments on commit 00b0ec3

Please sign in to comment.