Skip to content

Commit

Permalink
update some methods in object and models
Browse files Browse the repository at this point in the history
  • Loading branch information
tanhongit committed Oct 17, 2023
1 parent 8171161 commit 2c10816
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 20 deletions.
16 changes: 0 additions & 16 deletions src/Interfaces/EventInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
10 changes: 9 additions & 1 deletion src/Models/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class Event
{
public array $eventConfig = [];
private array $eventConfig = [];

public string $platform = EventConstant::DEFAULT_PLATFORM;

Expand All @@ -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
*
Expand Down
2 changes: 1 addition & 1 deletion src/Models/Setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class Setting
{
public array $settings = [];
private array $settings = [];

private string $settingFile = '';

Expand Down
13 changes: 11 additions & 2 deletions src/Objects/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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])) {
Expand Down

0 comments on commit 2c10816

Please sign in to comment.