r4nkt/laravel-resource-tidier 问题修复 & 功能扩展

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

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

r4nkt/laravel-resource-tidier

Composer 安装命令:

composer require r4nkt/laravel-resource-tidier

包简介

A simple-but-opinionated set of classes that allows for configurable tidying of various user resources.

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

A simple-but-opinionated set of classes that allows for configurable tidying of various user resources. It allows you to configure "tidiers", which find resources that need to be tidied up, culling them, notifying resource owners, and eventually performing the tidying-up task. It also allows for "unmarking" resources if/when the circumstances demand it.

This package was developed to scratch an itch, but it was also inspired by Freek and his blog post about removing inactive users and teams.

It should also be noted that it's the foundation for another r4nkt package, which may be useful in your own projects or as an example on how to use laravel-resource-tidier.

Finally, it's important to point out that this package benefitted from Spatie's Laravel package skeleton package.

Installation

You can install the package via composer:

composer require r4nkt/laravel-resource-tidier

You can publish the config file with:

php artisan vendor:publish --provider="R4nkt\ResourceTidier\ResourceTidierServiceProvider" --tag="laravel-resource-tidier-config"

This is the contents of the published config file:

<?php

use R4nkt\ResourceTidier\Actions\CullResources;
use R4nkt\ResourceTidier\Actions\HandleResources;
use R4nkt\ResourceTidier\Actions\NullFinder;
use R4nkt\ResourceTidier\Actions\NullMarker;
use R4nkt\ResourceTidier\Actions\NullNotifier;
use R4nkt\ResourceTidier\Actions\NullTask;
use R4nkt\ResourceTidier\Actions\NullUnmarker;

return [

    /**
     * Tidiers: A tidier is a simple class that tidies a given resource in two
     * steps:
     *  - First, it culls resources by finding those that match specific
     *    criteria, marking them, and notifying the resource owner of some
     *    impending action(s).
     *  - Second, it performs whatever tidying handler has been defined on the
     *    marked resources.
     *
     * Required parameters:
     *  - culler
     *  - handler
     */
    'tidiers' => [
        'null-resource-tidier' => [
            'culler' => 'null-resource-culler',
            'unmarker' => 'null-resource-unmarker',
            'handler' => 'null-resource-handler',
        ],
    ],

    /**
     * Cullers find specific resources, mark them, and notify their owners of
     * some impending handler(s).
     *
     * Required parameters:
     *  - class
     *  - params:
     *     - finder
     *     - marker
     *     - notifier
     *     - unmarker
     */
    'cullers' => [
        'null-resource-culler' => [
            'class' => CullResources::class, /** @todo Make optional...? */
            'params' => [
                'finder' => 'null-resource-finder',
                'marker' => 'null-resource-marker',
                'notifier' => 'null-resource-notifier',
            ],
        ],
    ],

    /**
     * Handlers, when executed, find resources having certain attributes and
     * then perform some sort of task on/with them.
     *
     * Required parameters:
     *  - class
     *  - params:
     *     - finder
     *     - task
     */
    'handlers' => [
        'null-resource-handler' => [
            'class' => HandleResources::class, /** @todo Make optional...? */
            'params' => [
                'finder' => 'null-resource-finder',
                'task' => 'null-resource-task',
            ],
        ],
    ],

    /**
     * Finders find resources that meet certain criteria, either for culling or
     * for handling.
     *
     * Required parameters:
     *  - class
     *
     * Optional parameters:
     *  - params
     *     - <custom param 1>
     *     - <custom param 2>
     *     - <custom param ...>
     *     - <custom param n>
     */
    'finders' => [
        'null-resource-finder' => [
            'class' => NullFinder::class,
            'params' => [
                'foo' => 'bar',
            ],
        ],
    ],

    /**
     * Markers mark a given resource as having been culled. The idea is that
     * enough information is stored to allow the handler's finder to
     * successfully find any marked resources.
     *
     * Required parameters:
     *  - class
     *
     * Optional parameters:
     *  - params
     *     - <custom param 1>
     *     - <custom param 2>
     *     - <custom param ...>
     *     - <custom param n>
     */
    'markers' => [
        'null-resource-marker' => [
            'class' => NullMarker::class,
            'params' => [
                'foo' => 'bar',
            ],
        ],
    ],

    /**
     * Notifiers are used to notify a resource owner that the resource has been
     * culled and that some action will take place.
     *
     * Required parameters:
     *  - class
     *
     * Optional parameters:
     *  - params
     *     - <custom param 1>
     *     - <custom param 2>
     *     - <custom param ...>
     *     - <custom param n>
     */
    'notifiers' => [
        'null-resource-notifier' => [
            'class' => NullNotifier::class,
            'params' => [
                'foo' => 'bar',
            ],
        ],
    ],

    /**
     * Tasks are executed for each culled resource during the handling stage of
     * the tidying process.
     *
     * Required parameters:
     *  - class
     *
     * Optional parameters:
     *  - params
     *     - <custom param 1>
     *     - <custom param 2>
     *     - <custom param ...>
     *     - <custom param n>
     */
    'tasks' => [
        'null-resource-task' => [
            'class' => NullTask::class,
            'params' => [
                'foo' => 'bar',
            ],
        ],
    ],

    /**
     * Unmarkers are meant to undo whatever the related marker has done,
     * effectively removing a given resource from the group of culled
     * resources.
     *
     * Required parameters:
     *  - class
     *
     * Optional parameters:
     *  - params
     *     - <custom param 1>
     *     - <custom param 2>
     *     - <custom param ...>
     *     - <custom param n>
     */
    'unmarkers' => [
        'null-resource-unmarker' => [
            'class' => NullUnmarker::class,
            'params' => [
                'foo' => 'bar',
            ],
        ],
    ],

];

Usage

To get a registered tidier, you can simply use the tidier factory like so:

use R4nkt\ResourceTidier\Support\Factories\TidierFactory;

$tidier = TidierFactory::make('my-resource-tidier');

You can then cull the tidier-specific resources by calling cull():

$tidier->cull();

You can also tidy up the culled resources by calling handle():

$tidier->handle();

Finally, you can unmark a culled resource by calling unmark() and passing in the individual resource:

$tidier->unmark($culledResource);

What does it do?

The tidier is a simple class that provides a way to tidy up resources:

  • First, it culls any resources that meet specific requirements. Each culled resource is marked for tidying up and the resource owner is notified.
  • Second, it allows individual resources that have been culled to be unmarked.
  • Finally, it performs the actual tidying up.

An example tidier might be for registered users that have not verified their email addresses. Culling will identify these users and mark them for deletion. Notifications will be sent to the resource owners, which are the users themselves, to let them know that their accounts will be deleted because the emails associated with their accounts haven't been verified. If they happen to verify their email addresses before being deleted, then they will be "unmarked". If nothing is done in time, however, then the unverified user accounts will be deleted.

Tidiers

Tidiers can be registered by name in the configuration file and must identify three items:

  • culler
  • unmarker
  • handler

Cullers

A culler's job is to find resources that meet some criteria, mark them as culled, and notify the individual resource owners.

Cullers can be registered by name in the configuration file and must identifiy three parameters:

  • finder
  • marker
  • notifier

Optionally, a class that implements R4nkt\ResourceTidier\Actions\Contracts\CullsResources can be provided.

Unmarkers

An unmarker's job is to unmark an individual resource that has been previously marked.

Unmarkers can be registered by name in the configuration file and must identifiy a class that implements R4nkt\ResourceTidier\Actions\Contracts\UnmarksResource.

Optionally, any params that the unmarkers require can be provided.

Handlers

A handler's job is to handle the tidying up of any culled resources.

Handlers can be registered by name in the configuration file and must identifiy the following parameters:

  • finder
  • task

Optionally, a class that implements R4nkt\ResourceTidier\Actions\Contracts\HandlesResources can be provided.

Finders

A finder's job is to find resources. They are used by cullers and handlers, but they perform the same general function. For cullers, they are to find resources that should be culled. For handlers, they are to find culled resources that should be tidied up.

Finders can be registered by name in the configuration file and must identifiy a class that implements R4nkt\ResourceTidier\Actions\Contracts\FindsResources.

Optionally, any params that the finders require can be provided.

Markers

A marker's job is to mark individual resources as having been culled.

Markers can be registered by name in the configuration file and must identifiy a class that implements R4nkt\ResourceTidier\Actions\Contracts\MarksResources.

Optionally, any params that the markers require can be provided.

Notifiers

A notifier's job is to notify individual resource owners that their resources have been culled and some sort of impending action is likely to take place.

Notifiers can be registered by name in the configuration file and must identifiy a class that implements R4nkt\ResourceTidier\Actions\Contracts\NotifiesResourceOwner.

Optionally, any params that the notifiers require can be provided.

Tasks

A task's job is to tidy up an individual resource.

Tasks can be registered by name in the configuration file and must identifiy a class that implements R4nkt\ResourceTidier\Actions\Contracts\ExecutesResourceTask.

Optionally, any params that the notifiers require can be provided.

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

r4nkt/laravel-resource-tidier 适用场景与选型建议

r4nkt/laravel-resource-tidier 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 68 次下载、GitHub Stars 达 1, 最近一次更新时间为 2021 年 04 月 23 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 r4nkt/laravel-resource-tidier 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-04-23