forked from jkapuscik2/design-patterns-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeviceTypeFactory.php
More file actions
41 lines (32 loc) · 902 Bytes
/
DeviceTypeFactory.php
File metadata and controls
41 lines (32 loc) · 902 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
<?php
namespace Structural\Flyweight;
class DeviceTypeFactory {
protected $deviceTypes = [];
public function getType (
string $location,
string $resolution,
string $producer,
string $operatingSystem): DeviceType {
$key = $this->getKey(
$location,
$resolution,
$producer,
$operatingSystem);
if (!array_key_exists($key, $this->deviceTypes)) {
$this->deviceTypes[$key] = new DeviceType(
$location,
$resolution,
$producer,
$operatingSystem
);
}
return $this->deviceTypes[$key];
}
protected function getKey (
string $location,
string $resolution,
string $producer,
string $operatingSystem) {
return md5(implode("_", func_get_args()));
}
}