wp-forge/fluent
Composer 安装命令:
composer require wp-forge/fluent
包简介
An instance of the Laravel Fluent class for use with WordPress.
README 文档
README
A PHP utility class which allows for more flexible ways of getting and setting data.
Installation
composer require wp-forge/fluent
Usage
Setting Values
Populate data from an existing array, object, or iterable
<?php use WP_Forge\Fluent\Fluent; // Populate using an array $fluent = new Fluent( [ 'a' => 1 ] ); var_dump( $fluent->toJson() ); // {"a":1} // Populate using an object $fluent = new Fluent( (object) [ 'b' => 2 ] ); var_dump( $fluent->toJson() ); // {"b":2} // Populate using an iterable $fluent = new Fluent( (function () { yield 1; yield 2; })() ); var_dump( $fluent->toJson() ); // [1,2]
Set values using array syntax
<?php $fluent = new \WP_Forge\Fluent\Fluent(); $fluent['isActive'] = true; var_dump( $fluent->toJson() ); // {"isActive":true}
Set values using property syntax
<?php $fluent = new \WP_Forge\Fluent\Fluent(); $fluent->isActive = true; var_dump( $fluent->toJson() ); // {"isActive":true}
Set values using the set() method
<?php $fluent = new \WP_Forge\Fluent\Fluent(); $fluent->set('isActive', true); var_dump( $fluent->toJson() ); // {"isActive":true}
Set values using by calling non-existent methods
<?php $fluent = new \WP_Forge\Fluent\Fluent(); $fluent->isActive(); // Will set to true by default var_dump( $fluent->toJson() ); // {"isActive":true} $fluent->isActive( false ); var_dump( $fluent->toJson() ); // {"isActive":false}
Getting Values
Get values using array syntax
<?php $fluent = new \WP_Forge\Fluent\Fluent( ['isActive' => true] ); var_dump( $fluent['isActive'] ); // true
Get values using property syntax
<?php $fluent = new \WP_Forge\Fluent\Fluent( ['isActive' => true] ); var_dump( $fluent->isActive ); // true
Get values using the get() method
<?php $fluent = new \WP_Forge\Fluent\Fluent( ['isActive' => true] ); var_dump( $fluent->get( 'isActive' ) ); // true // Since "isRegistered" doesn't exist, it returns the defined default value instead var_dump( $fluent->get( 'isRegistered', 'Ask again later' ) ); // Ask again later
Fetch all data using special methods
<?php use WP_Forge\Fluent\Fluent; $fluent = new Fluent( ['a' => 1] ); $fluent->toArray(); // Returns all data as an array $fluent->toJson(); // Returns all data as JSON
Checking if a Key Exists
Using array syntax
<?php use WP_Forge\Fluent\Fluent; $fluent = new Fluent( ['a' => 1] ); var_dump( isset( $fluent['a'] ) ); // true var_dump( isset( $fluent['b'] ) ); // false
Using property syntax
<?php use WP_Forge\Fluent\Fluent; $fluent = new Fluent( ['a' => 1] ); var_dump( isset( $fluent->a ) ); // true var_dump( isset( $fluent->b ) ); // false
Using the has() method
<?php use WP_Forge\Fluent\Fluent; $fluent = new Fluent( ['a' => 1] ); var_dump( $fluent->has( 'a' ) ); // true var_dump( $fluent->has( 'b' ) ); // false
Deleting Values
Using array syntax
<?php use WP_Forge\Fluent\Fluent; $fluent = new Fluent( ['a' => 1] ); unset( $fluent['a'] ); var_dump( $fluent->toJson() ); // []
Using property syntax
<?php use WP_Forge\Fluent\Fluent; $fluent = new Fluent( ['a' => 1] ); unset( $fluent->a ); var_dump( $fluent->toJson() ) ); // []
Using the delete() method
<?php use WP_Forge\Fluent\Fluent; $fluent = new Fluent( ['a' => 1] ); $fluent->delete( 'a' ); var_dump( $fluent->toJson() ); // []
wp-forge/fluent 适用场景与选型建议
wp-forge/fluent 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 249.67k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2022 年 03 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 wp-forge/fluent 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 wp-forge/fluent 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 249.67k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0-or-later
- 更新时间: 2022-03-03