定制 ixnode/php-container 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

Release PHP PHPStan PHPUnit PHPCS PHPMD Rector - Instant Upgrades and Automated Refactoring LICENSE

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 我们能提供哪些服务?
定制开发 / 二次开发

基于 ixnode/php-container 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.14k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 12
  • 依赖项目数: 5
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-12-30