Skip to content

[2.3][HttpFoundation] Allow MimeTypeGuesser to be constructed and customized outside of the singleton scope#7415

Closed
romainneutron wants to merge 1 commit intosymfony:masterfrom
romainneutron:mimetype-guesser
Closed

[2.3][HttpFoundation] Allow MimeTypeGuesser to be constructed and customized outside of the singleton scope#7415
romainneutron wants to merge 1 commit intosymfony:masterfrom
romainneutron:mimetype-guesser

Conversation

@romainneutron
Copy link
Copy Markdown
Contributor

Q A
Bug fix? yes
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #5615
License MIT

Allow singleton customization with the method defineAsInstance.

For example, to use a unique CustomMimeTypeGuesser :

$guesser = new MimeTypeGuesser();
$guesser->register(new CustomMimeTypeGuesser());
$guesser->defineAsInstance();

the following call to MimeTypeGuesser::getInstance(); will return the previously defined $guesser.

Allow singleton customization with the method `defineAsInstance`.
@fabpot
Copy link
Copy Markdown
Member

fabpot commented Apr 23, 2013

Re-reading the code now, I think what you are trying to achieve is already possible without any modifications:

MimeTypeGuesser::getInstance()->register(new CustomMimeTypeGuesser());

As register always add the guesser before existing one, the custom guesser will always be called instead of the default ones. Am I missing something here?

fabpot added a commit that referenced this pull request Apr 23, 2013
This PR was merged into the master branch.

Discussion
----------

[WIP][HttpFoundation] File mime types and extensions

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #5039, #6963, #5258, #7415, #5615
| License       | MIT
| Doc PR        | n/a

This pull request addresses most of the issues regarding mime types and extension on File instances.

I've also created an issue on the docs to add more documentation about how things work (see symfony/symfony-docs#2542).

Commits
-------

acc2b6a [HttpFoundation] updated the list of known mime types (sync from Apache)
f85cdd2 [HttpFoundation] fixed phpdoc
1aa68da [HttpFoundation] added a way to inject a custom magic file into FileinfoMimeTypeGuesser (closes #6963)
29b5413 [HttpFoundation] added some more phpdocs to clarify usage
ee784fb clarified how/when to use client or guessed mime-types and extensions on a File instance (closes #5039)
@fabpot fabpot closed this Apr 23, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants