Skip to content

Commit

Permalink
minor symfony#13843 Fill out custom type guesser paragraph (l-vo)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
javiereguiluz committed Jun 15, 2020
2 parents 74f1eea + d6757d9 commit 9073de4
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion components/mime.rst
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ that extension to improve the guessing performance.
Adding a MIME Type Guesser
..........................

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

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

And registering it::

$mimeTypes = new MimeTypes();
$mimeTypes->registerGuesser(new SomeMimeTypeGuesser());

When using the Symfony fullstack Framework, you just need to add the ``mime.mime_type_guesser`` tag:

.. configuration-block::

.. code-block:: yaml
# config/services.yaml
services:
App\SomeMimeTypeGuesser:
tags: [mime.mime_type_guesser]
.. code-block:: xml
<!-- config/services.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services
https://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="App\SomeMimeTypeGuesser">
<tag name="mime.mime_type_guesser"/>
</service>
</services>
</container>
.. code-block:: php
// config/services.php
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
use App\SomeMimeTypeGuesser;
return function(ContainerConfigurator $configurator) {
$services = $configurator->services();
$services->set(SomeMimeTypeGuesser::class)
->tag('mime.mime_type_guesser');
};
Note that this is already done for you if you use the :ref:`default services.yaml configuration <service-container-services-load-example>`
thanks to :ref:`autoconfigure <services-autoconfigure>`.

.. _`MIME`: https://en.wikipedia.org/wiki/MIME
.. _`MIME types`: https://en.wikipedia.org/wiki/Media_type
.. _`fileinfo extension`: https://www.php.net/fileinfo

0 comments on commit 9073de4

Please sign in to comment.