-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEventInterface.php
More file actions
123 lines (100 loc) · 2.45 KB
/
EventInterface.php
File metadata and controls
123 lines (100 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
declare (strict_types=1);
namespace Mateodioev\TgHandler\Events;
use Closure;
use Mateodioev\Bots\Telegram\Api;
use Mateodioev\TgHandler\Context;
use Mateodioev\TgHandler\Db\DbInterface;
use Mateodioev\TgHandler\Middleware\Middleware;
use Psr\Log\LoggerInterface;
/**
* This interface represents an event
*/
interface EventInterface
{
/**
* Get event type
*/
public function type(): EventType;
/**
* Set api and context vars
*/
public function setVars(Api $bot, Context $ctx): static;
/**
* Get description
*/
public function description(): string;
/**
* Set description
*/
public function setDescription(string $description): void;
/**
* Get logger
*/
public function logger(): LoggerInterface;
/**
* @see static::logger
* @deprecated v3.5.0 Use `static::logger`
*/
public function getLogger(): LoggerInterface;
/**
* Set logger
*/
public function setLogger(LoggerInterface $logger): static;
/**
* Get db to storage data
*/
public function db(): DbInterface;
/**
* Get db to storage data
*/
public function setDb(DbInterface $db): static;
/**
* Return true if event has middlewares
*/
public function hasMiddlewares(): bool;
/**
* Get middlewares
* @return Middleware[]
*/
public function middlewares(): array;
/**
* Return true if event has Attributes as Filters
*/
public function hasFilters(): bool;
/**
* Validates all filters, return `false` if any of them fail
*/
public function validateFilters(): bool;
/**
* Add single middleware. If two middlewares have the same name, the last one will be used
*/
public function addMiddleware(Closure $middleware): static;
/**
* @param Closure[] $middlewares
*/
public function setMiddlewares(array $middlewares): static;
/**
* Return true if the event is valid
*/
public function isValid(): bool;
/**
* Run event
* @param array $args Middlewares results
* @return ?EventInterface|void
*/
public function execute(array $args = []);
/**
* Get Telegram bot api instance
*/
public function api(): Api;
/**
* Get Context
*/
public function ctx(): Context;
/**
* Stop the bot in the next iteration
* @return void
*/
public function stop(): void;
}