You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
2.1 KiB
72 lines
2.1 KiB
<?php
|
|
|
|
abstract class FormHandler {
|
|
protected $nextHandler;
|
|
|
|
public function __construct($nextHandler = null) {
|
|
$this->nextHandler = $nextHandler;
|
|
}
|
|
|
|
public function handle($data) {
|
|
if ($this->nextHandler) {
|
|
return $this->nextHandler->handle($data);
|
|
}
|
|
return ['success' => true, 'message' => 'Форма обработана'];
|
|
}
|
|
}
|
|
|
|
class b24Handler extends FormHandler {
|
|
public function handle($data) {
|
|
// Логика отправки в Mailchimp
|
|
error_log("Отправка в b24: " . json_encode($data));
|
|
|
|
// Вызываем следующий обработчик в цепочке
|
|
return parent::handle($data);
|
|
}
|
|
}
|
|
|
|
class zohoHandler extends FormHandler {
|
|
public function handle($data) {
|
|
// Логика отправки в HubSpot
|
|
error_log("Отправка в Zoho: " . json_encode($data));
|
|
|
|
return parent::handle($data);
|
|
}
|
|
}
|
|
|
|
class mindboxHandler extends FormHandler {
|
|
public function handle($data) {
|
|
// Отправка в стандартный обработчик (например, email)
|
|
error_log("Отправка в mindBox: " . json_encode($data));
|
|
|
|
return parent::handle($data);
|
|
}
|
|
}
|
|
|
|
class emailHandler extends FormHandler {
|
|
public function handle($data) {
|
|
$to = 'fcs.andrew@gmail.com';
|
|
$subject = 'Test Email';
|
|
$message = json_encode($data, JSON_PRETTY_PRINT); // Преобразуем данные в строку
|
|
$headers = ['Content-Type: text/plain; charset=UTF-8'];
|
|
wp_mail($to, $subject, $message, $headers);
|
|
return parent::handle($data);
|
|
}
|
|
}
|
|
|
|
class FormHandlerFactory {
|
|
public static function getHandler() {
|
|
// Базовый обработчик
|
|
$handler = new emailHandler();
|
|
|
|
// Добавляем в цепочку обработчиков
|
|
$handler = new mindboxHandler($handler);
|
|
$handler = new zohoHandler($handler);
|
|
$handler = new b24Handler($handler);
|
|
return $handler;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
?>
|