@@ 16-67 (lines=52) @@ | ||
13 | ||
14 | use Emarsys\Exception\Mapping\NotFoundFieldException; |
|
15 | ||
16 | class Events |
|
17 | { |
|
18 | private $mapping = array(); |
|
19 | ||
20 | private $systemFields = array(); |
|
21 | ||
22 | /** |
|
23 | * @param array $mapping |
|
24 | */ |
|
25 | public function addMapping(array $mapping) |
|
26 | { |
|
27 | $this->mapping = array_merge($this->mapping, $mapping); |
|
28 | } |
|
29 | ||
30 | /** |
|
31 | * @param $nameOrId |
|
32 | * |
|
33 | * @return string|int |
|
34 | */ |
|
35 | public function find($nameOrId) |
|
36 | { |
|
37 | if (is_string($nameOrId)) { |
|
38 | return $this->findByName($nameOrId); |
|
39 | } |
|
40 | ||
41 | if (is_int($nameOrId)) { |
|
42 | return $this->findById($nameOrId); |
|
43 | } |
|
44 | } |
|
45 | ||
46 | public function findByName($name) |
|
47 | { |
|
48 | if (array_key_exists($name, $this->systemFields)) { |
|
49 | return $this->systemFields[$name]; |
|
50 | } |
|
51 | ||
52 | if (array_key_exists($name, $this->mapping)) { |
|
53 | return $this->mapping[$name]; |
|
54 | } |
|
55 | ||
56 | throw new NotFoundFieldException($name); |
|
57 | } |
|
58 | ||
59 | /** |
|
60 | * @param int $id |
|
61 | * |
|
62 | * @return string |
|
63 | */ |
|
64 | public function findById($id) |
|
65 | { |
|
66 | } |
|
67 | } |
|
68 |
@@ 21-91 (lines=71) @@ | ||
18 | * |
|
19 | * @author Claude Khedhiri <[email protected]> |
|
20 | */ |
|
21 | class Fields |
|
22 | { |
|
23 | /** |
|
24 | * @var array |
|
25 | */ |
|
26 | private $mapping = array(); |
|
27 | ||
28 | /** |
|
29 | * @var array |
|
30 | */ |
|
31 | private $systemFields = array(); |
|
32 | ||
33 | /** |
|
34 | * Fields constructor. |
|
35 | */ |
|
36 | public function __construct() |
|
37 | { |
|
38 | $this->systemFields = require __DIR__.'/../../config/fields.php'; |
|
39 | } |
|
40 | ||
41 | /** |
|
42 | * @param array $mapping |
|
43 | */ |
|
44 | public function addMapping(array $mapping) |
|
45 | { |
|
46 | $this->mapping = array_merge($this->mapping, $mapping); |
|
47 | } |
|
48 | ||
49 | /** |
|
50 | * @param $nameOrId |
|
51 | * |
|
52 | * @return string|int |
|
53 | */ |
|
54 | public function find($nameOrId) |
|
55 | { |
|
56 | if (is_string($nameOrId)) { |
|
57 | return $this->findByName($nameOrId); |
|
58 | } |
|
59 | ||
60 | if (is_int($nameOrId)) { |
|
61 | return $this->findById($nameOrId); |
|
62 | } |
|
63 | } |
|
64 | ||
65 | /** |
|
66 | * @param $name |
|
67 | * |
|
68 | * @return int |
|
69 | */ |
|
70 | public function findByName($name) |
|
71 | { |
|
72 | if (array_key_exists($name, $this->systemFields)) { |
|
73 | return $this->systemFields[$name]; |
|
74 | } |
|
75 | ||
76 | if (array_key_exists($name, $this->mapping)) { |
|
77 | return $this->mapping[$name]; |
|
78 | } |
|
79 | ||
80 | throw new NotFoundFieldException($name); |
|
81 | } |
|
82 | ||
83 | /** |
|
84 | * @param int $id |
|
85 | * |
|
86 | * @return string |
|
87 | */ |
|
88 | public function findById($id) |
|
89 | { |
|
90 | } |
|
91 | } |
|
92 |