-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.php
executable file
·28 lines (22 loc) · 927 Bytes
/
main.php
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
<?php
namespace Behavioral\ChainOfResponsibility;
require_once "./vendor/autoload.php";
// Create the starting element of the chain
// Создаём начальный элемент цепочки
$notice = new NoticeHandler();
try {
// Add items to the chain.
// Добавляем элементы в цепочку.
$notice->setNext(new WarningHandler())->setNext(new ErrorHandler());
printf("%s", "Call the handler by name:\n");
$notice->execute(NoticeHandler::class);
$notice->execute(WarningHandler::class);
$notice->execute(ErrorHandler::class);
print "\n";
printf("%s", "Call all handlers in the chain before request by name:\n");
$notice->execute(NoticeHandler::class, true);
$notice->execute(WarningHandler::class, true);
$notice->execute(ErrorHandler::class, true);
} catch (\Exception $e) {
printf("%s", "Caught exception: " . $e->getMessage() . "\n");
}