forked from Kantai235/php-design-pattern
-
Notifications
You must be signed in to change notification settings - Fork 0
/
StorageAdapter.php
53 lines (46 loc) · 898 Bytes
/
StorageAdapter.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
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
<?php
namespace DesignPatterns\Structural\DataMapper;
/**
* Class StorageAdapter.
*/
class StorageAdapter
{
/**
* @var array
*/
protected $data = [];
/**
* StorageAdapter constructor.
*
* @param array $data
*/
public function __construct(array $data)
{
$this->data = $data;
}
/**
* @param int $id
*
* @return array|null
*/
public function findById(int $id)
{
if (isset($this->data[$id])) {
return $this->data[$id];
}
return null;
}
/**
* @param string $island
*
* @return array|null
*/
public function findByIsland(string $island)
{
$key = array_search($island, array_column($this->data, 'island'));
if (false !== $key) {
return $this->data[$key];
}
return null;
}
}