7
7
*/
8
8
9
9
namespace Seta0909 \LaravelTwStreetname ;
10
+
10
11
class LaravelTwStreetname
11
12
{
12
13
private static $ instance ;
@@ -15,29 +16,35 @@ class LaravelTwStreetname
15
16
private static $ countrys ;
16
17
private static $ streets ;
17
18
private static $ zipCode ;
18
- private static $ cache ;
19
19
20
20
private static function getInstance ()
21
21
{
22
22
if (!isset (self ::$ instance )) {
23
23
$ class = __CLASS__ ;
24
24
self ::$ instance = new $ class ();
25
25
//先載載入快取
26
+ if (file_exists (dirname (__FILE__ ) . "/Origin.json " )) {
27
+ self ::$ originData = json_decode (file_get_contents (dirname (__FILE__ ) . "/Origin.json " ), true );
28
+ }
29
+ if (file_exists (dirname (__FILE__ ) . "/Citys.json " )) {
30
+ self ::$ citys = json_decode (file_get_contents (dirname (__FILE__ ) . "/Citys.json " ), true );
31
+ }
32
+ if (file_exists (dirname (__FILE__ ) . "/Countrys.json " )) {
33
+ self ::$ countrys = json_decode (file_get_contents (dirname (__FILE__ ) . "/Countrys.json " ), true );
34
+ }
35
+ if (file_exists (dirname (__FILE__ ) . "/Streets.json " )) {
36
+ self ::$ streets = json_decode (file_get_contents (dirname (__FILE__ ) . "/Streets.json " ), true );
37
+ }
38
+ if (file_exists (dirname (__FILE__ ) . "/ZipCode.json " )) {
39
+ self ::$ zipCode = json_decode (file_get_contents (dirname (__FILE__ ) . "/ZipCode.json " ), true );
40
+ }
41
+
26
42
27
- session_start ();
28
- self ::$ cache = 'session ' ;
29
- self ::$ originData = (isset ($ _SESSION ['LaravelTwStreetnameOrigin ' ])) ? $ _SESSION ['LaravelTwStreetnameOrigin ' ]:'' ;
30
- self ::$ citys = (isset ($ _SESSION ['LaravelTwStreetnameCitys ' ])) ? $ _SESSION ['LaravelTwStreetnameCitys ' ]:'' ;
31
- self ::$ countrys = (isset ($ _SESSION ['LaravelTwStreetnameCountrys ' ])) ? $ _SESSION ['LaravelTwStreetnameCountrys ' ]:'' ;
32
- self ::$ streets = (isset ($ _SESSION ['LaravelTwStreetnameStreets ' ])) ? $ _SESSION ['LaravelTwStreetnameStreets ' ]:'' ;
33
- self ::$ zipCode = (isset ($ _SESSION ['LaravelTwStreetnameZipCode ' ])) ? $ _SESSION ['LaravelTwStreetnameZipCode ' ]:'' ;
34
-
35
-
36
43
//載入街道Json資料
37
44
if (!is_array (self ::$ originData )) {
38
45
$ streetString = file_get_contents (dirname (__FILE__ ) . "/address_data.json " );
39
46
self ::$ originData = json_decode ($ streetString , true );
40
- $ _SESSION [ ' LaravelTwStreetnameOrigin ' ] = self ::$ originData ;
47
+ file_put_contents ( dirname ( __FILE__ ) . " /Origin.json " , json_encode ( self ::$ originData)) ;
41
48
}
42
49
//載入郵遞區號Json資料
43
50
if (!is_array (self ::$ zipCode )) {
@@ -48,7 +55,7 @@ private static function getInstance()
48
55
$ temp [$ val ['country ' ]] = $ val ['mailcode ' ];
49
56
}
50
57
self ::$ zipCode = $ temp ;
51
- $ _SESSION [ ' LaravelTwStreetnameZipCode ' ] = self ::$ zipCode ;
58
+ file_put_contents ( dirname ( __FILE__ ) . " /ZipCode.json " , json_encode ( self ::$ zipCode)) ;
52
59
}
53
60
54
61
//初始化資料
@@ -59,26 +66,25 @@ private static function getInstance()
59
66
self ::$ citys [] = $ val ;
60
67
}
61
68
}
62
- $ _SESSION [ ' LaravelTwStreetnameCitys ' ] = self ::$ citys ;
69
+ file_put_contents ( dirname ( __FILE__ ) . " /Citys.json " , json_encode ( self ::$ citys)) ;
63
70
}
64
71
//載入鄉鎮區
65
72
if (!is_array (self ::$ countrys )) {
66
73
foreach (self ::$ citys as $ key => $ val ) {
67
74
self ::$ countrys [$ val ['uid ' ]] = self ::searchLink ($ val ['uid ' ]);
68
75
}
69
- $ _SESSION [ ' LaravelTwStreetnameCountrys ' ] = self ::$ countrys ;
76
+ file_put_contents ( dirname ( __FILE__ ) . " /Countrys.json " , json_encode ( self ::$ countrys)) ;
70
77
}
71
78
//載入街道
72
79
if (!is_array (self ::$ streets )) {
73
80
foreach (self ::$ countrys as $ key => $ country ) {
74
81
foreach ($ country as $ val ) {
75
- if (isset ($ val ['uid ' ]))
76
- {
82
+ if (isset ($ val ['uid ' ])) {
77
83
self ::$ streets [$ val ['uid ' ]] = self ::searchLink ($ val ['uid ' ]);
78
84
}
79
85
}
80
86
}
81
- $ _SESSION [ ' LaravelTwStreetnameStreets ' ] = self ::$ streets ;
87
+ file_put_contents ( dirname ( __FILE__ ) . " /Streets.json " , json_encode ( self ::$ streets)) ;
82
88
}
83
89
}
84
90
}
0 commit comments