From 2c10816a5a7e40b08ec3b3fb2ae215e8c61709c7 Mon Sep 17 00:00:00 2001 From: Tan Nguyen Date: Tue, 17 Oct 2023 22:28:56 +0700 Subject: [PATCH] update some methods in object and models --- src/Interfaces/EventInterface.php | 16 ---------------- src/Models/Event.php | 10 +++++++++- src/Models/Setting.php | 2 +- src/Objects/Validator.php | 13 +++++++++++-- 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/Interfaces/EventInterface.php b/src/Interfaces/EventInterface.php index 571365c..fdbb2b4 100644 --- a/src/Interfaces/EventInterface.php +++ b/src/Interfaces/EventInterface.php @@ -2,26 +2,10 @@ namespace LbilTech\TelegramGitNotifier\Interfaces; -use LbilTech\TelegramGitNotifier\Constants\EventConstant; use Symfony\Component\HttpFoundation\Request; interface EventInterface { -// /** -// * Validate access event before send notify -// * -// * @param string $platform Source code platform (GitHub, GitLab) -// * @param string $event Event name (push, pull_request) -// * @param $payload -// * -// * @return bool -// */ -// public function validateAccessEvent( -// string $platform, -// string $event, -// $payload -// ): bool; - /** * Get action name of event from payload data * diff --git a/src/Models/Event.php b/src/Models/Event.php index c223f56..a6a8287 100644 --- a/src/Models/Event.php +++ b/src/Models/Event.php @@ -6,7 +6,7 @@ class Event { - public array $eventConfig = []; + private array $eventConfig = []; public string $platform = EventConstant::DEFAULT_PLATFORM; @@ -30,6 +30,14 @@ public function setPlatformFile(string $platformFile): void $this->platformFile = $platformFile; } + /** + * @return array + */ + public function getEventConfig(): array + { + return $this->eventConfig; + } + /** * Set event config * diff --git a/src/Models/Setting.php b/src/Models/Setting.php index 11bc475..6c07913 100644 --- a/src/Models/Setting.php +++ b/src/Models/Setting.php @@ -6,7 +6,7 @@ class Setting { - public array $settings = []; + private array $settings = []; private string $settingFile = ''; diff --git a/src/Objects/Validator.php b/src/Objects/Validator.php index 77969ce..944529d 100644 --- a/src/Objects/Validator.php +++ b/src/Objects/Validator.php @@ -20,7 +20,16 @@ public function __construct(Setting $setting, Event $event) $this->event = $event; } - public function accessEvent( + /** + * Validate is access event before send notify + * + * @param string $platform Source code platform (GitHub, GitLab) + * @param string $event Event name (push, pull_request) + * @param $payload + * + * @return bool + */ + public function isAccessEvent( string $platform, string $event, $payload @@ -34,7 +43,7 @@ public function accessEvent( } $this->event->setEventConfig($platform); - $eventConfig = $this->event->eventConfig[tgn_convert_event_name($event)] ?? false; + $eventConfig = $this->event->getEventConfig()[tgn_convert_event_name($event)] ?? false; $action = $this->getActionOfEvent($payload); if (!empty($action) && isset($eventConfig[$action])) {