File: /var/www/heifetz/heifetz-app/models/Modules/GoogleSheetsModule.php
<?php
declare(strict_types=1);
namespace Models\Modules;
use Helpers\Data;
class GoogleSheetsModule extends AbstractModule
{
const NAME = 'googleSheets';
const DATA = [
'title' => 'Интеграция с GoogleSheets',
'description' => 'Модуль подключает интеграцию с сервисом GoogleSheets',
'image' => '/assets/modules/googleSheets.png',
'template' => 'googleSheets',
];
const FIELD_PROJECT_ID = 'project_id';
const FIELD_PRIVATE_KEY_ID = 'private_key_id';
const FIELD_PRIVATE_KEY = 'private_key';
const FIELD_CLIENT_EMAIL = 'client_email';
const FIELD_CLIENT_ID = 'client_id';
const FIELD_CERT = 'client_x509_cert_url';
public static function getProjectId(): ?string
{
return self::getConfig()[self::FIELD_PROJECT_ID] ?? null;
}
public static function getPrivateKeyId(): ?string
{
return self::getConfig()[self::FIELD_PRIVATE_KEY_ID] ?? null;
}
public static function getPrivateKey(): ?string
{
return self::getConfig()[self::FIELD_PRIVATE_KEY] ?? null;
}
public static function getClientEmail(): ?string
{
return self::getConfig()[self::FIELD_CLIENT_EMAIL] ?? null;
}
public static function getClientId(): ?string
{
return self::getConfig()[self::FIELD_CLIENT_ID] ?? null;
}
public static function getCert(): ?string
{
return self::getConfig()[self::FIELD_CERT] ?? null;
}
public static function getAuthJson(): string
{
$googleSheetsAuth = [
'type' => 'service_account',
'project_id' => GoogleSheetsModule::getProjectId(),
'private_key_id' => GoogleSheetsModule::getPrivateKeyId(),
'private_key' => GoogleSheetsModule::getPrivateKey(),
'client_email' => GoogleSheetsModule::getClientEmail(),
'client_id' => GoogleSheetsModule::getClientId(),
'auth_uri' => "https://accounts.google.com/o/oauth2/auth",
'token_uri' => "https://oauth2.googleapis.com/token",
'auth_provider_x509_cert_url' => "https://www.googleapis.com/oauth2/v1/certs",
'client_x509_cert_url' => GoogleSheetsModule::getCert(),
'universe_domain' => "googleapis.com",
];
return Data::jsonEncode($googleSheetsAuth, true);
}
}