承接 wmsamolet/php-object-collections 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

wmsamolet/php-object-collections

Composer 安装命令:

composer require wmsamolet/php-object-collections

包简介

PHP object collections - strongly typed collections for objects and more

README 文档

README

Latest Stable Version Total Downloads Latest Unstable Version License PHP Version Require PHP Version Require

Strongly typed collections for objects and more

Advantages:

Documentation

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require wmsamolet/php-collections

or add

"wmsamolet/php-collections": "^1.0"

to the requirement section of your composer.json file.

Basic usage object collections

<?php

use Wmsamolet\PhpObjectCollections\ObjectCollection;

class TestEntity
{
    /** @var int */
    private $id;
    
    public function getId(): int
    {
        return $this->id;
    }
    
    public function setId(int $id): void 
    {
        $this->id = $id;
    }
}

// Create collection with values 1,2,3
$collection = new ObjectCollection(
    TestEntity::class, 
    [
        (new TestEntity())->setId(1), 
        (new TestEntity())->setId(2), 
        (new TestEntity())->setId(3), 
    ]
);

// Print entities: #1,#2,#3
echo '<pre>';
print_r($collection->getList());
echo '</pre>';

// If we try to add another collection to the collection
// WE WILL GET AN EXCEPTION!

class TestOtherEntity extends TestEntity
{
}

$collection->add((new TestOtherEntity())->setId(4));

Basic usage object static collections

<?php

use Wmsamolet\PhpObjectCollections\AbstractCollection;

class TestEntity
{
    /** @var int */
    private $id;
    
    public function getId(): int
    {
        return $this->id;
    }
    
    public function setId(int $id): void 
    {
        $this->id = $id;
    }
}

/**
 * Add PhpDoc for IDE autocompletion when working with this collection
 * 
 * @method TestEntity[] getList()
 * @method null|TestEntity get(int $key)
 * @method null|TestEntity getByOffset(int $key)
 */
class ExampleEntityCollection extends AbstractObjectCollection
{
    /**
     * Set collection item as TestEntity object class
     */
    public function collectionObjectClassName(): string
    {
        return TestEntity::class;
    }
}

// Add entities to collection
$collection = new ExampleEntityCollection([
    (new TestEntity())->setId(1),
    (new TestEntity())->setId(2),
    (new TestEntity())->setId(3),
]);

// Print entities: #1,#2,#3
echo '<pre>';
print_r($collection->getList());
echo '</pre>';

// If we try to add another collection or value with another to the collection
// WE WILL GET AN EXCEPTION!

class TestOtherEntity extends TestEntity
{
}

$collection->add((new TestOtherEntity())->setId(4));
$collection->add(5);

Basic usage typed collections

<?php

use Wmsamolet\PhpObjectCollections\TypedCollection;

// Create collection with values 1,2,3
$collection = new TypedCollection(TypedCollection::TYPE_INTEGER, [1, 2, 3]);

// Print values: 1,2,3
echo '<pre>';
print_r($collection->getList());
echo '</pre>';

// If we try to add value with another type to the collection
// WE WILL GET AN EXCEPTION!
$collection->add('4');
$collection->add([5]);

Basic usage typed static collections

<?php

use Wmsamolet\PhpObjectCollections\AbstractTypedCollection;

/**
 * Add PhpDoc for IDE autocompletion when working with this collection
 * 
 * @method int[] getList()
 * @method null|int get(int $key)
 * @method null|int getByOffset(int $key)
 */
class TestIdCollection extends AbstractTypedCollection
{
    /**
     * Set collection item value type
     */
    public function collectionValueType(): string
    {
        return static::TYPE_INT;
    }
}

// Create collection with ids #1,#2,#3 to collection
$collection = new TestIdCollection([1, 2, 3]);

// Print ids: #1,#2,#3
echo '<pre>';
print_r($collection->getList());
echo '</pre>';

// If we try to add value with another type to the collection
// WE WILL GET AN EXCEPTION!
$collection->add('4');
$collection->add([5]);

License

PHP Object Collections is licensed under the MIT License - see the LICENSE file for details

wmsamolet/php-object-collections 适用场景与选型建议

wmsamolet/php-object-collections 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 27 次下载、GitHub Stars 达 3, 最近一次更新时间为 2021 年 11 月 12 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「collections」 「php」 「array」 「object」 「iterators」 「typed」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 wmsamolet/php-object-collections 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 wmsamolet/php-object-collections 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 27
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-11-12