Skip to content

Commit 9073de4

Browse files
committed
minor #13843 Fill out custom type guesser paragraph (l-vo)
This PR was merged into the 4.4 branch. Discussion ---------- Fill out custom type guesser paragraph Fill out custom type guesser registration with the fullstack framework and add details about registration without the fullstack framework. Commits ------- d6757d9 Fill out custom type guesser paragraph
2 parents 74f1eea + d6757d9 commit 9073de4

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

components/mime.rst

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ that extension to improve the guessing performance.
276276
Adding a MIME Type Guesser
277277
..........................
278278

279-
You can register your own MIME type guesser by creating a class that implements
279+
You can write your own MIME type guesser by creating a class that implements
280280
:class:`Symfony\\Component\\Mime\\MimeTypeGuesserInterface`::
281281

282282
namespace App;
@@ -300,6 +300,55 @@ You can register your own MIME type guesser by creating a class that implements
300300
}
301301
}
302302

303+
And registering it::
304+
305+
$mimeTypes = new MimeTypes();
306+
$mimeTypes->registerGuesser(new SomeMimeTypeGuesser());
307+
308+
When using the Symfony fullstack Framework, you just need to add the ``mime.mime_type_guesser`` tag:
309+
310+
.. configuration-block::
311+
312+
.. code-block:: yaml
313+
314+
# config/services.yaml
315+
services:
316+
App\SomeMimeTypeGuesser:
317+
tags: [mime.mime_type_guesser]
318+
319+
.. code-block:: xml
320+
321+
<!-- config/services.xml -->
322+
<?xml version="1.0" encoding="UTF-8" ?>
323+
<container xmlns="http://symfony.com/schema/dic/services"
324+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
325+
xsi:schemaLocation="http://symfony.com/schema/dic/services
326+
https://symfony.com/schema/dic/services/services-1.0.xsd">
327+
328+
<services>
329+
<service id="App\SomeMimeTypeGuesser">
330+
<tag name="mime.mime_type_guesser"/>
331+
</service>
332+
</services>
333+
</container>
334+
335+
.. code-block:: php
336+
337+
// config/services.php
338+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
339+
340+
use App\SomeMimeTypeGuesser;
341+
342+
return function(ContainerConfigurator $configurator) {
343+
$services = $configurator->services();
344+
345+
$services->set(SomeMimeTypeGuesser::class)
346+
->tag('mime.mime_type_guesser');
347+
};
348+
349+
Note that this is already done for you if you use the :ref:`default services.yaml configuration <service-container-services-load-example>`
350+
thanks to :ref:`autoconfigure <services-autoconfigure>`.
351+
303352
.. _`MIME`: https://en.wikipedia.org/wiki/MIME
304353
.. _`MIME types`: https://en.wikipedia.org/wiki/Media_type
305354
.. _`fileinfo extension`: https://www.php.net/fileinfo

0 commit comments

Comments
 (0)