2016-09-01 12:15:17 +02:00
|
|
|
<?php
|
|
|
|
namespace EmotionHero\Api;
|
|
|
|
|
|
|
|
use EmotionHero\Application as EH;
|
|
|
|
use Silex\Application;
|
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
|
|
|
use Silex\Api\ControllerProviderInterface;
|
|
|
|
use EmotionHero\Models;
|
|
|
|
|
|
|
|
class ScoreControllerProvider implements ControllerProviderInterface
|
|
|
|
{
|
|
|
|
/** @var EH */
|
|
|
|
protected $_eh;
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->_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) {
|
2016-09-03 18:14:04 +02:00
|
|
|
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);
|
2016-09-01 12:15:17 +02:00
|
|
|
return $app['serializer']->serialize($levels, 'json');
|
|
|
|
});
|
|
|
|
|
|
|
|
return $controllers;
|
|
|
|
}
|
|
|
|
}
|