public function upload()
 {
     $input = file_get_contents("php://input");
     $data = str_replace("data:image/jpeg;base64,", "", $input);
     $data = str_replace("data:image/png;base64,", "", $data);
     $da = new DataAccess();
     $da->setContentType('image/png;base64');
     $response = $da->post("item-images", $data);
     // if not created return early.
     if (!preg_match('/(201 Created)/', $response)) {
         $output = ['status' => 'failed'];
         $output = json_encode($output);
         $this->response->setContent($output);
         return;
     }
     // only if success!!!!
     $response = preg_split("/\n/", $response);
     $id = 0;
     foreach ($response as $value) {
         if (preg_match("/(Location:)/", $value)) {
             $parts = preg_split("/\\//", $value);
             $last = count($parts) - 1;
             $id = str_replace("\r", "", $parts[$last]);
         }
     }
     if (Session::is_set('images')) {
         $images = Session::get('images');
     } else {
         $images[] = ['id' => $id, 'data' => $input];
         Session::set('images', $images);
     }
     $output = ['status' => 'success', 'id' => $id];
     $output = json_encode($output);
     $this->response->setContent($output);
     // $response = $da->get("item-images/1");
     // var_dump($response);
     // $json = json_decode($response, true);
     // $d = $json['data'];
     // echo "<img src='data:image/png;base64," . $d ."'/>";
 }
$env = 'dev';
// https://github.com/PatrickLouys/no-framework-tutorial
$whoops = new \Whoops\Run();
if ($env === 'dev') {
    $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
} else {
    $whoops->pushHandler(function ($e) {
        echo 'error!';
    });
}
$whoops->register();
// https://github.com/PatrickLouys/no-framework-tutorial
$injector = (include 'Dependencies.php');
$request = $injector->make('Http\\HttpRequest');
$response = $injector->make('Http\\HttpResponse');
Session::set('id', 10);
// https://github.com/PatrickLouys/no-framework-tutorial
foreach ($response->getHeaders() as $header) {
    header($header, false);
}
// https://github.com/PatrickLouys/no-framework-tutorial
$routeDefinitionCallback = function (\FastRoute\RouteCollector $r) {
    $routes = (include 'Routes.php');
    foreach ($routes as $route) {
        $r->addRoute($route[0], $route[1], $route[2]);
    }
};
// https://github.com/PatrickLouys/no-framework-tutorial
$dispatcher = \FastRoute\simpleDispatcher($routeDefinitionCallback);
$routeInfo = $dispatcher->dispatch($request->getMethod(), $request->getPath());
// https://github.com/PatrickLouys/no-framework-tutorial