Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
Zend_Validate_File_Hash Class Reference
Inheritance diagram for Zend_Validate_File_Hash:
Zend_Validate_Abstract Zend_Validate_Interface Zend_Validate_File_Crc32 Zend_Validate_File_Md5 Zend_Validate_File_Sha1

Public Member Functions

 __construct ($options)
 
 getHash ()
 
 setHash ($options)
 
 addHash ($options)
 
 isValid ($value, $file=null)
 
- Public Member Functions inherited from Zend_Validate_Abstract
 getMessages ()
 
 getMessageVariables ()
 
 getMessageTemplates ()
 
 setMessage ($messageString, $messageKey=null)
 
 setMessages (array $messages)
 
 __get ($property)
 
 getErrors ()
 
 setObscureValue ($flag)
 
 getObscureValue ()
 
 setTranslator ($translator=null)
 
 getTranslator ()
 
 hasTranslator ()
 
 setDisableTranslator ($flag)
 
 translatorIsDisabled ()
 
- Public Member Functions inherited from Zend_Validate_Interface
 isValid ($value)
 

Data Fields

const DOES_NOT_MATCH = 'fileHashDoesNotMatch'
 
const NOT_DETECTED = 'fileHashHashNotDetected'
 
const NOT_FOUND = 'fileHashNotFound'
 

Protected Member Functions

 _throw ($file, $errorType)
 
- Protected Member Functions inherited from Zend_Validate_Abstract
 _createMessage ($messageKey, $value)
 
 _implodeRecursive (array $pieces)
 
 _error ($messageKey, $value=null)
 
 _setValue ($value)
 

Protected Attributes

 $_messageTemplates
 
 $_hash
 
- Protected Attributes inherited from Zend_Validate_Abstract
 $_value
 
 $_messageVariables = array()
 
 $_messageTemplates = array()
 
 $_messages = array()
 
 $_obscureValue = false
 
 $_errors = array()
 
 $_translator
 
 $_translatorDisabled = false
 

Additional Inherited Members

- Static Public Member Functions inherited from Zend_Validate_Abstract
static setDefaultTranslator ($translator=null)
 
static getDefaultTranslator ()
 
static hasDefaultTranslator ()
 
static getMessageLength ()
 
static setMessageLength ($length=-1)
 
- Static Protected Attributes inherited from Zend_Validate_Abstract
static $_defaultTranslator
 
static $_messageLength = -1
 

Detailed Description

Definition at line 35 of file Hash.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $options)

Sets validator options

Parameters
string | array$options
Exceptions
Zend_Validate_Exception

Definition at line 66 of file Hash.php.

67  {
68  if ($options instanceof Zend_Config) {
69  $options = $options->toArray();
70  } elseif (is_scalar($options)) {
71  $options = array('hash1' => $options);
72  } elseif (!is_array($options)) {
73  #require_once 'Zend/Validate/Exception.php';
74  throw new Zend_Validate_Exception('Invalid options to validator provided');
75  }
76 
77  if (1 < func_num_args()) {
78  $options['algorithm'] = func_get_arg(1);
79  }
80 
81  $this->setHash($options);
82  }
setHash($options)
Definition: Hash.php:100
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17

Member Function Documentation

◆ _throw()

_throw (   $file,
  $errorType 
)
protected

Throws an error of the given type

Parameters
string$file
string$errorType
Returns
false

Definition at line 186 of file Hash.php.

187  {
188  if ($file !== null) {
189  $this->_value = $file['name'];
190  }
191 
192  $this->_error($errorType);
193  return false;
194  }
_error($messageKey, $value=null)
Definition: Abstract.php:284

◆ addHash()

addHash (   $options)

Adds the hash for one or multiple files

Parameters
string | array$options
Exceptions
Zend_Validate_Exception
Returns
Zend_Validate_File_Hash Provides a fluent interface

Definition at line 115 of file Hash.php.

116  {
117  if (is_string($options)) {
118  $options = array($options);
119  } else if (!is_array($options)) {
120  #require_once 'Zend/Validate/Exception.php';
121  throw new Zend_Validate_Exception("False parameter given");
122  }
123 
124  $known = hash_algos();
125  if (!isset($options['algorithm'])) {
126  $algorithm = 'crc32';
127  } else {
128  $algorithm = $options['algorithm'];
129  unset($options['algorithm']);
130  }
131 
132  if (!in_array($algorithm, $known)) {
133  #require_once 'Zend/Validate/Exception.php';
134  throw new Zend_Validate_Exception("Unknown algorithm '{$algorithm}'");
135  }
136 
137  foreach ($options as $value) {
138  $this->_hash[$value] = $algorithm;
139  }
140 
141  return $this;
142  }
$value
Definition: gender.phtml:16

◆ getHash()

getHash ( )

Returns the set hash values as array, the hash as key and the algorithm the value

Returns
array

Definition at line 89 of file Hash.php.

90  {
91  return $this->_hash;
92  }

◆ isValid()

isValid (   $value,
  $file = null 
)

Defined by Zend_Validate_Interface

Returns true if and only if the given file confirms the set hash

Parameters
string$valueFilename to check for hash
array$fileFile data from Zend_File_Transfer
Returns
boolean

Definition at line 153 of file Hash.php.

154  {
155  // Is file readable ?
156  #require_once 'Zend/Loader.php';
158  return $this->_throw($file, self::NOT_FOUND);
159  }
160 
161  $algos = array_unique(array_values($this->_hash));
162  $hashes = array_unique(array_keys($this->_hash));
163  foreach ($algos as $algorithm) {
164  $filehash = hash_file($algorithm, $value);
165  if ($filehash === false) {
166  return $this->_throw($file, self::NOT_DETECTED);
167  }
168 
169  foreach($hashes as $hash) {
170  if ($filehash === $hash) {
171  return true;
172  }
173  }
174  }
175 
176  return $this->_throw($file, self::DOES_NOT_MATCH);
177  }
static isReadable($filename)
Definition: Loader.php:162
$value
Definition: gender.phtml:16
_throw($file, $errorType)
Definition: Hash.php:186

◆ setHash()

setHash (   $options)

Sets the hash for one or multiple files

Parameters
string | array$options
Returns
Zend_Validate_File_Hash Provides a fluent interface

Definition at line 100 of file Hash.php.

101  {
102  $this->_hash = null;
103  $this->addHash($options);
104 
105  return $this;
106  }
addHash($options)
Definition: Hash.php:115

Field Documentation

◆ $_hash

$_hash
protected

Definition at line 58 of file Hash.php.

◆ $_messageTemplates

$_messageTemplates
protected
Initial value:
= array(
self::DOES_NOT_MATCH => "File '%value%' does not match the given hashes",
self::NOT_DETECTED => "A hash could not be evaluated for the given file",
self::NOT_FOUND => "File '%value%' is not readable or does not exist"
)

Definition at line 47 of file Hash.php.

◆ DOES_NOT_MATCH

const DOES_NOT_MATCH = 'fileHashDoesNotMatch'

@const string Error constants

Definition at line 40 of file Hash.php.

◆ NOT_DETECTED

const NOT_DETECTED = 'fileHashHashNotDetected'

Definition at line 41 of file Hash.php.

◆ NOT_FOUND

const NOT_FOUND = 'fileHashNotFound'

Definition at line 42 of file Hash.php.


The documentation for this class was generated from the following file: