samsonasik/is-deprecated
Composer 安装命令:
composer require samsonasik/is-deprecated
包简介
Check PHP user and core function is deprecated
关键字:
README 文档
README
Introduction
IsDeprecated is PHP7 Helper that can help you detect if your function is deprecated with E_USER_DEPRECATED and E_DEPRECATED level.
Features
- Detect on independent function (E_USER_DEPRECATED)
- Detect on function inside class (E_USER_DEPRECATED)
- Detect on core php function (E_DEPRECATED)
Installation
Require uses composer:
composer require samsonasik/is-deprecated
Usage
There are 2 functions:
1. For user defined function
/** * @param string|array $function the "functionName" or ["ClassName" or object, "functionName"] or "ClassName::functionName" * @throws InvalidArgumentException when trigger_error found but the error is not E_USER_DEPRECATED * @throws InvalidArgumentException when trigger_error and E_USER_DEPRECATED found but misplaced * @return bool */ function isDeprecatedUser($function): bool
Note: when trigger_error E_USER_DEPRECATED inside condition, you need to use
actualcall with signature:
/** * @param callable $function callable function * @return bool */ function isDeprecatedWithActualCall(callable $function)
2. For core PHP function
/** * @param callable $function callable function * @return bool */ function isDeprecatedCore(callable $function): bool
Example On independent function
include 'vendor/autoload.php'; // autoload may already handled by your framework use function IsDeprecated\isDeprecatedUser; use function IsDeprecated\isDeprecatedWithActualCall; function foo() { trigger_error('this method has been deprecated.', E_USER_DEPRECATED); echo 'foo' . PHP_EOL; } function foonotdeprecated() { echo 'foo' . PHP_EOL; } function fooDeprecatedWithCondition() { if (1 === 1) { trigger_error('this method has been deprecated.', E_USER_DEPRECATED); echo 'foo' . PHP_EOL; } } // deprecated var_dump(isDeprecatedUser('foo')); // true OR for deprecate with condition var_dump(isDeprecatedWithActualCall(function () { fooDeprecatedWithCondition(); })); // true // not deprecated var_dump(isDeprecatedUser('foonotdeprecated')); // false // Usage Example: if (isDeprecatedUser('foo')) { foonotdeprecated();; } else { foo(); }
Example On function inside class
include 'vendor/autoload.php'; // autoload may already handled by your framework use function IsDeprecated\isDeprecatedUser; use function IsDeprecated\isDeprecatedWithActualCall; class Aclass { function foo() { trigger_error('this method has been deprecated.', E_USER_DEPRECATED); echo 'foo' . PHP_EOL; } function foodeprecatedWithCondition() { if (1 === 1) { trigger_error('this method has been deprecated.', E_USER_DEPRECATED); } echo 'foo' . PHP_EOL; } function foonotdeprecated() { echo 'foo' . PHP_EOL; } // you may call inside the class // with $this as first index of array parameter function execute() { if (isDeprecatedUser([$this, 'foo'])) { $this->foonotdeprecated(); return; } $this->foo(); } } // deprecated var_dump(isDeprecatedUser(['Aclass', 'foo'])); // true OR var_dump(isDeprecatedUser([new \Aclass(), 'foo'])); // true OR var_dump(isDeprecatedUser('Aclass::foo')); // true OR for deprecate with condition var_dump(isDeprecatedWithActualCall(function () { // true new \Aclass()->foo(); })); // not deprecated var_dump(isDeprecatedUser(['Aclass', 'foonotdeprecated'])); // false OR var_dump(isDeprecatedUser([new \Aclass, 'foonotdeprecated'])); // false OR var_dump(isDeprecatedUser('Aclass::foonotdeprecated')); // false // Usage Example: if (isDeprecatedUser(['Aclass', 'foo'])) { (new \Aclass())->foonotdeprecated();; } else { (new \Aclass())->foo();; }
Example On core PHP function
include 'vendor/autoload.php'; // autoload may already handled by your framework use function IsDeprecated\isDeprecatedCore; $function = function () { mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC); }; //on php 7.1 var_dump(isDeprecatedCore($function)); // true //on php 7.0 var_dump(isDeprecatedCore($function)); // false // Usage Example: if (isDeprecatedCore($function)) { // alternative function, eg: openssl ... } else { $function(); }
Limitation
For Core PHP Functions or user function with condition (T_IF or T_SWITCH token), the function passed actually need to be called. It ensure that we don't get error during call deprecated function, and we can use alternative function if the isDeprecatedCore() returns true with call of isDeprecatedWithActualCall.
Contributing
Contributions are very welcome. Please read CONTRIBUTING.md
samsonasik/is-deprecated 适用场景与选型建议
samsonasik/is-deprecated 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 16 次下载、GitHub Stars 达 2, 最近一次更新时间为 2017 年 02 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「check」 「deprecated」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 samsonasik/is-deprecated 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 samsonasik/is-deprecated 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 samsonasik/is-deprecated 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Symfony bundle for chameleon-system/sanitycheck
This Extension integrates a credit check and more made by the LEONEX Risk Management Platform into your order process. Extensive configuration and evaluation options is provided in the Platform
SoftWax Health Check Bundle for Symfony framework
DDump Bundle to dump and optionnaly exit
Check for holidays - localeaware
atoum extension to avoid failures on deprecated errors
统计信息
- 总下载量: 16
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 10
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-02-04