damess/zf2-hashids
Composer 安装命令:
composer require damess/zf2-hashids
包简介
Zend Framework 2 module for hashids allowing you to obfuscate ID's in your API
README 文档
README
Full documentation
This is a Zend Framework 2 module for the PHP Hashids library. See the full documentation of the library at http://hashids.org/php.
Requirements
- PHP 5.3.3 or higher
- Zend Framework 2.1 onwards
(Optional) GNU Multiple Precision or BCMath to allow integers greater than 1,000,000,000 to be encoded. See https://github.com/ivanakimov/hashids.php for more information.
Installation using Composer
composer require damess/zf2-hashids
Add the module to ./config/application.config.php
<?php return array( 'modules' => array( 'Application', 'DaMess\Hashids', ), ... );
Options
The Hashids module has some options to allow you to quickly change the configuration. After installing the module, copy ./vendor/damess/zf2-hashids/config/hashids.global.php.dist to ./config/autoload/hashids.global.php and change the values as required.
- salt - Default value of ''. This is the value used when encoding an ID into a hash. Note: Please do not change this value once it's been set.
- min_length - Default value of 22. This defines the minimum length of the encoded hash value.
- alphabet - Default value of 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'. The alphabet used when encoding an ID. This must be at least 16 characters long and not contain any spaces.
<?php return array( 'hashids' => array( /* * The salt to use for encryption * NOTE: Do not change this once it's been set */ 'salt' => '', /* * Minimum length of the generated hash */ 'min_length' => 22, /* * Define which characters are used when building the hash */ 'alphabet' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890', ), );
Usage
This module provides a HashidsService and a controller plugin, see below for examples of use.
HashidsService
The HashidsService can be retrieved from the ServiceManager.
Inside a factory implementing Zend\ServiceManager\FactoryInterace
<?php $service = $serviceLocator->get('DaMess\Hashids\Service\HashidsService'); $service->encode(1); // 39J4q2VolejRejNmGQBW71 (assuming default config values) $service->decode('39J4q2VolejRejNmGQBW71'); // array(1) (assuming default config values)
Inside a controller or class implementing Zend\ServiceManager\ServiceLocatorAwareInterface that's been retrieved from the ServiceManager
<?php $service = $this->getServiceLocator()->get('DaMess\Hashids\Service\HashidsService'); $service->encode(1); // 39J4q2VolejRejNmGQBW71 (assuming default config values) $service->decode('39J4q2VolejRejNmGQBW71'); // array(1) (assuming default config values)
Controller plugin
The Hashids module provides a hashids controller plugin. This is how it can be used
<?php namespace Application\Controller; use Zend\Mvc\Controller\AbstractActionController; use Zend\View\Model\ViewModel; class IndexController extends AbstractActionController { public function indexAction() { return new ViewModel(array( 'hash' => $this->hashids()->encode(1), // 39J4q2VolejRejNmGQBW71 'id' => $this->hashids()->decode('39J4q2VolejRejNmGQBW71'), // array(1) )); } }
damess/zf2-hashids 适用场景与选型建议
damess/zf2-hashids 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.65k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2015 年 09 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「zend」 「zf2」 「zend framework 2」 「hashids」 「obfuscate」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 damess/zf2-hashids 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 damess/zf2-hashids 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 damess/zf2-hashids 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Framework HLEB2 is the foundation of the web application. Provides ease of development and application performance.
LosLog provides some log utility
EdpModuleLayouts is very simple Laminas module for making module-specific layouts insanely easy.
Polyfill for mb_ereg(), mb_eregi(), mb_ereg_match(), and mb_ereg_replace*() functions; primary use case is for mbstring on Windows 7.4+
Zend Framework module to leverage the symfony dependency injection container
RCM User HTML views/pages
统计信息
- 总下载量: 1.65k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 15
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-09-10