Augmentation vers version 3.3.0
This commit is contained in:
@@ -37,7 +37,7 @@ class ExtensionGuesser implements ExtensionGuesserInterface
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $guessers = array();
|
||||
protected $guessers = [];
|
||||
|
||||
/**
|
||||
* Returns the singleton instance.
|
||||
@@ -90,5 +90,7 @@ class ExtensionGuesser implements ExtensionGuesserInterface
|
||||
return $extension;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ class FileBinaryMimeTypeGuesser implements MimeTypeGuesserInterface
|
||||
*
|
||||
* @param string $cmd The command to run to get the mime type of a file
|
||||
*/
|
||||
public function __construct($cmd = 'file -b --mime %s 2>/dev/null')
|
||||
public function __construct($cmd = 'file -b --mime -- %s 2>/dev/null')
|
||||
{
|
||||
$this->cmd = $cmd;
|
||||
}
|
||||
@@ -74,24 +74,24 @@ class FileBinaryMimeTypeGuesser implements MimeTypeGuesserInterface
|
||||
}
|
||||
|
||||
if (!self::isSupported()) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
ob_start();
|
||||
|
||||
// need to use --mime instead of -i. see #6641
|
||||
passthru(sprintf($this->cmd, escapeshellarg($path)), $return);
|
||||
passthru(sprintf($this->cmd, escapeshellarg((0 === strpos($path, '-') ? './' : '').$path)), $return);
|
||||
if ($return > 0) {
|
||||
ob_end_clean();
|
||||
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
$type = trim(ob_get_clean());
|
||||
|
||||
if (!preg_match('#^([a-z0-9\-]+/[a-z0-9\-\.]+)#i', $type, $match)) {
|
||||
if (!preg_match('#^([a-z0-9\-]+/[a-z0-9\-\+\.]+)#i', $type, $match)) {
|
||||
// it's not a type, but an error message
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
return $match[1];
|
||||
|
||||
@@ -26,7 +26,7 @@ class FileinfoMimeTypeGuesser implements MimeTypeGuesserInterface
|
||||
/**
|
||||
* @param string $magicFile A magic file to use with the finfo instance
|
||||
*
|
||||
* @see http://www.php.net/manual/en/function.finfo-open.php
|
||||
* @see https://php.net/finfo-open
|
||||
*/
|
||||
public function __construct($magicFile = null)
|
||||
{
|
||||
@@ -57,11 +57,11 @@ class FileinfoMimeTypeGuesser implements MimeTypeGuesserInterface
|
||||
}
|
||||
|
||||
if (!self::isSupported()) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!$finfo = new \finfo(FILEINFO_MIME_TYPE, $this->magicFile)) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
return $finfo->file($path);
|
||||
|
||||
@@ -20,11 +20,11 @@ class MimeTypeExtensionGuesser implements ExtensionGuesserInterface
|
||||
* A map of mime types and their default extensions.
|
||||
*
|
||||
* This list has been placed under the public domain by the Apache HTTPD project.
|
||||
* This list has been updated from upstream on 2013-04-23.
|
||||
* This list has been updated from upstream on 2019-01-14.
|
||||
*
|
||||
* @see http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types
|
||||
* @see https://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types
|
||||
*/
|
||||
protected $defaultExtensions = array(
|
||||
protected $defaultExtensions = [
|
||||
'application/andrew-inset' => 'ez',
|
||||
'application/applixware' => 'aw',
|
||||
'application/atom+xml' => 'atom',
|
||||
@@ -618,7 +618,7 @@ class MimeTypeExtensionGuesser implements ExtensionGuesserInterface
|
||||
'audio/adpcm' => 'adp',
|
||||
'audio/basic' => 'au',
|
||||
'audio/midi' => 'mid',
|
||||
'audio/mp4' => 'mp4a',
|
||||
'audio/mp4' => 'm4a',
|
||||
'audio/mpeg' => 'mpga',
|
||||
'audio/ogg' => 'oga',
|
||||
'audio/s3m' => 's3m',
|
||||
@@ -653,6 +653,11 @@ class MimeTypeExtensionGuesser implements ExtensionGuesserInterface
|
||||
'chemical/x-cml' => 'cml',
|
||||
'chemical/x-csml' => 'csml',
|
||||
'chemical/x-xyz' => 'xyz',
|
||||
'font/collection' => 'ttc',
|
||||
'font/otf' => 'otf',
|
||||
'font/ttf' => 'ttf',
|
||||
'font/woff' => 'woff',
|
||||
'font/woff2' => 'woff2',
|
||||
'image/bmp' => 'bmp',
|
||||
'image/x-ms-bmp' => 'bmp',
|
||||
'image/cgm' => 'cgm',
|
||||
@@ -669,8 +674,8 @@ class MimeTypeExtensionGuesser implements ExtensionGuesserInterface
|
||||
'image/tiff' => 'tiff',
|
||||
'image/vnd.adobe.photoshop' => 'psd',
|
||||
'image/vnd.dece.graphic' => 'uvi',
|
||||
'image/vnd.dvb.subtitle' => 'sub',
|
||||
'image/vnd.djvu' => 'djvu',
|
||||
'image/vnd.dvb.subtitle' => 'sub',
|
||||
'image/vnd.dwg' => 'dwg',
|
||||
'image/vnd.dxf' => 'dxf',
|
||||
'image/vnd.fastbidsheet' => 'fbs',
|
||||
@@ -732,8 +737,8 @@ class MimeTypeExtensionGuesser implements ExtensionGuesserInterface
|
||||
'text/vcard' => 'vcard',
|
||||
'text/vnd.curl' => 'curl',
|
||||
'text/vnd.curl.dcurl' => 'dcurl',
|
||||
'text/vnd.curl.scurl' => 'scurl',
|
||||
'text/vnd.curl.mcurl' => 'mcurl',
|
||||
'text/vnd.curl.scurl' => 'scurl',
|
||||
'text/vnd.dvb.subtitle' => 'sub',
|
||||
'text/vnd.fly' => 'fly',
|
||||
'text/vnd.fmi.flexstor' => 'flx',
|
||||
@@ -743,13 +748,14 @@ class MimeTypeExtensionGuesser implements ExtensionGuesserInterface
|
||||
'text/vnd.sun.j2me.app-descriptor' => 'jad',
|
||||
'text/vnd.wap.wml' => 'wml',
|
||||
'text/vnd.wap.wmlscript' => 'wmls',
|
||||
'text/vtt' => 'vtt',
|
||||
'text/x-asm' => 's',
|
||||
'text/x-c' => 'c',
|
||||
'text/x-fortran' => 'f',
|
||||
'text/x-pascal' => 'p',
|
||||
'text/x-java-source' => 'java',
|
||||
'text/x-opml' => 'opml',
|
||||
'text/x-nfo' => 'nfo',
|
||||
'text/x-opml' => 'opml',
|
||||
'text/x-pascal' => 'p',
|
||||
'text/x-setext' => 'etx',
|
||||
'text/x-sfv' => 'sfv',
|
||||
'text/x-uuencode' => 'uu',
|
||||
@@ -795,13 +801,19 @@ class MimeTypeExtensionGuesser implements ExtensionGuesserInterface
|
||||
'video/x-sgi-movie' => 'movie',
|
||||
'video/x-smv' => 'smv',
|
||||
'x-conference/x-cooltalk' => 'ice',
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function guess($mimeType)
|
||||
{
|
||||
return isset($this->defaultExtensions[$mimeType]) ? $this->defaultExtensions[$mimeType] : null;
|
||||
if (isset($this->defaultExtensions[$mimeType])) {
|
||||
return $this->defaultExtensions[$mimeType];
|
||||
}
|
||||
|
||||
$lcMimeType = strtolower($mimeType);
|
||||
|
||||
return isset($this->defaultExtensions[$lcMimeType]) ? $this->defaultExtensions[$lcMimeType] : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ class MimeTypeGuesser implements MimeTypeGuesserInterface
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $guessers = array();
|
||||
protected $guessers = [];
|
||||
|
||||
/**
|
||||
* Returns the singleton instance.
|
||||
@@ -129,5 +129,7 @@ class MimeTypeGuesser implements MimeTypeGuesserInterface
|
||||
if (2 === \count($this->guessers) && !FileBinaryMimeTypeGuesser::isSupported() && !FileinfoMimeTypeGuesser::isSupported()) {
|
||||
throw new \LogicException('Unable to guess the mime type as no guessers are available (Did you enable the php_fileinfo extension?)');
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ interface MimeTypeGuesserInterface
|
||||
*
|
||||
* @param string $path The path to the file
|
||||
*
|
||||
* @return string The mime type or NULL, if none could be guessed
|
||||
* @return string|null The mime type or NULL, if none could be guessed
|
||||
*
|
||||
* @throws FileNotFoundException If the file does not exist
|
||||
* @throws AccessDeniedException If the file could not be read
|
||||
|
||||
28
vendor/symfony/http-foundation/File/Stream.php
vendored
Normal file
28
vendor/symfony/http-foundation/File/Stream.php
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\File;
|
||||
|
||||
/**
|
||||
* A PHP stream of unknown size.
|
||||
*
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
class Stream extends File
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSize()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -214,13 +214,26 @@ class UploadedFile extends File
|
||||
*/
|
||||
public static function getMaxFilesize()
|
||||
{
|
||||
$iniMax = strtolower(ini_get('upload_max_filesize'));
|
||||
$sizePostMax = self::parseFilesize(ini_get('post_max_size'));
|
||||
$sizeUploadMax = self::parseFilesize(ini_get('upload_max_filesize'));
|
||||
|
||||
if ('' === $iniMax) {
|
||||
return PHP_INT_MAX;
|
||||
return min($sizePostMax ?: PHP_INT_MAX, $sizeUploadMax ?: PHP_INT_MAX);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the given size from an ini value in bytes.
|
||||
*
|
||||
* @return int The given size in bytes
|
||||
*/
|
||||
private static function parseFilesize($size)
|
||||
{
|
||||
if ('' === $size) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$max = ltrim($iniMax, '+');
|
||||
$size = strtolower($size);
|
||||
|
||||
$max = ltrim($size, '+');
|
||||
if (0 === strpos($max, '0x')) {
|
||||
$max = \intval($max, 16);
|
||||
} elseif (0 === strpos($max, '0')) {
|
||||
@@ -229,7 +242,7 @@ class UploadedFile extends File
|
||||
$max = (int) $max;
|
||||
}
|
||||
|
||||
switch (substr($iniMax, -1)) {
|
||||
switch (substr($size, -1)) {
|
||||
case 't': $max *= 1024;
|
||||
// no break
|
||||
case 'g': $max *= 1024;
|
||||
@@ -249,7 +262,7 @@ class UploadedFile extends File
|
||||
*/
|
||||
public function getErrorMessage()
|
||||
{
|
||||
static $errors = array(
|
||||
static $errors = [
|
||||
UPLOAD_ERR_INI_SIZE => 'The file "%s" exceeds your upload_max_filesize ini directive (limit is %d KiB).',
|
||||
UPLOAD_ERR_FORM_SIZE => 'The file "%s" exceeds the upload limit defined in your form.',
|
||||
UPLOAD_ERR_PARTIAL => 'The file "%s" was only partially uploaded.',
|
||||
@@ -257,7 +270,7 @@ class UploadedFile extends File
|
||||
UPLOAD_ERR_CANT_WRITE => 'The file "%s" could not be written on disk.',
|
||||
UPLOAD_ERR_NO_TMP_DIR => 'File could not be uploaded: missing temporary directory.',
|
||||
UPLOAD_ERR_EXTENSION => 'File upload was stopped by a PHP extension.',
|
||||
);
|
||||
];
|
||||
|
||||
$errorCode = $this->error;
|
||||
$maxFilesize = UPLOAD_ERR_INI_SIZE === $errorCode ? self::getMaxFilesize() / 1024 : 0;
|
||||
|
||||
Reference in New Issue
Block a user