mirror of
https://github.com/moparisthebest/wallabag
synced 2024-12-18 05:32:23 -05:00
Move DB queries into a Repository class
This commit is contained in:
parent
67571d47cc
commit
674cf03409
11
app/app.php
11
app/app.php
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
use Knp\Provider\ConsoleServiceProvider;
|
||||
use Poche\Api\EntryApi;
|
||||
use Poche\Repository\EntryRepository;
|
||||
|
||||
use Silex\Provider\FormServiceProvider;
|
||||
|
||||
@ -13,7 +14,7 @@ $app->register(new Silex\Provider\TwigServiceProvider(), array(
|
||||
$app->before(function () use ($app) {
|
||||
$app['twig']->addGlobal('layout', $app['twig']->loadTemplate('layout.twig'));
|
||||
});
|
||||
|
||||
|
||||
$app->register(new ConsoleServiceProvider(), [
|
||||
'console.name' => 'Poche console',
|
||||
'console.version' => '0.1',
|
||||
@ -33,6 +34,10 @@ $app->register(new Silex\Provider\TranslationServiceProvider(), array(
|
||||
'translator.messages' => array(),
|
||||
));
|
||||
|
||||
$app['entry_api'] = $app->share(function ($app) {
|
||||
return new EntryApi($app['db']);
|
||||
$app['entry_repository'] = $app->share(function ($app) {
|
||||
return new EntryRepository($app['db']);
|
||||
});
|
||||
|
||||
$app['entry_api'] = $app->share(function ($app) {
|
||||
return new EntryApi($app['entry_repository']);
|
||||
});
|
||||
|
@ -4,15 +4,24 @@ namespace Poche\Api;
|
||||
|
||||
class EntryApi
|
||||
{
|
||||
private $db;
|
||||
private $entryRepository;
|
||||
|
||||
public function __construct($db) {
|
||||
$this->db = $db;
|
||||
public function __construct($entryRepository) {
|
||||
$this->entryRepository = $entryRepository;
|
||||
}
|
||||
|
||||
public function getEntries() {
|
||||
$sql = "SELECT * FROM entries";
|
||||
$entries = $this->db->fetchAssoc($sql);
|
||||
return ($entries ? $entries : array());
|
||||
return $this->entryRepository->getEntries();
|
||||
}
|
||||
|
||||
public function createEntryFromUrl($url) {
|
||||
|
||||
//TODO: Fetch all what we need, fill the title, content …
|
||||
|
||||
$entry = array(
|
||||
'url' => $url
|
||||
);
|
||||
return $entry;
|
||||
}
|
||||
|
||||
}
|
||||
|
21
src/Poche/Repository/EntryRepository.php
Normal file
21
src/Poche/Repository/EntryRepository.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Poche\Repository;
|
||||
|
||||
class EntryRepository
|
||||
{
|
||||
private $db;
|
||||
|
||||
public function __construct($db) {
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
public function getEntries() {
|
||||
$sql = "SELECT * FROM entries";
|
||||
$entries = $this->db->fetchAssoc($sql);
|
||||
return ($entries ? $entries : array());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user