From 6dc90c704c36466c646af5121fe4bfa7857319c0 Mon Sep 17 00:00:00 2001 From: Vincent Jousse Date: Fri, 22 Nov 2013 16:25:37 +0100 Subject: [PATCH] Add EntryApi as a Service --- app/app.php | 5 +++++ app/controllers/api.php | 6 ++++++ src/Poche/Api/EntryApi.php | 17 +++++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 src/Poche/Api/EntryApi.php diff --git a/app/app.php b/app/app.php index ce540e2..b4a940c 100644 --- a/app/app.php +++ b/app/app.php @@ -1,5 +1,6 @@ register(new Silex\Provider\DoctrineServiceProvider(), array( 'path' => __DIR__.'/../poche.db', ), )); + +$app['entry_api'] = $app->share(function ($app) { + return new EntryApi($app['db']); +}); diff --git a/app/controllers/api.php b/app/controllers/api.php index c573ad4..cab3000 100644 --- a/app/controllers/api.php +++ b/app/controllers/api.php @@ -1,6 +1,12 @@ get('/', function () { return 'API home page'; }); +$api->get('/entries', function () use ($app) { + $entries = $app['entry_api']->getEntries(); + return json_encode($entries); +}); + return $api; diff --git a/src/Poche/Api/EntryApi.php b/src/Poche/Api/EntryApi.php new file mode 100644 index 0000000..878cae1 --- /dev/null +++ b/src/Poche/Api/EntryApi.php @@ -0,0 +1,17 @@ +db = $db; + } + + public function getEntries() { + //Todo + return array(); + } +}