hughcube /
ipdb
| 1 | <?php |
||
| 2 | |||
| 3 | namespace HughCube\IpDb\Proxies; |
||
| 4 | |||
| 5 | use HughCube\IpDb\Readers\IpDbReader; |
||
| 6 | use HughCube\IpDb\Readers\Reader; |
||
| 7 | |||
| 8 | abstract class Proxy |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * @var Reader|null |
||
| 12 | */ |
||
| 13 | protected $reader = null; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * Proxy constructor. |
||
| 17 | * |
||
| 18 | * @param $reader |
||
| 19 | * |
||
| 20 | * @throws \Exception |
||
| 21 | */ |
||
| 22 | 4 | public function __construct(Reader $reader = null) |
|
| 23 | { |
||
| 24 | 4 | $reader = null === $reader ? $this->getDefaultReader() : $reader; |
|
| 25 | |||
| 26 | 4 | $this->reader = $reader; |
|
| 27 | 4 | } |
|
| 28 | |||
| 29 | /** |
||
| 30 | * 获取默认的 Reader. |
||
| 31 | * |
||
| 32 | * @throws \Exception |
||
| 33 | * |
||
| 34 | * @return Reader |
||
| 35 | */ |
||
| 36 | 4 | protected function getDefaultReader() |
|
| 37 | { |
||
| 38 | 4 | $dbFile = __DIR__.'/../../data/ipipfree.ipdb'; |
|
| 39 | |||
| 40 | 4 | return new IpDbReader($dbFile); |
|
| 41 | } |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @return Reader|null |
||
| 45 | */ |
||
| 46 | 4 | public function getReader() |
|
| 47 | { |
||
| 48 | 4 | return $this->reader; |
|
| 49 | } |
||
| 50 | |||
| 51 | /** |
||
| 52 | * 根据ip查找信息. |
||
| 53 | * |
||
| 54 | * @param string $ip 查找的ip |
||
| 55 | * @param string $language 语言 |
||
| 56 | * |
||
| 57 | * @return array|null |
||
| 58 | */ |
||
| 59 | 4 | public function find($ip, $language) |
|
| 60 | { |
||
| 61 | 4 | return $this->getReader()->find($ip, $language); |
|
| 62 | } |
||
| 63 | |||
| 64 | /** |
||
| 65 | * 根据ip查找信息map. |
||
| 66 | * |
||
| 67 | * @param string $ip 查找的ip |
||
| 68 | * @param string $language 语言 |
||
| 69 | * |
||
| 70 | * @return array|null |
||
| 71 | */ |
||
| 72 | 4 | public function findMap($ip, $language) |
|
| 73 | { |
||
| 74 | 4 | return $this->getReader()->findMap($ip, $language); |
|
|
0 ignored issues
–
show
|
|||
| 75 | } |
||
| 76 | |||
| 77 | /** |
||
| 78 | * 根据ip查找信息对象 |
||
| 79 | * |
||
| 80 | * @param string $ip 查找的ip |
||
| 81 | * @param string $language 语言 |
||
| 82 | * |
||
| 83 | * @return mixed |
||
| 84 | */ |
||
| 85 | abstract public function findInfo($ip, $language); |
||
| 86 | } |
||
| 87 |
If the returned type also contains false, it is an indicator that maybe an error condition leading to the specific return statement remains unhandled.