attia-ahmed/extendable-action 问题修复 & 功能扩展

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

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

attia-ahmed/extendable-action

Composer 安装命令:

composer require attia-ahmed/extendable-action

包简介

An Abstract classes to make extendable actions for the Laravel framework.

README 文档

README

Laravel packages that allows you to make your laravel project extendable and easy to include new features without touching old code throgh Extendable Actions .

Why ExtendableAction?

Having a large codebase and dynamic features leads to a missy codebase with huge maintainability headache! This package implements the main concept of WordPress pluggable features by using of Filters and Actions ( See WordPress Hooks ) that allow you to expand your codebase in a pluggable way.

Installation

  1. Install via composer
$ composer require attia-ahmed/extendable-action

or add it by hand to your composer.json file.

  1. Publish the config file with:
php artisan vendor:publish --tag="extendable-action-provider"
  1. Append to your providers in app.phpconfig file :
App\Providers\ExtendableActionAppServiceProvider::class,

Usage

  1. make your extendable action:

Which is the main functionality that needs to be extended. You can make your extendable action by extending ExtendableAction class and define the run method that take any number of parameters (will be modified by filters) and return result (will be modified by actions) then it will be called as Invokable Class Example:

class ExampleExtendableAction extends ExtendableAction
{
    public function run($name)
    {
        return "Hello " . $name;
    }
}
  1. make your filters:

Which are classes that modifies the ExtendableAction input parameters or do some logic/check before running the main functionality. You can make your Filter by extending Filter class and override the apply method that takes run method parameters of ExtendableAction as an array and returns array of parameters to be modified with another filters or to be passed to main ExtendableAction Example:

class ExampleFilter extends Filter
{
    public function apply(array $args): array
    {
        $args["name"] = "Mr. " . $args["name"];
        return $args;
    }
}
  1. make your actions:

Which are classes that modifies the ExtendableAction result or do some logic/check after running the main functionality. You can make your Action by extending Action class and override the apply method that takes the result ofrun method of ExtendableAction and returns new result to be modified with another actions or to be final return result of ExtendableAction functionality. Example:

class ExampleAction extends Action
{
    public function apply($result)
    {
        return "<h1>{$result}</h1>";
    }
}
  1. Link your Filters and Actions to your Extendable action :

You can link your Filters and Action to your Extendable Action by adding new element in ExtendableActionAppServiceProvider protected attribute $extendable_actions or by your custom implementation by overriding getFilters and getActions of ExtendableAction class Example :

   protected array $extendable_actions = [

        ExampleExtendableAction::class => [
            "filters" => [
                ExampleFilter::class
            ],
            "actions" => [
                ExampleAction::class
            ]
        ],
    ];
  1. Call your Extendable action :

ExtendableAction is an Invokable Class and can be called by as one of following examples:

//RECOMMENDED so it automatically be executed it while injecting its dependencies
$result = app(ExampleExtendableAction::class)(...$args);

or

$result = (new ExampleExtendableAction())(...$args);

Compatibility with other packages

spatie/laravel-queueable-action:

you can use Extendable Action with Queueable Actions as following:

  1. Extend your Queueable Action from ExtendableAction
  2. Add your code logic in custom defined run(...$args) method (Do Not Override __invoke() method)
  3. call your Queuable action as normal and Extend it with any Filters or Actions 🎉

note: You should return result to be returned to your Actions attached to Extendable Action

All your Filters and Action will run in queue

Examle:

Queuable Extendable Action:

class ExampleExtendedQueueableAction extends ExtendableAction
{
    use QueueableAction;
    
    public function run(Example1 $example1, Example2 $example2)
    {
        //custom logic happen in queue
        return $result;
    }
}

usage:

app(ExampleExtendedQueueableAction::class)()->onQueue()->execute($example1, $example2);

Usage Notes

⚠️This package is a proof of concept and IS NOT READY for production.⚠️

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2022-01-12

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固