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

Commit

Permalink
Merge commit 'refs/pull/2936/head' of github.com:zendframework/zf2 in…
Browse files Browse the repository at this point in the history
…to hotfix/ssl-case-sensitive
  • Loading branch information
Show file tree
Hide file tree
Showing 43 changed files with 1,698 additions and 2,233 deletions.
252 changes: 0 additions & 252 deletions src/File/Count.php

This file was deleted.

38 changes: 26 additions & 12 deletions src/File/Crc32.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

namespace Zend\Validator\File;

use Zend\Validator\Exception;

/**
* Validator for the crc32 hash of given files
*
Expand All @@ -29,9 +31,9 @@ class Crc32 extends Hash
* @var array Error message templates
*/
protected $messageTemplates = array(
self::DOES_NOT_MATCH => "File '%value%' does not match the given crc32 hashes",
self::DOES_NOT_MATCH => "File does not match the given crc32 hashes",
self::NOT_DETECTED => "A crc32 hash could not be evaluated for the given file",
self::NOT_FOUND => "File '%value%' is not readable or does not exist",
self::NOT_FOUND => "File is not readable or does not exist",
);

/**
Expand Down Expand Up @@ -81,25 +83,36 @@ public function addCrc32($options)
/**
* Returns true if and only if the given file confirms the set hash
*
* @param string $value Filename to check for hash
* @param array $file File data from \Zend\File\Transfer\Transfer
* @param string|array $value Filename to check for hash
* @return boolean
*/
public function isValid($value, $file = null)
public function isValid($value)
{
if ($file === null) {
$file = array('name' => basename($value));
if (is_array($value)) {
if (!isset($value['tmp_name']) || !isset($value['name'])) {
throw new Exception\InvalidArgumentException(
'Value array must be in $_FILES format'
);
}
$file = $value['tmp_name'];
$filename = $value['name'];
} else {
$file = $value;
$filename = basename($file);
}
$this->setValue($filename);

// Is file readable ?
if (false === stream_resolve_include_path($value)) {
return $this->throwError($file, self::NOT_FOUND);
if (false === stream_resolve_include_path($file)) {
$this->error(self::NOT_FOUND);
return false;
}

$hashes = array_unique(array_keys($this->getHash()));
$filehash = hash_file('crc32', $value);
$filehash = hash_file('crc32', $file);
if ($filehash === false) {
return $this->throwError($file, self::NOT_DETECTED);
$this->error(self::NOT_DETECTED);
return false;
}

foreach ($hashes as $hash) {
Expand All @@ -108,6 +121,7 @@ public function isValid($value, $file = null)
}
}

return $this->throwError($file, self::DOES_NOT_MATCH);
$this->error(self::DOES_NOT_MATCH);
return false;
}
}
Loading

0 comments on commit 53a840e

Please sign in to comment.