Skip to content

Commit ecda0b3

Browse files
Douglas Greenshieldsgsdevme
authored andcommitted
feat: upgrade symfony versions to 3.4 up to 5
1 parent 1f89633 commit ecda0b3

File tree

11 files changed

+139
-207
lines changed

11 files changed

+139
-207
lines changed

Cache/ObjectCache.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/**
99
* An object cache for oEmbed instances.
1010
*/
11-
class ObjectCache implements ObjectCacheInterface
11+
class ObjectCache
1212
{
1313
/**
1414
* @var CacheInterface
@@ -27,7 +27,8 @@ public function __construct(CacheInterface $cache, OEmbedSerializerInterface $se
2727
}
2828

2929
/**
30-
* {@inheritdoc}
30+
* @param string $key
31+
* @return OEmbedInterface|null
3132
**/
3233
public function get($key)
3334
{
@@ -40,7 +41,9 @@ public function get($key)
4041
}
4142

4243
/**
43-
* {@inheritdoc}
44+
* @param string $key
45+
* @param OEmbedInterface $oEmbed
46+
* @return void
4447
**/
4548
public function set($key, OEmbedInterface $oEmbed)
4649
{

Cache/ObjectCacheInterface.php

Lines changed: 0 additions & 28 deletions
This file was deleted.

Command/FetchOEmbedCommand.php renamed to Console/FetchOEmbedCommand.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,38 @@
11
<?php
22

3-
namespace Markup\OEmbedBundle\Command;
3+
namespace Markup\OEmbedBundle\Console;
44

55
use Markup\OEmbedBundle\Exception\OEmbedUnavailableException;
66
use Markup\OEmbedBundle\Service\OEmbedService;
7-
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
7+
use Symfony\Component\Console\Command\Command;
88
use Symfony\Component\Console\Input\InputArgument;
99
use Symfony\Component\Console\Input\InputInterface;
1010
use Symfony\Component\Console\Output\OutputInterface;
1111

1212
/**
1313
* A console command to fetch oEmbed instances and output their data.
1414
*/
15-
class FetchOEmbedCommand extends ContainerAwareCommand
15+
class FetchOEmbedCommand extends Command
1616
{
17+
protected static $defaultName = 'oembed:fetch';
18+
19+
/**
20+
* @var OEmbedService
21+
*/
22+
private $oEmbedService;
23+
24+
public function __construct(OEmbedService $oEmbedService)
25+
{
26+
$this->oEmbedService = $oEmbedService;
27+
parent::__construct();
28+
}
29+
1730
/**
1831
* @return void
1932
*/
2033
protected function configure()
2134
{
2235
$this
23-
->setName('oembed:fetch')
2436
->setDescription('Makes a query against an oEmbed provider for data about a piece of media')
2537
->addArgument('provider', InputArgument::REQUIRED, 'An oEmbed provider name')
2638
->addArgument('media_id', InputArgument::REQUIRED, 'The ID of the piece of media being embedded.');
@@ -37,9 +49,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
3749

3850
$startTime = microtime(true);
3951
try {
40-
/** @var OEmbedService $oEmbedService */
41-
$oEmbedService = $this->getContainer()->get('markup_oembed');
42-
$oEmbed = $oEmbedService->fetchOEmbed($provider, $mediaId);
52+
$oEmbed = $this->oEmbedService->fetchOEmbed($provider, $mediaId);
4353
} catch (OEmbedUnavailableException $e) {
4454
$output->writeln(sprintf('<error>Could not fetch the oEmbed data. Reported error: %s</error>', $e->getMessage()));
4555

DependencyInjection/Configuration.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ class Configuration implements ConfigurationInterface
1717
*/
1818
public function getConfigTreeBuilder()
1919
{
20-
$treeBuilder = new TreeBuilder();
21-
$rootNode = $treeBuilder->root('markup_o_embed');
20+
$treeBuilder = new TreeBuilder('markup_o_embed');
21+
$rootNode = (method_exists(TreeBuilder::class, 'getRootNode'))
22+
? $treeBuilder->getRootNode()
23+
: $treeBuilder->root('markup_o_embed');
2224

2325
$rootNode
2426
->fixXmlConfig('provider')

DependencyInjection/MarkupOEmbedExtension.php

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22

33
namespace Markup\OEmbedBundle\DependencyInjection;
44

5+
use Markup\OEmbedBundle\Cache\NullCache;
6+
use Markup\OEmbedBundle\Provider\SimpleProvider;
57
use Symfony\Component\Config\FileLocator;
68
use Symfony\Component\DependencyInjection\ContainerBuilder;
79
use Symfony\Component\DependencyInjection\Definition;
810
use Symfony\Component\DependencyInjection\Loader;
11+
use Symfony\Component\DependencyInjection\Reference;
912
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
1013

1114
/**
@@ -45,10 +48,28 @@ private function loadProviders(array $config, ContainerBuilder $container)
4548
if (!isset($config['providers'])) {
4649
return;
4750
}
51+
$providerLocator = $container->findDefinition('markup_oembed.provider_locator');
4852
foreach ($config['providers'] as $providerName => $provider) {
49-
$definition = new Definition('Markup\OEmbedBundle\Provider\SimpleProvider', array($providerName, $provider['endpoint'], $provider['scheme'], $provider['code_property']));
53+
$definition = (new Definition(
54+
SimpleProvider::class,
55+
[
56+
$providerName,
57+
$provider['endpoint'],
58+
$provider['scheme'],
59+
$provider['code_property'],
60+
]
61+
))->setPublic(false);
5062

51-
$container->setDefinition(sprintf('markup_oembed.provider.%s', $providerName), $definition);
63+
$providerId = sprintf('markup_oembed.provider.%s', $providerName);
64+
$container->setDefinition($providerId, $definition);
65+
$providerLocator->setArguments([
66+
array_merge(
67+
$providerLocator->getArguments()[0],
68+
[
69+
$providerName => new Reference($providerId),
70+
]
71+
)
72+
]);
5273
}
5374
}
5475

@@ -75,7 +96,7 @@ private function loadCacheServices(array $config, ContainerBuilder $container)
7596
{
7697
$cacheServiceId = 'markup_oembed.string_cache';
7798
if (!isset($config['cache']) || !isset($config['cache']['id'])) {
78-
$container->setDefinition($cacheServiceId, new Definition('Markup\OEmbedBundle\Cache\NullCache'));
99+
$container->setDefinition($cacheServiceId, new Definition(NullCache::class));
79100
} else {
80101
$container->setAlias($cacheServiceId, $config['cache']['id']);
81102
}

Provider/ProviderFactory.php

Lines changed: 0 additions & 51 deletions
This file was deleted.

Resources/config/services.yml

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,37 @@ parameters:
22
markup_oembed.cache_key_delimiter.default: ':'
33

44
services:
5-
markup_oembed:
6-
class: 'Markup\OEmbedBundle\Service\OEmbedService'
5+
Markup\OEmbedBundle\Service\OEmbedService:
76
arguments:
8-
- '@markup_oembed.client'
9-
- '@markup_oembed.provider_factory'
10-
- '@markup_oembed.object_cache'
11-
- '%markup_oembed.cache_key_delimiter%'
12-
markup_oembed.provider_factory:
13-
class: Markup\OEmbedBundle\Provider\ProviderFactory
14-
arguments:
15-
- '@service_container'
16-
- 'markup_oembed.provider'
17-
public: false
18-
markup_oembed.client.guzzle:
19-
class: 'Markup\OEmbedBundle\Client\GuzzleClient'
7+
$client: '@Markup\OEmbedBundle\Client\GuzzleClient'
8+
$providerLocator: '@markup_oembed.provider_locator'
9+
$cacheKeyDelimiter: '%markup_oembed.cache_key_delimiter%'
10+
autowire: true
11+
markup_oembed: '@Markup\OEmbedBundle\Service\OEmbedService'
12+
Markup\OEmbedBundle\Client\GuzzleClient:
2013
public: false
21-
markup_oembed.client:
22-
alias: markup_oembed.client.guzzle
23-
markup_oembed.twig.extension:
24-
class: 'Markup\OEmbedBundle\Twig\Extension'
14+
Markup\OEmbedBundle\Twig\Extension:
2515
arguments:
26-
- '@markup_oembed'
27-
- '%markup_oembed.squash_rendering_errors%'
16+
$shouldSquashRenderingErrors: '%markup_oembed.squash_rendering_errors%'
17+
autowire: true
2818
tags:
2919
- { name: twig.extension }
30-
markup_oembed.serializer:
31-
class: 'Markup\OEmbedBundle\Serializer\OEmbedSerializer'
20+
Markup\OEmbedBundle\Serializer\OEmbedSerializer:
3221
public: false
3322

34-
markup_oembed.object_cache:
35-
class: 'Markup\OEmbedBundle\Cache\ObjectCache'
23+
Markup\OEmbedBundle\Cache\ObjectCache:
3624
arguments:
3725
- '@markup_oembed.string_cache'
38-
- '@markup_oembed.serializer'
26+
- '@Markup\OEmbedBundle\Serializer\OEmbedSerializer'
3927
public: false
28+
29+
markup_oembed.provider_locator:
30+
class: Symfony\Component\DependencyInjection\ServiceLocator
31+
tags: ['container.service_locator']
32+
arguments: [[]]
33+
public: false
34+
35+
Markup\OEmbedBundle\Console\:
36+
resource: '../../Console/*'
37+
autowire: true
38+
autoconfigure: true

Service/OEmbedService.php

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace Markup\OEmbedBundle\Service;
56

6-
use Markup\OEmbedBundle\Cache\ObjectCacheInterface;
7+
use Markup\OEmbedBundle\Cache\ObjectCache;
78
use Markup\OEmbedBundle\Client\ClientInterface;
89
use Markup\OEmbedBundle\Exception\InvalidOEmbedContentException;
910
use Markup\OEmbedBundle\Exception\OEmbedUnavailableException;
10-
use Markup\OEmbedBundle\Exception\ProviderNotFoundException;
1111
use Markup\OEmbedBundle\OEmbed\OEmbedInterface;
12-
use Markup\OEmbedBundle\Provider\ProviderFactory;
12+
use Markup\OEmbedBundle\Provider\ProviderInterface;
13+
use Psr\Container\ContainerInterface;
14+
use Psr\Container\NotFoundExceptionInterface;
1315

1416
/**
1517
* A service for fetching oEmbed stuff from an implementing provider.
@@ -24,12 +26,12 @@ class OEmbedService
2426
private $client;
2527

2628
/**
27-
* @var ProviderFactory
28-
**/
29-
private $providerFactory;
29+
* @var ContainerInterface
30+
*/
31+
private $providerLocator;
3032

3133
/**
32-
* @var ObjectCacheInterface
34+
* @var ObjectCache
3335
**/
3436
private $objectCache;
3537

@@ -38,20 +40,14 @@ class OEmbedService
3840
**/
3941
private $cacheKeyDelimiter;
4042

41-
/**
42-
* @param ClientInterface $client
43-
* @param ProviderFactory $providerFactory
44-
* @param ObjectCacheInterface $objectCache
45-
* @param string $cacheKeyDelimiter
46-
**/
4743
public function __construct(
4844
ClientInterface $client,
49-
ProviderFactory $providerFactory,
50-
ObjectCacheInterface $objectCache,
51-
$cacheKeyDelimiter = ':'
45+
ContainerInterface $providerLocator,
46+
ObjectCache $objectCache,
47+
string $cacheKeyDelimiter = ':'
5248
) {
5349
$this->client = $client;
54-
$this->providerFactory = $providerFactory;
50+
$this->providerLocator = $providerLocator;
5551
$this->objectCache = $objectCache;
5652
$this->cacheKeyDelimiter = $cacheKeyDelimiter;
5753
}
@@ -67,8 +63,9 @@ public function fetchOEmbed(string $provider, string $mediaId, array $parameters
6763
}
6864

6965
try {
70-
$providerObject = $this->providerFactory->fetchProvider($provider);
71-
} catch (ProviderNotFoundException $e) {
66+
/** @var ProviderInterface $providerObject */
67+
$providerObject = $this->providerLocator->get($provider);
68+
} catch (NotFoundExceptionInterface $e) {
7269
throw new OEmbedUnavailableException($e->getMessage(), 0, $e);
7370
}
7471

0 commit comments

Comments
 (0)