<?php
/*
    Copyright (C) 2015 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
    MA 02110-1301  USA.
*/

require(__DIR__ ."/inc/envsetup.php");

$settings = new SiWeather\Webservice\WebserviceConfig();

$app = new \Slim\Slim
(
	array
	(
		"mode" => $settings->getConfig("mode"),
	)
);
$app->setName("siweather");

// Only invoked if mode is "production"
$app->configureMode('production', function () use ($app) {
    $app->config(array(
        "log.enable" => true,
        "log.level" => \Slim\Log::WARN,
        "debug" => false,
    ));
});
// Only invoked if mode is "development"
$app->configureMode('development', function () use ($app) {
    $app->config(array(
        "log.enable" => true,
        "log.level" => \Slim\Log::DEBUG,
        "debug" => true
    ));
});

$app->notFound(function () use ($app) {
	$html = "";
    if($app->config("debug")){
        ob_start();
        phpinfo( INFO_VARIABLES ^ INFO_ENVIRONMENT );
        $html = ob_get_contents();
        ob_end_clean();
    }
    $app->render("404.php", array("dump" => $html));
});

$app->get("/setup", function () use ($app){
	$app->render("setup.php");
});
$app->get("/stations", function () use ($app){
	\SiWeather\Webservice\WebserviceApi::stations();
});
$app->post("/stations/register", function () use ($app){
	\SiWeather\Webservice\WebserviceApi::stationsRegister();
});

$app->run();

?>
