@@ 20-35 (lines=16) @@ | ||
17 | ||
18 | abstract protected function handle($driver, $url, $encode); |
|
19 | ||
20 | public function shorten($url, $encode = true) |
|
21 | { |
|
22 | $short = false; |
|
23 | ||
24 | foreach ($this->drivers as $driver) { |
|
25 | if(!is_string($short)){ |
|
26 | $short = $this->handle($driver, $url, $encode); |
|
27 | } |
|
28 | } |
|
29 | ||
30 | if(is_string($short)){ |
|
31 | return $short; |
|
32 | } else { |
|
33 | throw new ShortenerException($this->error); |
|
34 | } |
|
35 | } |
|
36 | } |
@@ 39-58 (lines=20) @@ | ||
36 | } |
|
37 | } |
|
38 | ||
39 | public function shorten($url, $encode = true) |
|
40 | { |
|
41 | $short = false; |
|
42 | ||
43 | foreach ($this->drivers as $driver) { |
|
44 | if(!is_string($short)){ |
|
45 | try { |
|
46 | $short = $driver->shorten($url, $encode); |
|
47 | } catch (Exception $e) { |
|
48 | $this->error = $e; |
|
49 | } |
|
50 | } |
|
51 | } |
|
52 | ||
53 | if(is_string($short)){ |
|
54 | return $short; |
|
55 | } else { |
|
56 | throw $this->error; |
|
57 | } |
|
58 | } |
|
59 | } |