Skip to content

Commit

Permalink
Merge pull request #18 from phpminds/develop
Browse files Browse the repository at this point in the history
Merge http caching into master
  • Loading branch information
pavlakis committed Dec 15, 2015
2 parents e20151b + 999699c commit cd77b68
Show file tree
Hide file tree
Showing 7 changed files with 203 additions and 71 deletions.
7 changes: 6 additions & 1 deletion app/dependencies.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@
return new \GuzzleHttp\Client();
};

$container['cache'] = function () {
return new \Slim\HttpCache\CacheProvider();
};

$container ['db'] = function ($c) {
$db = $c->get('settings')['db'];

Expand Down Expand Up @@ -132,6 +136,7 @@

$container['auth.middleware'] = function ($c) {
return new App\Middleware\AuthCheck($_SESSION, 'auth', $c->get('settings')['auth-routes']);

};

$container['csrf'] = function ($c) {
Expand Down Expand Up @@ -189,7 +194,7 @@

$container['App\Action\HomeAction'] = function ($c) {
return new App\Action\HomeAction(
$c->get('view'), $c->get('logger'), $c->get('service.event'), $c->get('service.content')
$c->get('view'), $c->get('logger'), $c->get('service.event'), $c->get('service.content'), $c->get('cache')
);
};

Expand Down
6 changes: 6 additions & 0 deletions app/middleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@
// Application middleware


$app->add(new \Slim\HttpCache\Cache('public', 86400));


$app->add($container->get('auth.middleware'));

$app->add($container->get('csrf'));

$app->add($container->get('auth.middleware'));

$app->add(new App\Middleware\CliRequest());

3 changes: 2 additions & 1 deletion app/routes.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
// Routes

$app->get('/', 'App\Action\HomeAction:dispatch')
$app->get('/', 'App\Action\HomeAction:dispatch')
->setName('homepage');

$app->get('/login', 'App\Action\LoginAction:dispatch')
Expand Down Expand Up @@ -38,3 +38,4 @@

$app->get('/status', 'App\Action\EventStatusAction:dispatch')
->setName('status');

25 changes: 20 additions & 5 deletions app/src/Action/HomeAction.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?php
namespace App\Action;

use App\Service\ContentService;
use App\Service\EventsService;
use Slim\HttpCache\CacheProvider;
use Slim\Views\Twig;
use Psr\Log\LoggerInterface;

Expand All @@ -21,13 +23,24 @@ final class HomeAction
* @var EventsService
*/
private $eventService;
private $contentService;

public function __construct(Twig $view, LoggerInterface $logger, $eventService, $contentService)
/**
* @var ContentService
*/
private $contentService;

/**
* @var CacheProvider
*/
private $cache;


public function __construct(Twig $view, LoggerInterface $logger, EventsService $eventService, ContentService $contentService, CacheProvider $cache)
{
$this->view = $view;
$this->logger = $logger;
$this->view = $view;
$this->logger = $logger;
$this->eventService = $eventService;
$this->cache = $cache;
$this->contentService = $contentService;
}

Expand All @@ -39,7 +52,9 @@ public function dispatch($request, $response, $args)
$this->view->getEnvironment()->addFilter($filter);


$resWithETag = $this->cache->withETag($response, $event['id']);

$this->view->render($response, 'home.twig', ['event' => $event]);
return $response;
return $resWithETag;
}
}
2 changes: 1 addition & 1 deletion app/src/Model/MeetupEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function formatResponse(array $event = [])
}

return [
'id' => $eventID,
'id' => $eventID,
'group' => $groupName,
'subject' => $subject,
'date_time' => $eventDate . ' at ' . $eventTime,
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@
}
},
"require": {
"slim/slim": "^3.0@beta",
"slim/slim": "^3.0",
"slim/twig-view": "^1.1",
"slim/flash": "^0.1.0",
"monolog/monolog": "^1.13",
"guzzlehttp/guzzle": "^6.1",
"slim/http-cache": "^0.3.0",
"aura/sql": "^2.4",
"slim/csrf": "^0.4.0",
"erusev/parsedown": "^1.6",
Expand Down
Loading

0 comments on commit cd77b68

Please sign in to comment.