Add EntryApi as a Service

This commit is contained in:
Vincent Jousse 2013-11-22 16:25:37 +01:00
parent 3734cb0090
commit 6dc90c704c
3 changed files with 28 additions and 0 deletions

View File

@ -1,5 +1,6 @@
<?php
use Knp\Provider\ConsoleServiceProvider;
use Poche\Api\EntryApi;
$app = new Silex\Application();
@ -19,3 +20,7 @@ $app->register(new Silex\Provider\DoctrineServiceProvider(), array(
'path' => __DIR__.'/../poche.db',
),
));
$app['entry_api'] = $app->share(function ($app) {
return new EntryApi($app['db']);
});

View File

@ -1,6 +1,12 @@
<?php
$api = $app['controllers_factory'];
$api->get('/', function () { return 'API home page'; });
$api->get('/entries', function () use ($app) {
$entries = $app['entry_api']->getEntries();
return json_encode($entries);
});
return $api;

View File

@ -0,0 +1,17 @@
<?php
namespace Poche\Api;
class EntryApi
{
private $db;
public function __construct($db) {
$this->db = $db;
}
public function getEntries() {
//Todo
return array();
}
}