-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlaravel_interfaces.php
More file actions
42 lines (33 loc) · 952 Bytes
/
laravel_interfaces.php
File metadata and controls
42 lines (33 loc) · 952 Bytes
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
<?php
declare(strict_types=1);
interface NotificationService
{
public function send($to, $message);
}
class EmailNotificationService implements NotificationService
{
public function send($to, $message): void
{
echo " Sending email $to: $message";
}
}
class SMSNotificationService implements NotificationService
{
public function send($to, $message): void
{
echo " Sending SMS $to: $message";
}
}
class OrderProcessor
{
public function __construct(private NotificationService $notifier) {}
public function processOrder($order): void
{
$this->notifier->send($order["email"], $order["message"]);
}
}
$order = ["email" => "me@me.it","message" => "My email message"];
$emailProcessor = new OrderProcessor(new EmailNotificationService());
$emailProcessor->processOrder($order);
$smsProcessor = new OrderProcessor(new SMSNotificationService());
$smsProcessor->processOrder($order);