Skip to content

Commit

Permalink
Fix zendframework#165 - Use is_readable() instead of stream_resolve_i…
Browse files Browse the repository at this point in the history
…nclude_path()
  • Loading branch information
larsnystrom committed May 23, 2017
1 parent 438b3a6 commit 33591b6
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 38 deletions.
4 changes: 2 additions & 2 deletions src/File/Crc32.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ public function isValid($value, $file = null)
$this->setValue($filename);

// Is file readable ?
if (empty($file) || false === stream_resolve_include_path($file)) {
if (empty($file) || false === is_readable($file)) {
$this->error(self::NOT_FOUND);
return false;
}

$hashes = array_unique(array_keys($this->getHash()));
$hashes = array_unique(array_keys($this->getHash()));
$filehash = hash_file('crc32', $file);
if ($filehash === false) {
$this->error(self::NOT_DETECTED);
Expand Down
2 changes: 1 addition & 1 deletion src/File/ExcludeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function isValid($value, $file = null)
$this->setValue($filename);

// Is file readable ?
if (empty($file) || false === stream_resolve_include_path($file)) {
if (empty($file) || false === is_readable($file)) {
$this->error(self::NOT_FOUND);
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/File/ExcludeMimeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function isValid($value, $file = null)
$this->setValue($filename);

// Is file readable ?
if (empty($file) || false === stream_resolve_include_path($file)) {
if (empty($file) || false === is_readable($file)) {
$this->error(self::NOT_READABLE);
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/File/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public function isValid($value, $file = null)
$this->setValue($filename);

// Is file readable ?
if (empty($file) || false === stream_resolve_include_path($file)) {
if (empty($file) || false === is_readable($file)) {
$this->error(self::NOT_FOUND);
return false;
}
Expand Down
12 changes: 6 additions & 6 deletions src/File/FilesSize.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ public function isValid($value, $file = null)
'Value array must be in $_FILES format'
);
}
$file = $files;
$file = $files;
$files = $files['tmp_name'];
}

// Is file readable ?
if (empty($files) || false === stream_resolve_include_path($files)) {
if (empty($files) || false === is_readable($files)) {
$this->throwError($file, self::NOT_READABLE);
continue;
}
Expand All @@ -128,10 +128,10 @@ public function isValid($value, $file = null)
if (($max !== null) && ($max < $size)) {
if ($this->getByteString()) {
$this->options['max'] = $this->toByteString($max);
$this->size = $this->toByteString($size);
$this->size = $this->toByteString($size);
$this->throwError($file, self::TOO_BIG);
$this->options['max'] = $max;
$this->size = $size;
$this->size = $size;
} else {
$this->throwError($file, self::TOO_BIG);
}
Expand All @@ -142,10 +142,10 @@ public function isValid($value, $file = null)
if (($min !== null) && ($size < $min)) {
if ($this->getByteString()) {
$this->options['min'] = $this->toByteString($min);
$this->size = $this->toByteString($size);
$this->size = $this->toByteString($size);
$this->throwError($file, self::TOO_SMALL);
$this->options['min'] = $min;
$this->size = $size;
$this->size = $size;
} else {
$this->throwError($file, self::TOO_SMALL);
}
Expand Down
4 changes: 2 additions & 2 deletions src/File/Hash.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ public function setHash($options)
* Adds the hash for one or multiple files
*
* @param string|array $options
* @return Hash Provides a fluent interface
* @throws Exception\InvalidArgumentException
* @return Hash Provides a fluent interface
*/
public function addHash($options)
{
Expand Down Expand Up @@ -148,7 +148,7 @@ public function isValid($value, $file = null)
$this->setValue($filename);

// Is file readable ?
if (empty($file) || false === stream_resolve_include_path($file)) {
if (empty($file) || false === is_readable($file)) {
$this->error(self::NOT_FOUND);
return false;
}
Expand Down
10 changes: 5 additions & 5 deletions src/File/ImageSize.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ public function getMinWidth()
* Sets the minimum allowed width
*
* @param int $minWidth
* @return ImageSize Provides a fluid interface
* @throws Exception\InvalidArgumentException When minwidth is greater than maxwidth
* @return ImageSize Provides a fluid interface
*/
public function setMinWidth($minWidth)
{
Expand Down Expand Up @@ -154,8 +154,8 @@ public function getMaxWidth()
* Sets the maximum allowed width
*
* @param int $maxWidth
* @return ImageSize Provides a fluid interface
* @throws Exception\InvalidArgumentException When maxwidth is less than minwidth
* @return ImageSize Provides a fluid interface
*/
public function setMaxWidth($maxWidth)
{
Expand Down Expand Up @@ -184,8 +184,8 @@ public function getMinHeight()
* Sets the minimum allowed height
*
* @param int $minHeight
* @return ImageSize Provides a fluid interface
* @throws Exception\InvalidArgumentException When minheight is greater than maxheight
* @return ImageSize Provides a fluid interface
*/
public function setMinHeight($minHeight)
{
Expand Down Expand Up @@ -214,8 +214,8 @@ public function getMaxHeight()
* Sets the maximum allowed height
*
* @param int $maxHeight
* @return ImageSize Provides a fluid interface
* @throws Exception\InvalidArgumentException When maxheight is less than minheight
* @return ImageSize Provides a fluid interface
*/
public function setMaxHeight($maxHeight)
{
Expand Down Expand Up @@ -351,7 +351,7 @@ public function isValid($value, $file = null)
$this->setValue($filename);

// Is file readable ?
if (empty($file) || false === stream_resolve_include_path($file)) {
if (empty($file) || false === is_readable($file)) {
$this->error(self::NOT_READABLE);
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/File/Md5.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ public function isValid($value, $file = null)
$this->setValue($filename);

// Is file readable ?
if (empty($file) || false === stream_resolve_include_path($file)) {
if (empty($file) || false === is_readable($file)) {
$this->error(self::NOT_FOUND);
return false;
}

$hashes = array_unique(array_keys($this->getHash()));
$hashes = array_unique(array_keys($this->getHash()));
$filehash = hash_file('md5', $file);
if ($filehash === false) {
$this->error(self::NOT_DETECTED);
Expand Down
6 changes: 3 additions & 3 deletions src/File/MimeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,10 @@ public function getMagicFile()
* if false, the default MAGIC file from PHP will be used
*
* @param string $file
* @return MimeType Provides fluid interface
* @throws Exception\RuntimeException When finfo can not read the magicfile
* @throws Exception\InvalidArgumentException
* @throws Exception\InvalidMagicMimeFileException
* @return MimeType Provides fluid interface
*/
public function setMagicFile($file)
{
Expand Down Expand Up @@ -291,8 +291,8 @@ public function setMimeType($mimetype)
* Adds the mimetypes
*
* @param string|array $mimetype The mimetypes to add for validation
* @return MimeType Provides a fluent interface
* @throws Exception\InvalidArgumentException
* @return MimeType Provides a fluent interface
*/
public function addMimeType($mimetype)
{
Expand Down Expand Up @@ -363,7 +363,7 @@ public function isValid($value, $file = null)
$this->setValue($filename);

// Is file readable ?
if (empty($file) || false === stream_resolve_include_path($file)) {
if (empty($file) || false === is_readable($file)) {
$this->error(static::NOT_READABLE);
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/File/Sha1.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ public function isValid($value, $file = null)
$this->setValue($filename);

// Is file readable ?
if (empty($file) || false === stream_resolve_include_path($file)) {
if (empty($file) || false === is_readable($file)) {
$this->error(self::NOT_FOUND);
return false;
}

$hashes = array_unique(array_keys($this->getHash()));
$hashes = array_unique(array_keys($this->getHash()));
$filehash = hash_file('sha1', $file);
if ($filehash === false) {
$this->error(self::NOT_DETECTED);
Expand Down
14 changes: 7 additions & 7 deletions src/File/Size.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ public function getMin($raw = false)
* For example: 2000, 2MB, 0.2GB
*
* @param int|string $min The minimum file size
* @return Size Provides a fluent interface
* @throws Exception\InvalidArgumentException When min is greater than max
* @return Size Provides a fluent interface
*/
public function setMin($min)
{
Expand Down Expand Up @@ -181,8 +181,8 @@ public function getMax($raw = false)
* For example: 2000, 2MB, 0.2GB
*
* @param int|string $max The maximum file size
* @return Size Provides a fluent interface
* @throws Exception\InvalidArgumentException When max is smaller than min
* @return Size Provides a fluent interface
*/
public function setMax($max)
{
Expand Down Expand Up @@ -253,7 +253,7 @@ public function isValid($value, $file = null)
$this->setValue($filename);

// Is file readable ?
if (empty($file) || false === stream_resolve_include_path($file)) {
if (empty($file) || false === is_readable($file)) {
$this->error(self::NOT_FOUND);
return false;
}
Expand All @@ -270,10 +270,10 @@ public function isValid($value, $file = null)
if (($min !== null) && ($size < $min)) {
if ($this->getByteString()) {
$this->options['min'] = $this->toByteString($min);
$this->size = $this->toByteString($size);
$this->size = $this->toByteString($size);
$this->error(self::TOO_SMALL);
$this->options['min'] = $min;
$this->size = $size;
$this->size = $size;
} else {
$this->error(self::TOO_SMALL);
}
Expand All @@ -283,10 +283,10 @@ public function isValid($value, $file = null)
if (($max !== null) && ($max < $size)) {
if ($this->getByteString()) {
$this->options['max'] = $this->toByteString($max);
$this->size = $this->toByteString($size);
$this->size = $this->toByteString($size);
$this->error(self::TOO_BIG);
$this->options['max'] = $max;
$this->size = $size;
$this->size = $size;
} else {
$this->error(self::TOO_BIG);
}
Expand Down
12 changes: 6 additions & 6 deletions src/File/WordCount.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class WordCount extends AbstractValidator
* @var array Error message templates
*/
protected $messageTemplates = [
self::TOO_MUCH => "Too many words, maximum '%max%' are allowed but '%count%' were counted",
self::TOO_LESS => "Too few words, minimum '%min%' are expected but '%count%' were counted",
self::TOO_MUCH => "Too many words, maximum '%max%' are allowed but '%count%' were counted",
self::TOO_LESS => "Too few words, minimum '%min%' are expected but '%count%' were counted",
self::NOT_FOUND => "File is not readable or does not exist",
];

Expand Down Expand Up @@ -75,7 +75,7 @@ class WordCount extends AbstractValidator
public function __construct($options = null)
{
if (1 < func_num_args()) {
$args = func_get_args();
$args = func_get_args();
$options = [
'min' => array_shift($args),
'max' => array_shift($args),
Expand Down Expand Up @@ -103,8 +103,8 @@ public function getMin()
* Sets the minimum word count
*
* @param int|array $min The minimum word count
* @return WordCount Provides a fluent interface
* @throws Exception\InvalidArgumentException When min is greater than max
* @return WordCount Provides a fluent interface
*/
public function setMin($min)
{
Expand Down Expand Up @@ -141,8 +141,8 @@ public function getMax()
* Sets the maximum file count
*
* @param int|array $max The maximum word count
* @return WordCount Provides a fluent interface
* @throws Exception\InvalidArgumentException When max is smaller than min
* @return WordCount Provides a fluent interface
*/
public function setMax($max)
{
Expand Down Expand Up @@ -194,7 +194,7 @@ public function isValid($value, $file = null)
$this->setValue($filename);

// Is file readable ?
if (empty($file) || false === stream_resolve_include_path($file)) {
if (empty($file) || false === is_readable($file)) {
$this->error(self::NOT_FOUND);
return false;
}
Expand Down

0 comments on commit 33591b6

Please sign in to comment.