liiinder /
ramverk1-module
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Linder\Controller; |
||
| 4 | |||
| 5 | use Anax\Commons\ContainerInjectableInterface; |
||
| 6 | use Anax\Commons\ContainerInjectableTrait; |
||
| 7 | |||
| 8 | /** |
||
| 9 | * A controller that handles a get request |
||
| 10 | * uses a model and returns a Json. |
||
| 11 | */ |
||
| 12 | class APIMockController implements ContainerInjectableInterface |
||
| 13 | { |
||
| 14 | use ContainerInjectableTrait; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * Main index page, serves as the ip mock |
||
| 18 | * @return Array |
||
| 19 | */ |
||
| 20 | 1 | public function indexAction() : array |
|
| 21 | { |
||
| 22 | 1 | $ip = $this->di->request->getGet("ip") ?: $this->di->request->getServer("REMOTE_ADDR"); |
|
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 23 | 1 | $ipMock = new \Linder\Mock\IpVerifierMock(); |
|
| 24 | return [ |
||
| 25 | 1 | $ipMock->getJson($ip) |
|
| 26 | ]; |
||
| 27 | } |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Darksky mock route which mocks the return |
||
| 31 | * type from the external darksky api |
||
| 32 | * @return Array |
||
| 33 | */ |
||
| 34 | 1 | public function darkSkyMockAction() : Array |
|
| 35 | { |
||
| 36 | 1 | $darksky = new \Linder\Mock\DarkSkyMock(); |
|
| 37 | 1 | $url = $this->di->request->getCurrentUrl(); |
|
|
0 ignored issues
–
show
|
|||
| 38 | 1 | $res = (strpos($url, "?exclude=currently,flags") || $this->di->request->getGet("type") == "past") ? |
|
| 39 | 1 | $darksky->getWeatherPast() : |
|
| 40 | 1 | $darksky->getWeatherComing(); |
|
| 41 | 1 | return $res; |
|
| 42 | } |
||
| 43 | } |
||
| 44 |