1 | <?php |
||
19 | class Geolocate |
||
20 | { |
||
21 | use Utils\ContainerTrait; |
||
22 | |||
23 | const KEY = 'GEOLOCATE'; |
||
24 | |||
25 | /** |
||
26 | * @var Geocoder |
||
27 | */ |
||
28 | protected $geocoder; |
||
29 | |||
30 | /** |
||
31 | * Returns the client location. |
||
32 | * |
||
33 | * @param ServerRequestInterface $request |
||
34 | * |
||
35 | * @return AddressCollection|null |
||
36 | */ |
||
37 | public static function getLocation(ServerRequestInterface $request) |
||
41 | |||
42 | /** |
||
43 | * Constructor. Set the geocoder instance. |
||
44 | * |
||
45 | * @param null|Geocoder $geocoder |
||
46 | */ |
||
47 | public function __construct(Geocoder $geocoder = null) |
||
53 | |||
54 | /** |
||
55 | * Set a geocoder instance. |
||
56 | * |
||
57 | * @param Geocoder $geocoder |
||
58 | * |
||
59 | * @return self |
||
60 | */ |
||
61 | public function geocoder(Geocoder $geocoder) |
||
67 | |||
68 | /** |
||
69 | * Execute the middleware. |
||
70 | * |
||
71 | * @param ServerRequestInterface $request |
||
72 | * @param ResponseInterface $response |
||
73 | * @param callable $next |
||
74 | * |
||
75 | * @return ResponseInterface |
||
76 | */ |
||
77 | public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next) |
||
93 | |||
94 | /** |
||
95 | * Create a default geocoder instance. |
||
96 | * |
||
97 | * @return Geocoder |
||
98 | */ |
||
99 | protected function getGeocoder() |
||
107 | } |
||
108 |
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: