Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Merge pull request zendframework/zendframework#4102 from sasezaki/val…
Browse files Browse the repository at this point in the history
…idator_fileinfo_simplify_constants

simplify constant usage. FILEINFO_MIME_TYPE is available since PHP 5.3.0
  • Loading branch information
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
5 changes: 2 additions & 3 deletions src/File/ExcludeMimeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,12 @@ public function isValid($value, $file = null)

$mimefile = $this->getMagicFile();
if (class_exists('finfo', false)) {
$const = defined('FILEINFO_MIME_TYPE') ? FILEINFO_MIME_TYPE : FILEINFO_MIME;
if (!$this->isMagicFileDisabled() && (!empty($mimefile) && empty($this->finfo))) {
$this->finfo = finfo_open($const, $mimefile);
$this->finfo = finfo_open(FILEINFO_MIME_TYPE, $mimefile);
}

if (empty($this->finfo)) {
$this->finfo = finfo_open($const);
$this->finfo = finfo_open(FILEINFO_MIME_TYPE);
}

$this->type = null;
Expand Down
8 changes: 3 additions & 5 deletions src/File/MimeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,8 @@ public function setMagicFile($file)
$file
));
} else {
$const = defined('FILEINFO_MIME_TYPE') ? FILEINFO_MIME_TYPE : FILEINFO_MIME;
ErrorHandler::start(E_NOTICE|E_WARNING);
$this->finfo = finfo_open($const, $file);
$this->finfo = finfo_open(FILEINFO_MIME_TYPE, $file);
$error = ErrorHandler::stop();
if (empty($this->finfo)) {
$this->finfo = null;
Expand Down Expand Up @@ -376,16 +375,15 @@ public function isValid($value, $file = null)

$mimefile = $this->getMagicFile();
if (class_exists('finfo', false)) {
$const = defined('FILEINFO_MIME_TYPE') ? FILEINFO_MIME_TYPE : FILEINFO_MIME;
if (!$this->isMagicFileDisabled() && (!empty($mimefile) && empty($this->finfo))) {
ErrorHandler::start(E_NOTICE|E_WARNING);
$this->finfo = finfo_open($const, $mimefile);
$this->finfo = finfo_open(FILEINFO_MIME_TYPE, $mimefile);
ErrorHandler::stop();
}

if (empty($this->finfo)) {
ErrorHandler::start(E_NOTICE|E_WARNING);
$this->finfo = finfo_open($const);
$this->finfo = finfo_open(FILEINFO_MIME_TYPE);
ErrorHandler::stop();
}

Expand Down

0 comments on commit 89a20a8

Please sign in to comment.