Exemplo n.º 1
0
 /**
  * Save the data using Service.
  * As we are using only a file storage, we don't need to check the data for SQL injection
  * Data gets saved as it is, and then gets escaped on the Twig file
  *
  * @param array $data
  * @return string
  */
 public function saveData(array $data)
 {
     if ($this->storageService->saveData($data)) {
         return '<p class="info">data saved</p>';
     }
     return 'Error saving the data';
 }
Exemplo n.º 2
0
 */
$router = new Klein();
/*
 * Create new pimple container for dependency injection
 */
$app = new Container();
/*
 * Environment variables
 */
$app['config.storage'] = $config['DBFile'];
$app['twig'] = $twig;
/*
 * Build services and provide them from the Container
 */
$app['service.storage'] = function () use($app) {
    $service = new StorageService();
    $service->setStorageName($app['config.storage']);
    return $service;
};
$app['controller.data'] = function () use($app) {
    $controller = new DataController();
    $controller->setApp($app);
    $controller->setStorageService($app['service.storage']);
    return $controller;
};
/*
 * Build routes
 */
$router->respond('POST', '/update', function () use($app) {
    return $app['controller.data']->saveData($_POST['people']);
});