bfg/object 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

bfg/object

Composer 安装命令:

composer require bfg/object

包简介

To work with objects and arrays

README 文档

README

To work with objects and arrays.

GAG Object

The Gag object is designed for recursive data filling and the construction of circuits and its children from the repartition that can be automatically filling. Standard Gag Object connects all classes in the app/Gags folder, all the classes are parsed there automatically fall into the Gag storage.

By default, there is already a harvested Gag object Bfg\Object\Gag which you can use globally for your needs. There is also the opportunity to create its own Gag collection.

Consider the situation with the filling of the standard GAG object:

\Bfg\Object\Gag::register('gag_name', MyComponent::class);
\Bfg\Object\Gag::register('gag_next', MyNextComponent::class);

Implementation methods:

public function gag(\Bfg\Object\Gag $gag)
{
    $gag->gag_name(...$construct_arguments)
        ->before(function (...$construct_arguments) {}) 
        // "before" To call an event before initialization.
        ->then(function (MyComponent $component, ...$construct_arguments) {})
        // "then" To call an event after initialization.
        ->gag_next();

    return $gag;
}

And the initializer will enter it:

\Bfg\Object\Gag::instance(MyComponent::class, function (
    MyComponent $component, array $child, ...$construct_arguments
) {
    return $component->applyChilds($child);
});

If you need to wrap in the GAG already ready component and there is no possibility to overload or replace it, then you can, I added a wrapper for such cases, to the priment, helper view is organized through such a wrapper:

<?php
use Bfg\Object\GagCore;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\View\Factory;
use Illuminate\Contracts\View\View;

/**
 * Class ViewComponent
 * @package Bfg\Layout\BodyComponents
 */
class ViewComponent
{
    /**
     * The name of the component in the Gag storage.
     * 
     * @var string
     */
    static string $name = "view";

    /**
     * To save in the designer of the object template.
     * 
     * @var Application|Factory|View
     */
    public Application|Factory|View $view;

    /**
     * ViewComponent constructor.
     *
     * @param  string  $name
     * @param  array  $data
     * @param  array  $mergeData
     */
    public function __construct(string $name, array $data = [], array $mergeData = [])
    {
        $this->view = view($name, $data, $mergeData);
    }
    
    /**
     * To call an event before initialization.
     * 
     * @param ...$construct_arguments
     */
    public function gagBefore(...$construct_arguments){
        //
    }
    
    /**
     * To call an event after initialization.
     * 
     * @param ...$construct_arguments
     */
    public function gagThen(...$construct_arguments){
        //
    }

    /**
     * For the use of GAG object to sequence.
     * 
     * @param  GagCore  $core
     * @return string
     */
    public function gagApply(GagCore $core): string
    {
        return $this->view->with('content', implode('', $core->child))->render();
    }
}

Well, accordingly, if you need to create your Gag object, you can go to the following way:

<?php

use Bfg\Object\GagCore;

/**
 * @mixin \MyGags
 */
class MyGag extends GagCore
{
    /**
     * Storage of components
     * @var array
     */
    #[
        StaticClassStorage('MyComponents'),
        StaticClassStorage('app/Components', false),
        DocMethods([Body::class, 'static'], '{key}({value_construct})', 'Storage body gag {key} component'),
        DocClassName('{class}Gags')
    ]
    static array $storage = [];

    /**
     * Gag instances for subject injection with child
     * @var array
     */
    protected static array $instances = [];
}

Static class storage

This is an attribute that allows you to scan the folder on the files with classes and is the list of them for the Static Properties.

Important! The property must be a static public array!

#[StaticClassStorage('Components')]
static array $classes = [];

Collection

Adds to the collection of a paginate method, convenient to create a paginator from the collection.

collect([])->paginate($perPage = 15, $pageName = 'page', $page = null);

Helpers

pipeline

The organization of pipeline is the same as it is implemented by middleware Laravel.

pipeline($send, array $pipes);

is_call

When this is called an item.

is_call(mixed $subject);

is_assoc

Check whether an array is associative.

is_assoc(array $arr);

array_merge_recursive_distinct

array_merge_recursive does indeed merge arrays, but it converts values with duplicate keys to arrays rather than overwriting the value in the first array with the duplicate value in the second array, as array_merge does. I.e., with array_merge_recursive, this happens (documented behavior):

array_merge_recursive(array('key' => 'org value'), array('key' => 'new value'));
     => array('key' => array('org value', 'new value'));

array_merge_recursive_distinct does not change the datatypes of the values in the arrays. Matching keys' values in the second array overwrite those in the first array, as is the case with array_merge, i.e.:

array_merge_recursive_distinct(array('key' => 'org value'), array('key' => 'new value'));
     => array('key' => array('new value'));

Parameters are passed by reference, though only for performance reasons. They're not altered by this function.

array_dots_uncollapse

Expand an array folded into a dot array.

array_dots_uncollapse(array $array);

multi_dot_call

Access to an object or/and an array using the dot path method

multi_dot_call($obj, string $dot_path, bool $locale = true);

bfg/object 适用场景与选型建议

bfg/object 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 61.87k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2021 年 07 月 14 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-07-14