Guest User

Untitled

a guest
Dec 13th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. <?php
  2. namespace AppWeatherAdapters;
  3.  
  4. use AppWeatherClientsClientOpenWeather;
  5. use AppWeatherTranslatorsTranslatorOpenWeather;
  6.  
  7. class ClientOpenWeatherAdapter implements WeatherClientAdapterInterface
  8. {
  9.  
  10. private $client;
  11.  
  12. public function __construct(ClientOpenWeather $client)
  13. {
  14. $this->client = $client;
  15. }
  16.  
  17. public function getWeather(float $lat,float $lon)
  18. {
  19. //Получение данных о погоде от API
  20. $dataWeather = $this->client->getWeather($lat, $lon);
  21. if ($dataWeather === null) {
  22. return null;
  23. }
  24.  
  25. //Трансляция данных из массива в WeatherDTO
  26. return TranslatorOpenWeather::translate($dataWeather);
  27. }
  28. }
  29.  
  30. ...
  31. public function addWeather(
  32. Request $request,
  33. ClientOpenWeatherAdapter $clientOpenWeatherAdapter,
  34. ClientYandexWeatherAdapter $clientYandexAdapter
  35. ) {
  36. ...
  37. $clientOpenWeatherAdapter->getWeather($lat, $lon);
  38. $clientYandexAdapter->getWeather($lat, $lon);
  39. ...
  40. }
Add Comment
Please, Sign In to add comment