Skip to content

Commit 5a8c06e

Browse files
committed
minor #30000 [Mime] move add mime type guesser pass to the component (xabbuh)
This PR was merged into the 4.3-dev branch. Discussion ---------- [Mime] move add mime type guesser pass to the component | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | Commits ------- ba20bb2 move add mime type guesser pass to the component
2 parents 98bc3e7 + ba20bb2 commit 5a8c06e

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddAnnotationsCachedReaderPass;
1515
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddDebugLogProcessorPass;
1616
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddExpressionLanguageProvidersPass;
17-
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddMimeTypeGuesserPass;
1817
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ContainerBuilderDebugDumpPass;
1918
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\DataCollectorTranslatorPass;
2019
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\LoggingTranslatorPass;
@@ -45,6 +44,7 @@
4544
use Symfony\Component\HttpKernel\DependencyInjection\ResettableServicePass;
4645
use Symfony\Component\HttpKernel\KernelEvents;
4746
use Symfony\Component\Messenger\DependencyInjection\MessengerPass;
47+
use Symfony\Component\Mime\DependencyInjection\AddMimeTypeGuesserPass;
4848
use Symfony\Component\PropertyInfo\DependencyInjection\PropertyInfoPass;
4949
use Symfony\Component\Routing\DependencyInjection\RoutingResolverPass;
5050
use Symfony\Component\Serializer\DependencyInjection\SerializerPass;
@@ -124,7 +124,7 @@ public function build(ContainerBuilder $container)
124124
$container->addCompilerPass(new ResettableServicePass());
125125
$container->addCompilerPass(new TestServiceContainerWeakRefPass(), PassConfig::TYPE_BEFORE_REMOVING, -32);
126126
$container->addCompilerPass(new TestServiceContainerRealRefPass(), PassConfig::TYPE_AFTER_REMOVING);
127-
$container->addCompilerPass(new AddMimeTypeGuesserPass());
127+
$this->addCompilerPassIfExists($container, AddMimeTypeGuesserPass::class);
128128
$this->addCompilerPassIfExists($container, MessengerPass::class);
129129

130130
if ($container->getParameter('kernel.debug')) {
Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
12+
namespace Symfony\Component\Mime\DependencyInjection;
1313

1414
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
1515
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -22,14 +22,23 @@
2222
*/
2323
class AddMimeTypeGuesserPass implements CompilerPassInterface
2424
{
25+
private $mimeTypesService;
26+
private $mimeTypeGuesserTag;
27+
28+
public function __construct(string $mimeTypesService = 'mime_types', string $mimeTypeGuesserTag = 'mime.mime_type_guesser')
29+
{
30+
$this->mimeTypesService = $mimeTypesService;
31+
$this->mimeTypeGuesserTag = $mimeTypeGuesserTag;
32+
}
33+
2534
/**
2635
* {@inheritdoc}
2736
*/
2837
public function process(ContainerBuilder $container)
2938
{
30-
if ($container->has('mime_types')) {
31-
$definition = $container->findDefinition('mime_types');
32-
foreach ($container->findTaggedServiceIds('mime.mime_type_guesser', true) as $id => $attributes) {
39+
if ($container->has($this->mimeTypesService)) {
40+
$definition = $container->findDefinition($this->mimeTypesService);
41+
foreach ($container->findTaggedServiceIds($this->mimeTypeGuesserTag, true) as $id => $attributes) {
3342
$definition->addMethodCall('registerGuesser', [new Reference($id)]);
3443
}
3544
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
12+
namespace Symfony\Component\Mime\Tests\DependencyInjection;
1313

1414
use PHPUnit\Framework\TestCase;
15-
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddMimeTypeGuesserPass;
1615
use Symfony\Component\DependencyInjection\ContainerBuilder;
1716
use Symfony\Component\DependencyInjection\Definition;
1817
use Symfony\Component\DependencyInjection\Reference;
18+
use Symfony\Component\Mime\DependencyInjection\AddMimeTypeGuesserPass;
1919
use Symfony\Component\Mime\FileinfoMimeTypeGuesser;
2020
use Symfony\Component\Mime\MimeTypes;
2121

src/Symfony/Component/Mime/composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
"require": {
1919
"php": "^7.1.3"
2020
},
21+
"require-dev": {
22+
"symfony/dependency-injection": "~3.4|^4.1"
23+
},
2124
"autoload": {
2225
"psr-4": { "Symfony\\Component\\Mime\\": "" },
2326
"exclude-from-classmap": [

0 commit comments

Comments
 (0)