1 | <?php |
||
8 | class TrackerFactory |
||
9 | { |
||
10 | /** |
||
11 | * Container instance. |
||
12 | * |
||
13 | * @var \Illuminate\Contracts\Container\Container |
||
14 | */ |
||
15 | protected $container; |
||
16 | |||
17 | /** |
||
18 | * Tracker type array. |
||
19 | * |
||
20 | * @var array |
||
21 | */ |
||
22 | protected $trackers; |
||
23 | |||
24 | /** |
||
25 | * TrackerFactory constructor. |
||
26 | * |
||
27 | * @param \Illuminate\Contracts\Container\Container $container |
||
28 | * @param array $trackers |
||
29 | */ |
||
30 | 9 | public function __construct(Container $container, array $trackers) |
|
31 | { |
||
32 | 9 | $this->container = $container; |
|
33 | |||
34 | 9 | foreach ($trackers as $abstract) { |
|
35 | 9 | $handle = $container[$abstract]->getHandle(); |
|
36 | |||
37 | 9 | $this->trackers[$handle] = $abstract; |
|
38 | 9 | } |
|
39 | 9 | } |
|
40 | |||
41 | /** |
||
42 | * Source a model from an argument. |
||
43 | * |
||
44 | * @param $arg |
||
45 | * @return mixed |
||
46 | */ |
||
47 | 5 | protected function sourceModel($arg) |
|
63 | |||
64 | /** |
||
65 | * Destroy a tracker by id or model. |
||
66 | * |
||
67 | * @param string|\BoxedCode\Tracking\TrackableResourceModel $mixed |
||
68 | */ |
||
69 | 2 | public function destroy($mixed) |
|
75 | |||
76 | /** |
||
77 | * Get a tracker by id or model. |
||
78 | * |
||
79 | * @param $mixed |
||
80 | * @return string|\BoxedCode\Tracking\TrackableResourceModel $mixed |
||
81 | */ |
||
82 | 3 | public function resource($mixed) |
|
92 | |||
93 | /** |
||
94 | * Dynamically pass calls to tracker instances. |
||
95 | * |
||
96 | * @param $name |
||
97 | * @param array $arguments |
||
98 | * @return \BoxedCode\Tracking\Contracts\Tracker |
||
99 | */ |
||
100 | 1 | public function __call($name, $arguments = []) |
|
112 | } |
||
113 |