1 | <?php namespace Arcanedev\GeoIP\Tasks; |
||
12 | class DownloadMaxmindDatabaseTask |
||
13 | { |
||
14 | /* ----------------------------------------------------------------- |
||
15 | | Main Methods |
||
16 | | ----------------------------------------------------------------- |
||
17 | */ |
||
18 | |||
19 | /** |
||
20 | * Run the task. |
||
21 | * |
||
22 | * @param string $url The database URL. |
||
23 | * @param string $path Destination path to save the file |
||
24 | * |
||
25 | * @return bool |
||
26 | * |
||
27 | * @throws Exception |
||
28 | */ |
||
29 | public static function run($url, $path) |
||
30 | { |
||
31 | $path = static::checkDestinationPath($path); |
||
|
|||
32 | |||
33 | static::checkUrl($url); |
||
34 | |||
35 | $tmpFile = tempnam(sys_get_temp_dir(), 'maxmind'); |
||
36 | file_put_contents($tmpFile, fopen($url, 'r')); |
||
37 | file_put_contents($path, gzopen($tmpFile, 'r')); |
||
38 | |||
39 | unlink($tmpFile); |
||
40 | |||
41 | return true; |
||
42 | } |
||
43 | |||
44 | /** |
||
45 | * Check the destination path. |
||
46 | * |
||
47 | * @param string $path |
||
48 | * |
||
49 | * @return string |
||
50 | * |
||
51 | * @throws \Exception |
||
52 | */ |
||
53 | private static function checkDestinationPath($path) |
||
60 | |||
61 | /** |
||
62 | * Check the url status. |
||
63 | * |
||
64 | * @param string $url |
||
65 | * |
||
66 | * @throws \Exception |
||
67 | */ |
||
68 | private static function checkUrl($url) |
||
76 | } |
||
77 |
Let’s assume you have a class which uses late-static binding:
}
The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the
getSomeVariable()
on that sub-class, you will receive a runtime error:In the case above, it makes sense to update
SomeClass
to useself
instead: