作业声明与接口不兼容
Declaration of job is incompatible with interface
我在尝试最新工作时遇到声明错误。我已经建立了许多类似的工作,但我似乎无法找到它出现错误的问题。请帮忙!我可能只是盯着它看了太久。每个文件都声明“使用 Illuminate\Support\Carbon;”但碳 class 似乎仍未说明。
这是错误:
Symfony\Component\ErrorHandler\Error\FatalError
Declaration of App\Services\Shopify\ShopifyService::getOnlineOrders(App\Services\Shopify\Carbon
$startDate, App\Services\Shopify\Carbon $endDate) must be compatible
with
App\Services\Shopify\ShopifyServiceInterface::getOnlineOrders(Illuminate\Support\Carbon
$startDate, Illuminate\Support\Carbon $endDate)
这是工作:
<?php
namespace App\Jobs\Testing;
use App\Models\OnlineOrder;
use App\Services\Shopify\ShopifyService;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Carbon;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Arr;
use Carbon\Carbon as MexicanJoe;
use function json_encode;
use function app;
use Exception;
class OnlineOrderSyncJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $startDate;
protected $endDate;
/**
* Create a new job instance.
*
* @param Carbon $startDate
* @param Carbon $endDate
*/
public function __construct(Carbon $startDate, Carbon $endDate)
{
$this->startDate = $startDate;
$this->endDate = $endDate;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
// get all the created and updated orders
$orders = app(ShopifyService::class)->getOnlineOrders($this->startDate, $this->endDate);
Log::channel('dataSync')->info("Complete: OnlineOrderSyncJob", [
'startDate' => $this->startDate->toDateTimeLocalString(),
'endDate' => $this->endDate->toDateTimeLocalString(),
'Orders' => $orders
]);
}
/**
* Handle a job failure.
*
* @param Exception $exception
* @return void
*/
public function failed(Exception $exception)
{
Log::channel('dataSync')->error('UNABLE TO SYNC ONLINE ORDERS.', [
'errors' => json_encode($exception->getMessage()),
]);
}
}
这是作业调用的服务:
<?php
namespace App\Services\Shopify;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
use function config;
use function json_decode;
class ShopifyService implements ShopifyServiceInterface
{
/**
* Get all the conversations created or updated between two dates
*
* @param Carbon $startDate
* @param Carbon $endDate
* @return mixed
*/
public function getOnlineOrders(Carbon $startDate, Carbon $endDate)
{
$response = Http::withBasicAuth('[secret stuff]', '[more secret stuff]')->
get('https://[secret stuff]:[more secret stuff].myshopify.com/admin/api/2020-10/orders.json', [
'created_at_min' => $startDate->toDateTimeLocalString(),
'updated_at_max' => $endDate->toDateTimeLocalString(),
]);
$responseData = json_decode($response->getBody());
return $responseData;
}
}
这是界面:
<?php
namespace App\Services\Shopify;
use Illuminate\Support\Carbon;
interface ShopifyServiceInterface
{
/**
* Get all the audits modified between two dates
*
* @param Carbon $startDate
* @param Carbon $endDate
* @return mixed
*/
public function getOnlineOrders(Carbon $startDate, Carbon $endDate);
}
我最终删除了别名碳 class,刷新队列,运行 php artisan 优化,然后再次重新启动队列。我相信我的别名造成了麻烦,我在其他地方使用它没有问题,并将调查这里出了什么问题,但它现在正在运行。谢谢!
我在尝试最新工作时遇到声明错误。我已经建立了许多类似的工作,但我似乎无法找到它出现错误的问题。请帮忙!我可能只是盯着它看了太久。每个文件都声明“使用 Illuminate\Support\Carbon;”但碳 class 似乎仍未说明。
这是错误:
Symfony\Component\ErrorHandler\Error\FatalError
Declaration of App\Services\Shopify\ShopifyService::getOnlineOrders(App\Services\Shopify\Carbon $startDate, App\Services\Shopify\Carbon $endDate) must be compatible with App\Services\Shopify\ShopifyServiceInterface::getOnlineOrders(Illuminate\Support\Carbon $startDate, Illuminate\Support\Carbon $endDate)
这是工作:
<?php
namespace App\Jobs\Testing;
use App\Models\OnlineOrder;
use App\Services\Shopify\ShopifyService;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Carbon;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Arr;
use Carbon\Carbon as MexicanJoe;
use function json_encode;
use function app;
use Exception;
class OnlineOrderSyncJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $startDate;
protected $endDate;
/**
* Create a new job instance.
*
* @param Carbon $startDate
* @param Carbon $endDate
*/
public function __construct(Carbon $startDate, Carbon $endDate)
{
$this->startDate = $startDate;
$this->endDate = $endDate;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
// get all the created and updated orders
$orders = app(ShopifyService::class)->getOnlineOrders($this->startDate, $this->endDate);
Log::channel('dataSync')->info("Complete: OnlineOrderSyncJob", [
'startDate' => $this->startDate->toDateTimeLocalString(),
'endDate' => $this->endDate->toDateTimeLocalString(),
'Orders' => $orders
]);
}
/**
* Handle a job failure.
*
* @param Exception $exception
* @return void
*/
public function failed(Exception $exception)
{
Log::channel('dataSync')->error('UNABLE TO SYNC ONLINE ORDERS.', [
'errors' => json_encode($exception->getMessage()),
]);
}
}
这是作业调用的服务:
<?php
namespace App\Services\Shopify;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
use function config;
use function json_decode;
class ShopifyService implements ShopifyServiceInterface
{
/**
* Get all the conversations created or updated between two dates
*
* @param Carbon $startDate
* @param Carbon $endDate
* @return mixed
*/
public function getOnlineOrders(Carbon $startDate, Carbon $endDate)
{
$response = Http::withBasicAuth('[secret stuff]', '[more secret stuff]')->
get('https://[secret stuff]:[more secret stuff].myshopify.com/admin/api/2020-10/orders.json', [
'created_at_min' => $startDate->toDateTimeLocalString(),
'updated_at_max' => $endDate->toDateTimeLocalString(),
]);
$responseData = json_decode($response->getBody());
return $responseData;
}
}
这是界面:
<?php
namespace App\Services\Shopify;
use Illuminate\Support\Carbon;
interface ShopifyServiceInterface
{
/**
* Get all the audits modified between two dates
*
* @param Carbon $startDate
* @param Carbon $endDate
* @return mixed
*/
public function getOnlineOrders(Carbon $startDate, Carbon $endDate);
}
我最终删除了别名碳 class,刷新队列,运行 php artisan 优化,然后再次重新启动队列。我相信我的别名造成了麻烦,我在其他地方使用它没有问题,并将调查这里出了什么问题,但它现在正在运行。谢谢!