ixnode/php-container
最新稳定版本:1.0.27
Composer 安装命令:
composer require ixnode/php-container
包简介
PHP Container - A collection of various PHP container classes like JSON, File, etc.
关键字:
README 文档
README
A collection of various PHP container classes like JSON, File, etc.
1) Installation
composer require ixnode/php-container
vendor/bin/php-container -V
php-container 0.1.0 (12-19-2022 01:17:26) - Björn Hempel <bjoern@hempel.li>
2) Usage
2.1) File
use Ixnode\PhpContainer\File;
2.1.1) Check if file exists
$exists = (new File('path-to-file'))->exist();
true || false
2.1.2) Get the filesize (integer value)
$fileSize = (new File('path-to-file'))->getFileSize();
1523943
2.1.3) Get the filesize (human readable)
$fileSizeHuman = (new File('path-to-file'))->getFileSizeHuman();
1.45 MB
2.1.4) Get the file content
$content = (new File('path-to-file'))->getContentAsText();
line 1 line 2 line 3 ...
2.1.5) Get the file content as JSON object
$content = (new File('path-to-json-file'))->getJson()->getJsonStringFormatted();
{
"data": "Content of file 'path-to-json-file'."
}
2.2) JSON
use Ixnode\PhpContainer\Json;
2.2.1) Convert array to JSON
$json = (new Json(['data' => 'json']))->getJsonStringFormatted();
{
"data": "json"
}
2.2.2) Convert JSON to array
$array = (new Json('{"data": "json"}'))->getArray();
[
'data' => 'json',
]
2.2.3) Convert JSON file to array
$array = (new Json(new File('path-to-json-file')))->getArray();
2.2.4) Access to JSON object
$json = (new Json([ 'key1' => 'value1', 'key2' => [ 'associative' => [ 'name' => 'Test', 'id' => 123 ], 'indexed' => [1, 2, 3], ], 'key3' => 'value3', 'key4' => 'value4', 'key5' => 'value5', ]));
print $json->getKeyString(['key2', 'associative', 'name']); // return value: (string) 'Test'
print $json->getKeyInteger(['key2', 'indexed', 0]); // return value: (int) 1
print_r($json->getKeyArray(['key2', 'indexed'])); // return value: (array) [1, 2, 3]
2.2.5) Build a new array from JSON
$array = (new Json('[{"key1": 111, "key2": "222"},{"key1": 333, "key2": "444"}]'))->buildArray( [ /* path []['key1'] as area1 */ 'area1' => [['key1']], /* path []['key2'] as area2 */ 'area2' => [['key2']], ] );
[
'area1' => [111, 333],
'area2' => ['222', '444'],
]
2.3) CSV
use Ixnode\PhpContainer\Csv;
2.3.1) Parse CSV file to array
$array = (new Csv(new File('path-to-csv-file')))->getArray();
Content of "path-to-csv-file":
"headerLine1Cell1";"headerLine1Cell2"
"valueLine2Cell1";"valueLine2Cell2"
"valueLine3Cell1";"valueLine3Cell2"
Response:
[
[
'headerLine1Cell1' => 'valueLine2Cell1',
'headerLine1Cell2' => 'valueLine2Cell2',
],
[
'headerLine1Cell1' => 'valueLine3Cell1',
'headerLine1Cell2' => 'valueLine3Cell2',
],
...
]
2.4) Curl
use Ixnode\PhpContainer\Curl;
2.4.1) Return the response value from 'URL'
$text = (new Curl('URL')->getContentAsText();
2.5) Image
use Ixnode\PhpContainer\Image;
2.5.1) Return width of given image.
$imageWidth = (new Image(new File('path-to-json-file')))->getWidth();
2.5.2) Returns a resized image.
$imageString = (new Image(new File('path-to-json-file')))->getImageString(1000, Image::FORMAT_JPG, 85);
3.) Development
git clone git@github.com:ixnode/php-container.git && cd php-container
composer install
composer test
4.) License
This tool is licensed under the MIT License - see the LICENSE file for details
ixnode/php-container 适用场景与选型建议
ixnode/php-container 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.14k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2022 年 12 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「container」 「php」 「json」 「file」 「data」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ixnode/php-container 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ixnode/php-container 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ixnode/php-container 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Kinikit - PHP Application development framework MVC component
ext-json wrapper with sane defaults
A package to cast json fields, each sub-keys is castable
A fast and intuitive dependency injection container.
swagger-php - Generate interactive documentation for your RESTful API using phpdoc annotations
Get wordpress nav menus and share the main site menus with the child sites.
统计信息
- 总下载量: 1.14k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 12
- 依赖项目数: 5
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-12-30