if (!is_null($var)) { $retval[] = $var; } } return $retval; } } class BackupApplication extends Silex\Application { use Silex\Application\TranslationTrait; use Silex\Application\TwigTrait; use Silex\Application\MonologTrait; } $app = new BackupApplication(); $app['debug'] = true; $app->register(new Silex\Provider\MonologServiceProvider(), array('monolog.logfile' => __DIR__ . '/logs/app.log')); $app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/templates')); $bpc = new BackupPcInterface($app, $config['host'], $config['port'], $config['secret']); $app->get('/', function () use($app) { return $app['twig']->render('index.html.twig'); }); $app->get('/host/', function () use($app, $bpc, $config) { $app->log('Fetching hosts'); return json_encode($bpc->getHosts()); }); $app->get('/host/{hostname}', function ($hostname) use($app, $bpc) { $app->log('Fetching information for Host ' . $hostname); return json_encode($bpc->getHost($hostname)); }); $app->run();