_eh = EH::getInstance(); } public function connect(Application $app) { // creates a new controller based on the default route $controllers = $app['controllers_factory']; $controllers->get('/', function (Application $app) { return "OK"; }); $controllers->get('/levels', function (Application $app) { $levels = $this->_eh->getEm()->getRepository(Models\Level::class)->findAll(); return $app['serializer']->serialize($levels, 'json'); }); $controllers->get('/emotions', function (Application $app) { $levels = $this->_eh->getEm()->getRepository(Models\Emotion::class)->findAll(); return $app['serializer']->serialize($levels, 'json'); }); $controllers->get('/me', function (Application $app) { $token = $app['security.token_storage']->getToken(); $user = $token->getUser(); return $app['serializer']->serialize($user, 'json'); }); $controllers->post('/me/games', function (Request $request, Application $app) { var_dump($request->getContent()); $a = date("Y-m-d H:i:s")."\n"; $a .= print_r($request->attributes->all(), true); $a .= print_r($request->query->all(), true); $a .= print_r($request->request->all(), true); $a .= "\n\n"; $a .= $request->getContent(); file_put_contents(__DIR__.'/../../cache/me_games', $a); // $vars = json_decode($request->getContent(), true); // var_dump($vars); return $app['serializer']->serialize($levels, 'json'); }); return $controllers; } }