brightnucleus/phpfeature
Composer 安装命令:
composer require brightnucleus/phpfeature
包简介
PHP Feature Detection Library
README 文档
README
PHPFeature is a first draft of a PHP Feature Detection Library similar to what Modernizr does for the browser features. So, instead of checking for a specific PHP version number (which forces you to know which and compare which features were introduced by which versions), you can simply tell the library what features you need, and it will tell you with a simple boolean value whether these are supported or not.
You can read more background information here: http://www.alainschlesser.com/php-feature/
Table Of Contents
Requirements
To develop using the library, you will need PHP 5.3.2+, as it uses Composer to manage its dependencies.
However, the runtime code only requires PHP 5.2+, as one of the goals was to make it useful for WordPress development.
Installation
To include the library in your project, you can use Composer:
composer require brightnucleus/phpfeature
Alternatively, you can copy the classes inside of your application and make sure that your application can find them.
Basic Usage
Usage is pretty simple, it only comes with two methods so far.
public function is_supported( $features );
This returns a boolean value telling you whether all of the features that you passed in are supported by the current PHP version.
public function get_minimum_required( $features );
This returns a SemanticVersion object that contains the minimum PHP version that supports all of the features that you passed in.
Here’s an example of how to use it to stop execution and inform the user:
// Array of strings to define what features you need. $features = array( 'namespaces', 'traits' ); // Instantiate the PHPFeature library. // When you don't provide a version number as the first argument, // the version of the currently used PHP interpreter is fetched. $php = new PHPFeature(); // Check whether all of the features are supported. If not... if ( ! $php->is_supported( $features ) ) { // ... throw exception and let user know the minimum needed. throw new RuntimeException( sprintf( 'Your PHP interpreter does not support some features needed to run this application. Please upgrade to version %1$s or newer.', $php->get_minimum_required( $features ) ) ); }
Known Issues
-
The library currently uses PHP's
version_compare()to make the actual comparison. This should probably be done by a real SemVer comparison algorithm. -
The list of features is not yet exhaustive. There should also be some guidelines to know how these are named.
-
The algorithm behind
get_minimum_required()is still very basic, andNotEqualis not implemented.
Contributing
All feedback / bug reports / pull requests are welcome.
License
This code is released under the MIT license. For the full copyright and license information, please view the LICENSE file distributed with this source code.
brightnucleus/phpfeature 适用场景与选型建议
brightnucleus/phpfeature 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 20 次下载、GitHub Stars 达 6, 最近一次更新时间为 2016 年 01 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 brightnucleus/phpfeature 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 brightnucleus/phpfeature 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 20
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-01-14