-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolid_o.php
More file actions
37 lines (28 loc) · 862 Bytes
/
solid_o.php
File metadata and controls
37 lines (28 loc) · 862 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
<?php
interface ObjectsHandlerInterface {
public function handleObjects(array $objects): array;
}
class SomeObject {
protected $name;
public function __construct(string $name) { }
public function getObjectName() { }
}
class SomeObjectsHandler implements ObjectsHandlerInterface {
public function __construct() { }
public function handleObjects(array $objects): array {
$handlers = [];
foreach ($objects as $object) {
if ($object->getObjectName() == 'object_1')
$handlers[] = 'handle_object_1';
if ($object->getObjectName() == 'object_2')
$handlers[] = 'handle_object_2';
}
return $handlers;
}
}
$objects = [
new SomeObject('object_1'),
new SomeObject('object_2')
];
$soh = new SomeObjectsHandler();
$soh->handleObjects($objects);