1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-30 21:40:43 +02:00

[ticket/11912] Introduce guesser priority to mimetype guessers

The mimetype guesser priority can now be set through the service definition.
Mimetypes will be guessed from the guesser with the highest priority to
the one with the lowest priority. Standard priority types have been added
to the service definition file. Any integer value can be used though.
Standard mimetype guessers that do not have the methods get_priority
and set_priority implemented, like the standard MimeTypeGuessers of symfony,
will have the default priority with the value of 0. Lower priority guessers
have values lower than 0 while high priority ones can be added with values
higher than 0.

PHPBB3-11912
This commit is contained in:
Marc Alexander
2013-11-11 21:18:23 +01:00
parent b1719db47d
commit bef6a5a640
7 changed files with 124 additions and 3 deletions

View File

@@ -135,4 +135,19 @@ class guesser_test extends \phpbb_test_case
$this->assertEquals($expected[1], $guesser->guess($this->jpg_file . '.jpg'));
@unlink($this->jpg_file . '.jpg');
}
public function test_sort_priority()
{
$guessers = array(
'FileinfoMimeTypeGuesser' => new \Symfony\Component\HttpFoundation\File\MimeType\FileinfoMimeTypeGuesser,
'extension_guesser' => new \phpbb\mimetype\extension_guesser,
'FileBinaryMimeTypeGuesser' => new \Symfony\Component\HttpFoundation\File\MimeType\FileBinaryMimeTypeGuesser,
'content_guesser' => new \phpbb\mimetype\content_guesser,
);
$guessers['content_guesser']->set_priority(5);
$guessers['extension_guesser']->set_priority(-5);
usort($guessers, array($this->guesser, 'sort_priority'));
$this->assertInstanceOf('\phpbb\mimetype\content_guesser', $guessers[0]);
$this->assertInstanceOf('\phpbb\mimetype\extension_guesser', $guessers[3]);
}
}