Total Complexity | 8 |
Total Lines | 53 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
7 | class Shorturl |
||
8 | { |
||
9 | protected $factory; |
||
10 | protected $driver; |
||
11 | private $driver_instance; |
||
12 | |||
13 | public function __construct (DriverFactory $factory) |
||
16 | } |
||
17 | |||
18 | /** |
||
19 | * @param string $driver |
||
20 | * |
||
21 | * @return Shorturl |
||
22 | */ |
||
23 | public function onDriver (string $driver) |
||
24 | { |
||
25 | $this->driver = $driver; |
||
26 | $this->setDriverInstance(); |
||
27 | return $this; |
||
28 | } |
||
29 | |||
30 | /** |
||
31 | * @return void |
||
32 | */ |
||
33 | private function setDriverInstance () |
||
34 | { |
||
35 | $this->driver_instance = $this->factory->make($this->getDriver()); |
||
36 | } |
||
37 | |||
38 | /** |
||
39 | * |
||
40 | * Get name of current driver in use |
||
41 | * |
||
42 | * @return string |
||
43 | */ |
||
44 | public function getDriver (): string |
||
45 | { |
||
46 | return $this->driver ?: config("shorturl.drivers.default"); |
||
47 | } |
||
48 | |||
49 | public function __call ($method, $args) |
||
50 | { |
||
51 | return call_user_func_array(array ($this->getDriverInstance(), $method), $args); |
||
52 | } |
||
53 | |||
54 | private function getDriverInstance () |
||
60 | } |
||
61 | } |