如何将我的自定义 google 日历模块用于 Laminas MVC 中的另一个自定义待办事项模块?

How to use my custom google calendar module into another custom todo module in Laminas MVC?

我在 laminas MVC 中创建了一个 Calendar module,它与 Google Calendar 交互,然后创建了另一个 Todo module,它应该与我的 Calendar module 交互. Calendar moduleCalendarController的签名就像

    public function __construct(
        ListProcess $listProcess,
        AddProcess $addProcess,
        EditProcess $editProcess,
        DeleteProcess $deleteProcess
    ) 

现在我在 Todo module 中应该启动调度过程的代码如下

public function execute(): array
    {
        $todo = json_decode((new CrmApiService())->getTodo($this->getTodoId()), true);
        $eventData["summary"] = $todo->title;
        $eventData["description"] = $todo->content;
        $eventData["startDateTime"] = $todo->nextActionDate;
        $eventData["endDateTime"] = $todo->nextActionDate;
        $calendar = new CalendarController();

        return $calendar->scheduleFromAnotherSource($eventData);
    }

当我执行此操作时,出现如下错误

Too few arguments to function CalendarModule\Controller\CalendarController::__construct(), 0 passed in D:\laminas\todo-module-integrated\vendor\iss-module\todo-module\src\Process\TodoScheduleProcess.php on line 53 and exactly 4 expected

我知道我不应该直接调用 CalendarController 而应该通过 Service.

我的问题是,我应该如何在 Todo module 中创建一个依赖于 Calendar moduleService 并且它应该与Calendar module 不需要 CalendarController 的参与,它有进一步的依赖性?

感谢大家的帮助。

以下是我的实现方式。 (希望对某人有所帮助)

在我的 Calendar-module 中,添加逻辑与 CalendarController 和它的调用 AddProcess 是分开的,这就是我从控制器添加事件的方式。 $result = $this->addProcess->execute($this->params()->fromPost());。 Google 身份验证通过单独的服务 CalendarClientService 处理。我的所有进程都访问此服务以进行身份​​验证,然后执行。

$client = $this->calendarClientService->getClient();
if (!$this->calendarClientService->authenticateClient($client)) {
    return ["error" => "authentication", "url" => filter_var($client->createAuthUrl(), FILTER_SANITIZE_URL)];
}

现在我在 Calendar-module 中创建了一个新服务,如下所示,我刚刚调用 AddProcess 并将新的 eventData.

传递给它
class CalendarService
{
    protected AddProcess $addProcess;

    public function __construct(AddProcess $addProcess)
    {
        $this->addProcess = $addProcess;
    }

    public function scheduleAsEvent($eventData)
    {
        $eventData["startDateTime"] = Carbon::parse($eventData["startDateTime"])->format("Y-m-d\TH:i");
        $eventData["endDateTime"] = Carbon::parse($eventData["endDateTime"])->format("Y-m-d\TH:i");

        return $this->addProcess->execute($eventData);
    }
}

然后从我的Todo-module,我按如下方式访问此服务

namespace TodoModule\Process;

use Carbon\Carbon;
use Google\Exception;
use Laminas\Cache\Exception\ExceptionInterface;
use Laminas\Mvc\Controller\AbstractActionController;
use CalendarModule\Service\CalendarService;
use TodoModule\Service\CrmApiService;

class TodoScheduleProcess extends AbstractActionController
{
    protected int $todoID;

    protected CalendarService $calendarService;

    public function __construct(CalendarService $calendarService)
    {
        $this->calendarService = $calendarService;
    }

    public function execute(): array
    {
        $todo = json_decode((new CrmApiService())->getTodo($this->getTodoId()));
        $eventData["summary"] = $todo->title;
        $eventData["description"] = $todo->content;
        $eventData["startDateTime"] = $todo->nextActionDate;
        $eventData["endDateTime"] = $todo->nextActionDate;

        return $this->calendarService->scheduleAsEvent($eventData);
    }

    public function getTodoId()
    {
        return $this->todoID;
    }

    public function setTodoId($id)
    {
        $this->todoID = $id;
    }
}```