1 | <?php |
||
18 | class Geolocate |
||
19 | { |
||
20 | const KEY = 'GEOLOCATE'; |
||
21 | |||
22 | /** |
||
23 | * @var Geocoder |
||
24 | */ |
||
25 | private $geocoder; |
||
26 | |||
27 | /** |
||
28 | * Returns the client location. |
||
29 | * |
||
30 | * @param ServerRequestInterface $request |
||
31 | * |
||
32 | * @return AddressCollection|null |
||
33 | */ |
||
34 | public static function getLocation(ServerRequestInterface $request) |
||
38 | |||
39 | /** |
||
40 | * Constructor. Set the geocoder instance. |
||
41 | * |
||
42 | * @param null|Geocoder $geocoder |
||
43 | */ |
||
44 | public function __construct(Geocoder $geocoder = null) |
||
50 | |||
51 | /** |
||
52 | * Set a geocoder instance. |
||
53 | * |
||
54 | * @param Geocoder $geocoder |
||
55 | * |
||
56 | * @return self |
||
57 | */ |
||
58 | public function geocoder(Geocoder $geocoder) |
||
64 | |||
65 | /** |
||
66 | * Execute the middleware. |
||
67 | * |
||
68 | * @param ServerRequestInterface $request |
||
69 | * @param ResponseInterface $response |
||
70 | * @param callable $next |
||
71 | * |
||
72 | * @return ResponseInterface |
||
73 | */ |
||
74 | public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next) |
||
90 | |||
91 | /** |
||
92 | * Create a default geocoder instance. |
||
93 | * |
||
94 | * @return Geocoder |
||
95 | */ |
||
96 | private function getGeocoder() |
||
104 | } |
||
105 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: