上下文绑定不适用于Job :: handle()

时间:2019-04-05 18:29:04

标签: laravel

请查看绑定。当工作分派时,一种有效,而另一种无效。

<?php

namespace App\Providers;

use App\Jobs\SendCalendarEventDataToZohoJob;
use CristianPontes\ZohoCRMClient\ZohoCRMClient;
use Illuminate\Support\ServiceProvider;

class ZohoEntityProvider extends ServiceProvider{
    /**
     * Bootstrap the application services.
     *
     * @return void
     */
    public function boot(){
        //
    }

    /**
     * Register the application services.
     *
     * @return void
     */
    public function register(){
        //this fires
        $this->app->bind(ZohoCRMClient::class, function(){
            return new ZohoCRMClient('Products', env('ZOHO_TOKEN'));
        });

        //this doesn't
        $this->app
            ->when(SendCalendarEventDataToZohoJob::class)
            ->needs(ZohoCRMClient::class)
            ->give(function (){
                return new ZohoCRMClient('Products', env('ZOHO_TOKEN'));
            });
    }
}

0 个答案:

没有答案