| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Moody\weather_and_position; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Anax\Commons\ContainerInjectableInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Anax\Commons\ContainerInjectableTrait; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | // use Anax\Route\Exception\ForbiddenException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | // use Anax\Route\Exception\NotFoundException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | // use Anax\Route\Exception\InternalErrorException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * A sample controller to show how a controller class can be implemented. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * The controller will be injected with $di if implementing the interface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * ContainerInjectableInterface, like this sample class does. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * The controller is mounted on a particular route and can then handle all | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * requests for that mount point. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  * @SuppressWarnings(PHPMD.TooManyPublicMethods) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | class weather_befor implements ContainerInjectableInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     use ContainerInjectableTrait; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     protected $ipAddress; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     protected $object; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 32 | 2 |  |     public function result($ipAddress, $object) : string | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 34 | 2 |  |         if ($object->getProtocol($ipAddress)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 35 | 1 |  |             return "The IP $ipAddress is a valid " . $object->getProtocol($ipAddress) ." address." ; | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 37 | 1 |  |         return "The IP $ipAddress is not a valid ip-Address."; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 | 1 |  |     public function indexAction() : object | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         // Deal with the action and return a response. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 | 1 |  |         $protocol =  null; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 | 1 |  |         $host = null; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         // $address = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         // $latitude = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         // $longitude = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 | 1 |  |         $title = "Ip validator"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 | 1 |  |         $page = $this->di->get("page"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 | 1 |  |         $request = $this->di->get("request"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 | 1 |  |         $this->ipAddress = $request->getGet("ip"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 | 1 |  |         $ip = $this->ipAddress; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 | 1 |  |         $this->object = $this->di->get("IpValidate"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 | 1 |  |         $this->openWeatherMapModel = $this->di->get("openWeatherMap"); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 | 1 |  |         foreach ($this->openWeatherMapModel as $key => $value) : | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 | 1 |  |             $this->object->setMessage($value); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         endforeach; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 | 1 |  |         $protocol = $this->result($this->ipAddress, $this->object); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 | 1 |  |         $host = $this->object->getDomain($this->ipAddress); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 | 1 |  |         $address = $this->object->getAddress($this->ipAddress); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 | 1 |  |         $latitude =  $address["latitude"] ??null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 | 1 |  |         $longitude = $address["longitude"] ??null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         // var_dump($latitude); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         // var_dump($longitude); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         // $weatherSet = $this->object->setWeather($latitude, $longitude); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 | 1 |  |         $weatherSet2 = $this->object->setWeather2($latitude, $longitude); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |         // $weatherGet = $this->object->getWeather(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 | 1 |  |         $weatherGet2 = $this->object->getWeather2(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         // $getData = $this->object->getData($weatherGet); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 | 1 |  |         $getDataArray = $this->object->getDataArray($weatherGet2); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 | 1 |  |         $ip = $this->object->getCurrentIp($this->ipAddress); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 | 1 |  |         $Domain = $this->object->getDomain($this->ipAddress); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 | 1 |  |         $json = $this->ipJson($this->ipAddress, $this->object); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 | 1 |  |         $data['json'] = $json; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 | 1 |  |         $data["ip"] = $ip; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 | 1 |  |         $data["protocol"] = $protocol; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 | 1 |  |         $data["host"] = $host; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 | 1 |  |         $data["address"] = $address; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 | 1 |  |         $data["Domain"] = $Domain; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 | 1 |  |         $data["latitude"] = $latitude; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 | 1 |  |         $data["longitude"] = $longitude; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |         // $data["weatherSet"] = $weatherSet; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 | 1 |  |         $data["weatherSet2"] = $weatherSet2; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |         // $data["getData"] = $getData; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 | 1 |  |         $data["getDataArray"] = $getDataArray; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |         // var_dump($getDataArray); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 | 1 |  |         $page->add("weather/befor", $data); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 | 1 |  |         return $page->render([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 | 1 |  |             "title" => $title, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 | 1 |  |     public function ipJson($ipAddress, $object) : array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |         $json = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 | 1 |  |             "ip" => $ipAddress, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 | 1 |  |             "Protocol" => $object->getProtocol($ipAddress) ?? null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 | 1 |  |             "Domain" => $object->getDomain($ipAddress) ?? null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 | 1 |  |             "address" => $object->getDataArray($this->object->getWeather2()) ?? null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 | 1 |  |         return [$json]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 130 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 131 |  |  |  |