HEX
Server: nginx/1.18.0
System: Linux iZj6c1ieg2jrpk1z5tzi19Z 6.3.9-1.el7.elrepo.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jun 21 22:18:40 EDT 2023 x86_64
User: www (1001)
PHP: 8.2.4
Disabled: passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Upload Files
File: /www/wwwroot/www.cytocare.cn/wp-content/plugins/mailpoet/lib/Automation/Engine/Engine.php
<?php declare(strict_types = 1);

namespace MailPoet\Automation\Engine;

if (!defined('ABSPATH')) exit;


use MailPoet\Automation\Engine\API\API;
use MailPoet\Automation\Engine\Control\StepHandler;
use MailPoet\Automation\Engine\Control\TriggerHandler;
use MailPoet\Automation\Engine\Endpoints\Automations\AutomationsCreateFromTemplateEndpoint;
use MailPoet\Automation\Engine\Endpoints\Automations\AutomationsDeleteEndpoint;
use MailPoet\Automation\Engine\Endpoints\Automations\AutomationsDuplicateEndpoint;
use MailPoet\Automation\Engine\Endpoints\Automations\AutomationsGetEndpoint;
use MailPoet\Automation\Engine\Endpoints\Automations\AutomationsPutEndpoint;
use MailPoet\Automation\Engine\Endpoints\Automations\AutomationTemplateGetEndpoint;
use MailPoet\Automation\Engine\Endpoints\Automations\AutomationTemplatesGetEndpoint;
use MailPoet\Automation\Engine\Storage\AutomationStorage;
use MailPoet\Automation\Integrations\Core\CoreIntegration;
use MailPoet\Automation\Integrations\WordPress\WordPressIntegration;

class Engine {
  const CAPABILITY_MANAGE_AUTOMATIONS = 'mailpoet_manage_automations';

  /** @var API */
  private $api;

  /** @var CoreIntegration */
  private $coreIntegration;

  /** @var WordPressIntegration */
  private $wordPressIntegration;

  /** @var Registry */
  private $registry;

  /** @var StepHandler */
  private $stepHandler;

  /** @var TriggerHandler */
  private $triggerHandler;

  /** @var WordPress */
  private $wordPress;

  /** @var AutomationStorage */
  private $automationStorage;

  public function __construct(
    API $api,
    CoreIntegration $coreIntegration,
    WordPressIntegration $wordPressIntegration,
    Registry $registry,
    StepHandler $stepHandler,
    TriggerHandler $triggerHandler,
    WordPress $wordPress,
    AutomationStorage $automationStorage
  ) {
    $this->api = $api;
    $this->coreIntegration = $coreIntegration;
    $this->wordPressIntegration = $wordPressIntegration;
    $this->registry = $registry;
    $this->stepHandler = $stepHandler;
    $this->triggerHandler = $triggerHandler;
    $this->wordPress = $wordPress;
    $this->automationStorage = $automationStorage;
  }

  public function initialize(): void {
    $this->registerApiRoutes();

    $this->api->initialize();
    $this->stepHandler->initialize();
    $this->triggerHandler->initialize();

    $this->coreIntegration->register($this->registry);
    $this->wordPressIntegration->register($this->registry);
    $this->wordPress->doAction(Hooks::INITIALIZE, [$this->registry]);
    $this->registerActiveTriggerHooks();
  }

  private function registerApiRoutes(): void {
    $this->wordPress->addAction(Hooks::API_INITIALIZE, function (API $api) {
      $api->registerGetRoute('automations', AutomationsGetEndpoint::class);
      $api->registerPutRoute('automations/(?P<id>\d+)', AutomationsPutEndpoint::class);
      $api->registerDeleteRoute('automations/(?P<id>\d+)', AutomationsDeleteEndpoint::class);
      $api->registerPostRoute('automations/(?P<id>\d+)/duplicate', AutomationsDuplicateEndpoint::class);
      $api->registerPostRoute('automations/create-from-template', AutomationsCreateFromTemplateEndpoint::class);
      $api->registerGetRoute('automation-templates', AutomationTemplatesGetEndpoint::class);
      $api->registerGetRoute('automation-templates/(?P<slug>.+)', AutomationTemplateGetEndpoint::class);
    });
  }

  private function registerActiveTriggerHooks(): void {
    $triggerKeys = $this->automationStorage->getActiveTriggerKeys();
    foreach ($triggerKeys as $triggerKey) {
      $instance = $this->registry->getTrigger($triggerKey);
      if ($instance) {
        $instance->registerHooks();
      }
    }
  }
}