devhelp/hash
Composer 安装命令:
composer require devhelp/hash
包简介
Introduces HashGenerator class that can be used to register and use different hash algorithms
关键字:
README 文档
README
Installation
Composer is preferred to install Devhelp/Hash, please check composer website for more information.
$ composer require 'devhelp/hash:dev-master'
Purpose
Devhelp/Hash introduces HashGenerator class that can be used to register and use different hash algorithms. It supports all PHP core hash algorithms by default, but you can register custom ones as \Closure or Devhelp\Hash\Algorithm\HashAlgorithmInterface
Usage
Using built-in php core algorithms
it uses hash function under the hood
$generator = new \Devhelp\Hash\HashGenerator();
$generator->generate('sha256', 'some_data'); // returns hash generated by sha256 algorithm
$generator->generate('sha256', 'some_data', array('raw_output' => true);
Registering custom algorithms
class CustomHashAlgorithm implements \Devhelp\Hash\Algorithm\HashAlgorithmInterface
{
public function hash($data, array $options = array())
{
//...
}
}
$myAlgorithm = new CustomHashAlgorithm();
$myClosure = function ($data, $options) {
//...
};
$generator = new \Devhelp\Hash\HashGenerator();
$generator->register('my_algorithm', $myAlgorithm);
$generator->register('my_closure', $myClosure);
$generator->generate('my_algorithm', 'some_data'); //returns hash generated by CustomHashAlgorithm class
$generator->generate('my_closure', 'some_data'); //returns hash generated by $myClosure \Closure
Overriding built-in PHP core algorithms
Only thing to do is to define custom algorithm and register in under the same name as the core algorithm
$generator = new \Devhelp\Hash\HashGenerator();
$generator->register('sha512', new CustomHashAlgorithm());
$generator->generate('sha512', $data); //returns hash generated by CustomHashAlgorithm class
Credits
Brought to you by : Devhelp.pl
统计信息
- 总下载量: 47
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-05-18