Php 命名Laravel事件、侦听器和作业

Php 命名Laravel事件、侦听器和作业,php,laravel,naming-conventions,Php,Laravel,Naming Conventions,我有一个名为userwasregated的事件,我还有一个名为userwasregated的侦听器,从那里我开始开发作业命令,名为: EmailRegistrationConfirmation NotifyAdminsNewRegistration CreateNewBillingAccount 所有这些作业都将在UserWasRegistered事件侦听器类中执行 这是正确的方法还是应该为用户注册多个侦听器?我觉得使用jobs方法使我能够在不同的时间从应用程序的其他区域调用这些“jobs”。e

我有一个名为
userwasregated
的事件,我还有一个名为
userwasregated
的侦听器,从那里我开始开发作业命令,名为:

EmailRegistrationConfirmation

NotifyAdminsNewRegistration

CreateNewBillingAccount

所有这些作业都将在
UserWasRegistered
事件侦听器类中执行


这是正确的方法还是应该为
用户注册多个侦听器?我觉得使用jobs方法使我能够在不同的时间从应用程序的其他区域调用这些“jobs”。e、 g.如果用户更改了详细信息,可能会调用
CreateNewBillingAccount
。?

我建议更改更明确的侦听器名称,这样我就不会直接将侦听器与事件配对

我们使用的是贫血事件/监听器方法,因此监听器将实际任务传递给“实干者”(工作、服务,你可以说)

此示例取自实际系统:

app/Providers/EventServiceProvider.php

    OrderWasPaid::class    => [
        ProvideAccessToProduct::class,
        StartSubscription::class,
        SendOrderPaidNotification::class,
        ProcessPendingShipment::class,
        LogOrderPayment::class
    ],
开始订阅侦听器:

namespace App\Modules\Subscription\Listeners;


use App\Modules\Order\Contracts\OrderEventInterface;
use App\Modules\Subscription\Services\SubscriptionCreator;

class StartSubscription
{
    /**
     * @var SubscriptionCreator
     */
    private $subscriptionCreator;

    /**
     * StartSubscription constructor.
     *
     * @param SubscriptionCreator $subscriptionCreator
     */
    public function __construct(SubscriptionCreator $subscriptionCreator)
    {
        $this->subscriptionCreator = $subscriptionCreator;
    }

    /**
     * Creates the subscription if the order is a subscription order.
     *
     * @param OrderEventInterface $event
     */
    public function handle(OrderEventInterface $event)
    {
        $order = $event->getOrder();

        if (!$order->isSubscription()) {
            return;
        }

        $this->subscriptionCreator->createFromOrder($order);
    }
}
通过这种方式,您可以在应用程序的其他区域调用作业/服务(
SubscriptionCreator


也可以将侦听器绑定到其他事件,而不是
orderwaspayed

,基本上侦听器不应该调用作业。没有自己执行任务的责任?