Created
March 21, 2014 13:49
-
-
Save adnasa/9686702 to your computer and use it in GitHub Desktop.
Base index for silex.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once __DIR__.'/../vendor/autoload.php'; | |
use Symfony\Component\HttpFoundation\Request; | |
$app = new Silex\Application(); | |
$app->register(new Silex\Provider\TranslationServiceProvider(), array( | |
'translator.messages' => array(), | |
)); | |
$app->register(new Silex\Provider\TwigServiceProvider(), array( | |
'twig.path' => __DIR__.'/theme/templates', | |
)); | |
$app->register(new Silex\Provider\DoctrineServiceProvider(), array( | |
/*'db.options' => array ( | |
'driver' => 'pdo_mysql', | |
'host' => 'localhost', | |
'dbname' => '', | |
'user' => '', | |
'password' => '', | |
'charset' => 'utf8', | |
)*/ | |
)); | |
/** | |
* Mapper. | |
*/ | |
$app['app.mapper'] = $app->share(function() use ($app) { | |
return new \Application\Model\Mapper\DbMapper($app['db']); | |
}); | |
/** | |
* LogController | |
*/ | |
$app['app.log'] = $app->share(function() use($app) { | |
return new \Application\Controller\LogController($app['app.mapper']); | |
}); | |
/** | |
* ProjectController | |
*/ | |
$app['app.project'] = $app->share(function() use($app) { | |
return new \Application\Controller\ProjectController($app['app.mapper']); | |
}); | |
/** | |
* endpoints. | |
*/ | |
$app->get('/', function() use($app) { | |
$response = array( | |
'implements' => array( | |
'/api/v1/logs' => array('GET', 'POST'), | |
'/api/v1/logs[/:id]' => array( | |
'PUT', | |
'DELETE', | |
), | |
'/api/v1/projects' => array('GET', 'POST'), | |
'/api/v1/project[/:id]' => array( | |
'PUT', | |
'DELETE', | |
), | |
), | |
// 'session_key' => '', | |
); | |
return $app->json($response, 200); | |
}); | |
$app->get('/api/v1/logs', function() use($app) { | |
$getList = $app['app.log']->getList(); | |
return $app->json($getList, 200); | |
}); | |
$app->match('/api/v1/log/{id}', function (Request $request, $id) use ($app) { | |
$log = $app['app.log']->getLog($id); | |
if ($log === null) { | |
$response = array( | |
'content' => "Log with [id:{$id}], does not exist.", | |
); | |
return $app->json($response, 404); | |
} | |
return $app->json($log, 200); | |
}); | |
$app->get('/api/v1/projects', function() use($app) { | |
}); | |
$app->match('/api/v1/project/{id}', function(Request $request, $id) use($app) { | |
}); | |
$app->run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment