able/struct
Composer 安装命令:
composer require able/struct
包简介
phpABLE struct data type implementation library
关键字:
README 文档
README
The phpABLE struct emulation library.
Requirements
- PHP >= 8.0.0
- able/helpers
- able/prototypes
- able/exceptions
- able/reglib
Features
The mission of this library is to emulate the structures' behavior most naturally.
Install
There's a simple way to install the able/struct package via composer:
composer require able/struct
Usage
Basic
Let's try to declare a structure:
use \Able\Struct; class MyStruct extends AStruct { protected static $Prototype = ['field1', 'field2']; }
Now we can use it in a siple way:
$Struct = new MyStruct(1,2); echo $Struct->field1; //> 1
It's also possible to fill fields later:
$Struct = new MyStruct(); $Struct->field1 = "Test string!"; echo $Struct->field1; //> Test string!
Mutators
Mutators are pretty helpful in case it needed to customize the default structure behavior.
use \Able\Struct; class MyStruct extends AStruct { protected static $Prototype = ['field1', 'field2']; protected final function setField1Property($value) { return 'The mutated via setter value is: ' . $value; } protected final function getField2Property($value) { return 'The mutated via getter value is: ' . $value; } }
Let's test it:
$Struct = new MyStruct(1,2); echo $Struct->field1; echo $Struct->field2; //> The mutated via setter value is: 1 //> The mutated via getter value is: 2
The next example just illustrates the difference between setters and getters.
$Data = $Struct->toArray(); echo $Data['field1']; echo $Data['field2']; //> The mutated via setter value is: 1 //> 2
Default values
The default values could be set via constants.
use \Able\Struct; class MyParentStruct extends AStruct { protected static array $Prototype = ['field1', 'field2']; protected const defaultField1Value = "default value for field1"; protected const defaultField2Value = "default value for field2"; }
Inheritance
The inheritance level isn't limited. All fields defined at parent classes will also be accessible at child classes.
use \Able\Struct; class MyParentStruct extends AStruct { protected static array $Prototype = ['field1', 'field2']; } class MyChildStruct extends MyParentStruct { protected static array $Prototype = ['field3']; }
It perfectly works:
$Struct = new MyChildStruct(1,2,3); echo $Struct->field1; echo $Struct->field2; echo $Struct->field3; //> 1 //> 2 //> 3
Advanced
To retrieve all structure keys:
$Struct->keys();
To retrieve all structure values:
$Struct->values();
To copy all data into an array:
$Struct->toArray();
To get fields count:
$Struct->count();
To clean all fields and restore its default values:
$Struct->flush();
IDEs support
If you use a PHPDoc-friendly IDE you can gain additional advantages by using the syntax below:
use \Able\Struct; /** * @property int field1 * @property string field2 */ class MyStruct extends AStruct { protected static array $Prototype = ['field1', 'field2']; }
License
This package is released under the MIT license.
able/struct 适用场景与选型建议
able/struct 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.09k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2018 年 05 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「struct」 「Structures」 「phpable」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 able/struct 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 able/struct 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 able/struct 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Structure-aware migration helpers for Laravel Enso packages
A collection of functional programming data structures
PHP implementation of python's struct module.
A collection of common algorithms implemented in PHP. The collection is based on "Cracking the Coding Interview" by Gayle Laakmann McDowell
PHP library containing heap implementations
Struct libraries used by Zimbra Api
统计信息
- 总下载量: 1.09k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 3
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-05-22