Skip to content
This repository has been archived by the owner on May 24, 2018. It is now read-only.

Latest commit

 

History

History
73 lines (43 loc) · 1.82 KB

zend.validator.file.hash.rst

File metadata and controls

73 lines (43 loc) · 1.82 KB

Hash

Zend\Validator\File\Hash allows you to validate if a given file's hashed contents matches the supplied hash(es) and algorithm(s).

Note

This validator requires the Hash extension from PHP. A list of supported hash algorithms can be found with the hash_algos() function.

Supported Options

The following set of options are supported:

  • hash (string)

    Hash to test the file against.

  • algorithm (string) default: "crc32"

    Algorithm to use for the hashing validation.

Usage Examples

// Does file have the given hash?
$validator = new \Zend\Validator\File\Hash('3b3652f', 'crc32');

// Or, check file against multiple hashes
$validator = new \Zend\Validator\File\Hash(array('3b3652f', 'e612b69'), 'crc32');

// Perform validation with file path
if ($validator->isValid('./myfile.txt')) {
   // file is valid
}

Public Methods

getHash()

Returns the current set of hashes.

rtype

array

addHash(string|array $options)

Adds a hash for one or multiple files to the internal set of hashes.

param $options

See Supported Options <zend.validator.file.hash.options> section for more information.

setHash(string|array $options)

Sets a hash for one or multiple files. Removes any previously set hashes.

param $options

See Supported Options <zend.validator.file.hash.options> section for more information.