| 1 | <?php
|
|---|
| 2 | /*
|
|---|
| 3 | Copyright (C) 2015 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
|
|---|
| 4 |
|
|---|
| 5 | This library is free software; you can redistribute it and/or
|
|---|
| 6 | modify it under the terms of the GNU Lesser General Public
|
|---|
| 7 | License as published by the Free Software Foundation; either
|
|---|
| 8 | version 2.1 of the License, or (at your option) any later version.
|
|---|
| 9 |
|
|---|
| 10 | This library is distributed in the hope that it will be useful,
|
|---|
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|---|
| 13 | Lesser General Public License for more details.
|
|---|
| 14 |
|
|---|
| 15 | You should have received a copy of the GNU Lesser General Public
|
|---|
| 16 | License along with this library; if not, write to the Free Software
|
|---|
| 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|---|
| 18 | MA 02110-1301 USA.
|
|---|
| 19 | */
|
|---|
| 20 |
|
|---|
| 21 | require(__DIR__ ."/inc/envsetup.php");
|
|---|
| 22 |
|
|---|
| 23 | $settings = new SiWeather\Webservice\WebserviceConfig();
|
|---|
| 24 |
|
|---|
| 25 | /**
|
|---|
| 26 | * @brief Handles the stations (list) REST requests
|
|---|
| 27 | */
|
|---|
| 28 | function stations(){
|
|---|
| 29 | $stations = Array();
|
|---|
| 30 | // $station = Array();
|
|---|
| 31 | // $station["id"] = "123456";
|
|---|
| 32 | // $station["name"] = "Station Name";
|
|---|
| 33 | // $station["longitude"] = 52.320;
|
|---|
| 34 | // $station["latitude"] = 48;
|
|---|
| 35 | // $station["city"] = "Krefeld";
|
|---|
| 36 | // $station["values"] = Array();
|
|---|
| 37 | // $station["values"][] = "temperature";
|
|---|
| 38 | // $station["values"][] = "humidity";
|
|---|
| 39 | // $station["url"] = "stations/". $station["id"];
|
|---|
| 40 | // $stations[] = $station;
|
|---|
| 41 | echo json_encode($stations);
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 | $app = new \Slim\Slim
|
|---|
| 45 | (
|
|---|
| 46 | array
|
|---|
| 47 | (
|
|---|
| 48 | "mode" => $settings->getConfig("mode"),
|
|---|
| 49 | )
|
|---|
| 50 | );
|
|---|
| 51 | $app->setName("SiWeather Webservice");
|
|---|
| 52 |
|
|---|
| 53 | // Only invoked if mode is "production"
|
|---|
| 54 | $app->configureMode('production', function () use ($app) {
|
|---|
| 55 | $app->config(array(
|
|---|
| 56 | "log.enable" => true,
|
|---|
| 57 | "log.level" => \Slim\Log::WARN,
|
|---|
| 58 | "debug" => false,
|
|---|
| 59 | ));
|
|---|
| 60 | });
|
|---|
| 61 | // Only invoked if mode is "development"
|
|---|
| 62 | $app->configureMode('development', function () use ($app) {
|
|---|
| 63 | $app->config(array(
|
|---|
| 64 | "log.enable" => true,
|
|---|
| 65 | "log.level" => \Slim\Log::DEBUG,
|
|---|
| 66 | "debug" => true
|
|---|
| 67 | ));
|
|---|
| 68 | });
|
|---|
| 69 |
|
|---|
| 70 | $app->notFound(function () use ($app) {
|
|---|
| 71 | $html = "";
|
|---|
| 72 | if($app->config("debug")){
|
|---|
| 73 | ob_start();
|
|---|
| 74 | phpinfo( INFO_VARIABLES ^ INFO_ENVIRONMENT );
|
|---|
| 75 | $html = ob_get_contents();
|
|---|
| 76 | ob_end_clean();
|
|---|
| 77 | }
|
|---|
| 78 | $app->render("404.php", array("dump" => $html));
|
|---|
| 79 | });
|
|---|
| 80 |
|
|---|
| 81 | $app->get("/setup", function () use ($app){
|
|---|
| 82 | $app->render("setup.php");
|
|---|
| 83 | });
|
|---|
| 84 |
|
|---|
| 85 | $app->get("/stations", "stations");
|
|---|
| 86 | $app->get("/stations/:uuid", function ($uuid){
|
|---|
| 87 | echo "stations 123";
|
|---|
| 88 | });
|
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 | $app->run();
|
|---|
| 93 |
|
|---|
| 94 | ?>
|
|---|