定制 lumosolutions/actionable 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

lumosolutions/actionable

Composer 安装命令:

composer require lumosolutions/actionable

包简介

Provides a clean, elegant way to create dispatchable and runnable actions in Laravel with built-in array conversion capabilities

README 文档

README

CI Pipeline codecov Latest Stable Version Total Downloads License

InstallationQuick StartFeaturesDocumentationExamples

hero

Transform your Laravel code into clean, testable, and reusable actions. Say goodbye to bloated controllers and hello to elegantly organized business logic!

💡 Why Actionable?

Ever found yourself writing the same business logic patterns over and over? Controllers getting too fat? Service classes becoming a mess? Actionable is here to save the day!

// ❌ The old way - Fat controllers, messy code
class UserController extends Controller
{
    public function register(Request $request)
    {
        // Validation logic...
        // User creation logic...
        // Email sending logic...
        // Queue processing...
        // 200 lines later...
    }
}

// ✅ The Actionable way - Clean, focused, reusable
RegisterUser::run($userData);

🎯 Key Features

🏃‍♂️ Runnable Actions

Execute business logic with a single, expressive call. No more hunting through service classes!

📬 Dispatchable Actions

Seamlessly queue your actions for background processing. It's as easy as changing run() to dispatch()!

💡 Smart Code Completion

Full IntelliSense support with auto-completion for runnable and dispatchable actions across all major IDEs.

🔄 Smart Array Conversion

Convert between arrays and objects effortlessly with our powerful attribute system. Perfect for APIs!

🛠️ Artisan Generators

Scaffold Actions and DTOs in seconds with our intuitive Artisan commands.

🎨 Flexible Attributes

Fine-tune serialization behavior with elegant attributes like #[FieldName], #[DateFormat], and more!

📦 Installation

composer require lumosolutions/actionable

That's it! No configuration needed. Start writing better code immediately.

🚀 Quick Start

Your First Action in 30 Seconds

1️⃣ Generate an action:

php artisan make:action SendWelcomeEmail

2️⃣ Define your logic:

class SendWelcomeEmail
{
    use IsRunnable;

    public function handle(string $email, string $name): void
    {
        Mail::to($email)->send(new WelcomeEmail($name));
    }
}

3️⃣ Use it anywhere:

SendWelcomeEmail::run('user@example.com', 'John Doe');

That's it! Clean, testable, reusable. 🎉

📚 Documentation

⚡ Actions

Actions are the heart of your application's business logic. They're single-purpose classes that do one thing and do it well.

Basic Actions

class CalculateOrderTotal
{
    use IsRunnable;

    public function handle(Order $order): float
    {
        return $order->items->sum(fn($item) => $item->price * $item->quantity);
    }
}

// Usage
$total = CalculateOrderTotal::run($order);

Queueable Actions

Need background processing? Just add a trait!

class ProcessVideoUpload
{
    use IsRunnable, IsDispatchable;

    public function handle(Video $video): void
    {
        // Heavy processing logic here
    }
}

// Run synchronously
ProcessVideoUpload::run($video);

// Or dispatch to queue
ProcessVideoUpload::dispatch($video);

// Use a specific queue
ProcessVideoUpload::dispatchOn('video-processing', $video);

🗄️ Data Transfer Objects (DTOs)

DTOs with superpowers! Convert between arrays and objects seamlessly.

class ProductData
{
    use ArrayConvertible;

    public function __construct(
        public string $name,
        public float $price,
        public int $stock
    ) {}
}

// From request data
$product = ProductData::fromArray($request->validated());

// To API response
return response()->json($product->toArray());

🏷️ Powerful Attributes

#[FieldName] - API-Friendly Naming

class UserResponse
{
    use ArrayConvertible;

    public function __construct(
        #[FieldName('user_id')]
        public int $userId,
        
        #[FieldName('full_name')]
        public string $fullName
    ) {}
}

#[DateFormat] - Date Formatting Made Easy

class EventData
{
    use ArrayConvertible;

    public function __construct(
        #[DateFormat('Y-m-d')]
        public DateTime $date,
        
        #[DateFormat('H:i')]
        public DateTime $startTime
    ) {}
}

#[ArrayOf] - Handle Nested Objects

class ShoppingCart
{
    use ArrayConvertible;

    public function __construct(
        #[ArrayOf(CartItem::class)]
        public array $items
    ) {}
}

#[Ignore] - Keep Secrets Secret

class UserAccount
{
    use ArrayConvertible;

    public function __construct(
        public string $email,
        
        #[Ignore]
        public string $password,
        
        #[Ignore]
        public string $apiSecret
    ) {}
}

🛠️ Artisan Commands

Generate boilerplate with style:

# Basic action
php artisan make:action ProcessOrder

# Queueable action
php artisan make:action SendNewsletter --dispatchable

# Invokable action
php artisan make:action CalculateShipping --invokable

# DTO with array conversion
php artisan make:dto OrderData

# Enable Smart Code Completion
php artisan ide-helper:actions

🌟 Real-World Examples

E-commerce Order Processing

// The DTO
class OrderData
{
    use ArrayConvertible;

    public function __construct(
        #[FieldName('customer_email')]
        public string $customerEmail,
        
        #[ArrayOf(OrderItemData::class)]
        public array $items,
        
        #[FieldName('discount_code')]
        public ?string $discountCode = null
    ) {}
}

// The Action
class ProcessOrder
{
    use IsRunnable, IsDispatchable;

    public function handle(OrderData $orderData): Order
    {
        $order = DB::transaction(function () use ($orderData) {
            $order = Order::create([...]);
            
            // Process items
            foreach ($orderData->items as $item) {
                $order->items()->create([...]);
            }
            
            // Apply discount
            if ($orderData->discountCode) {
                ApplyDiscount::run($order, $orderData->discountCode);
            }
            
            return $order;
        });

        // Queue follow-up actions
        SendOrderConfirmation::dispatch($order);
        UpdateInventory::dispatch($order);
        
        return $order;
    }
}

// Usage - It's this simple!
$orderData = OrderData::fromArray($request->validated());
$order = ProcessOrder::run($orderData);

User Registration Flow

class RegisterUser
{
    use IsRunnable;

    public function handle(RegistrationData $data): User
    {
        $user = CreateUser::run($data);
        
        SendWelcomeEmail::dispatch($user);
        NotifyAdmins::dispatch($user);
        TrackRegistration::dispatch($user, $data->referralSource);
        
        return $user;
    }
}

🤲 Contributing

We love contributions! Whether it's a bug fix, new feature, or improvement to our docs - we appreciate it all. Please feel free to submit a pull request or open an issue.

📄 License

Actionable is open-sourced software licensed under the MIT license.

💬 Support & Community

Built with ❤️ by Lumo Solutions

Actionable: Making Laravel development more enjoyable, one action at a time.

lumosolutions/actionable 适用场景与选型建议

lumosolutions/actionable 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 824 次下载、GitHub Stars 达 16, 最近一次更新时间为 2025 年 05 月 25 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 824
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 16
  • 点击次数: 8
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-05-25