Skip to content

Commit

Permalink
Conduit 0.11.0 usage of $next()
Browse files Browse the repository at this point in the history
- Always pass the request and response.
  • Loading branch information
weierophinney committed Jan 26, 2015
1 parent 1c5b6d8 commit 986b059
Show file tree
Hide file tree
Showing 18 changed files with 55 additions and 53 deletions.
4 changes: 2 additions & 2 deletions composer.json
Expand Up @@ -11,8 +11,8 @@
"opauth/github": ">=0.1.0@dev,<2.0.0",
"opauth/google": ">=0.2.2@dev,<2.0.0",
"opauth/twitter": ">=0.3.1@dev,<2.0.0",
"phly/conduit": "~0.10.0",
"phly/http": "~0.8",
"phly/conduit": "~0.11.0",
"phly/http": "~0.8.4",
"phly/phly-comic": "~1.0",
"phly/mustache": "~1.1",
"psr/http-message": "~0.6",
Expand Down
24 changes: 12 additions & 12 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Auth/Auth.php
Expand Up @@ -23,7 +23,7 @@ public function __construct(array $authConfig, Session $session)
public function __invoke($req, $res, $next)
{
if ($req->getMethod() !== 'GET') {
return $next('GET', $res->withStatus(405));
return $next($req, $res->withStatus(405), 'GET');
}

if (isset($req->getQueryParams()['redirect'])) {
Expand Down
8 changes: 4 additions & 4 deletions src/Auth/AuthCallback.php
Expand Up @@ -34,12 +34,12 @@ public function __invoke($req, $res, $next)
$authResponse = unserialize(base64_decode($req->getQueryParams()['opauth']));
break;
default:
return $next('Invalid request', $res->withStatus(400));
return $next($req, $res->withStatus(400), 'Invalid request');
break;
}

if (array_key_exists('error', $authResponse)) {
return $next('Error authenticating', $res->withStatus(403));
return $next($req, $res->withStatus(403), 'Error authenticating');
}

if (empty($authResponse['auth'])
Expand All @@ -48,7 +48,7 @@ public function __invoke($req, $res, $next)
|| empty($authResponse['auth']['provider'])
|| empty($authResponse['auth']['uid'])
) {
return $next('Invalid authentication response', $res->withStatus(403));
return $next($req, $res->withStatus(403), 'Invalid authentication response');
}

if ($auth->env['callback_transport'] !== 'session'
Expand All @@ -59,7 +59,7 @@ public function __invoke($req, $res, $next)
$reason
)
) {
return $next('Invalid authentication response', $res->withStatus(403));
return $next($req, $res->withStatus(403), 'Invalid authentication response');
}

$auth = $this->session->getSegment('auth');
Expand Down
2 changes: 1 addition & 1 deletion src/Auth/UserSession.php
Expand Up @@ -15,6 +15,6 @@ public function __construct(Session $session)
public function __invoke($request, $response, $next)
{
$auth = $this->session->getSegment('auth');
return $next($request->withAttribute('user', $auth->get('user')));
return $next($request->withAttribute('user', $auth->get('user')), $response);
}
}
8 changes: 4 additions & 4 deletions src/Blog/CachingMiddleware.php
Expand Up @@ -18,7 +18,7 @@ public function __construct($cachePath, $enabled = true)
public function __invoke($req, $res, $next)
{
if (! $this->enabled) {
return $next();
return $next($req, $res);
}

if (! $req->getAttribute('blog', false)) {
Expand All @@ -39,23 +39,23 @@ public function __invoke($req, $res, $next)
return $this->cache($req, $res, $next);
}

return $next($req);
return $next($req, $res);
}

private function fetchFromCache($req, $res, $next)
{
$path = $req->getUri()->getPath();
if (! preg_match('#^/(?P<page>[^/]+\.html)$#', $path, $matches)) {
// Nothing to do; not a blog post
return $next();
return $next($req, $res);
}

$cachePath = sprintf('%s/%s', $this->cachePath, $matches['page']);

if (! file_exists($cachePath)) {
// Nothing in cache, but should be cached
$req->getAttribute('blog')->cacheable = $matches['page'];
return $next();
return $next($req, $res);
}

// Cache hit!
Expand Down
10 changes: 5 additions & 5 deletions src/Blog/EngineMiddleware.php
Expand Up @@ -105,20 +105,20 @@ private function listPosts($req, $res, $next, $tag = null)
return $next($req->withAttribute('view', (object) [
'template' => 'blog.list',
'model' => $view,
]));
]), $res);
}

private function displayPost($id, $req, $res, $next)
{
$post = $this->mapper->fetch($id);

if (! $post) {
return $next('Not found', $res->withStatus(404));
return $next($req, $res->withStatus(404), 'Not found');
}

$post = include $post['path'];
if (! $post instanceof EntryEntity) {
return $next('Not found', $res->withStatus(404));
return $next($req, $res->withStatus(404), 'Not found');
}

$original = $req->getOriginalRequest()->getUri()->getPath();
Expand All @@ -128,7 +128,7 @@ private function displayPost($id, $req, $res, $next)
return $next($req->withAttribute('view', (object) [
'template' => 'blog.post',
'model' => $post,
]));
]), $res);
}

private function displayFeed($req, $res, $next, $type, $tag = null)
Expand All @@ -140,7 +140,7 @@ private function displayFeed($req, $res, $next, $type, $tag = null)
}

if (! file_exists($path)) {
return $next('Not found', $res->withStatus(404));
return $next($req, $res->withStatus(404), 'Not found');
}

return $res
Expand Down
12 changes: 7 additions & 5 deletions src/BodyParams.php
Expand Up @@ -12,7 +12,7 @@ class BodyParams
public function __invoke($request, $response, $next)
{
if (in_array($request->getMethod(), $this->nonBodyRequests)) {
return $next();
return $next($request, $response);
}

$header = $request->getHeader('Content-Type');
Expand All @@ -35,17 +35,19 @@ public function __invoke($request, $response, $next)
case 'form':
// $_POST is injected by default into the request body parameters;
// re-inject them into the attributes.
return $next($request->withAttribute('body', $request->getBodyParams()));
return $next($request->withAttribute('body', $request->getBodyParams()), $response);
case 'json':
$rawBody = $request->getBody()->getContents();
return $next($request
return $next(
$request
->withAttribute('rawBody', $rawBody)
->withAttribute('body', json_decode($rawBody, true))
->withAttribute('body', json_decode($rawBody, true)),
$response
);
default:
break;
}

return $next();
return $next($request, $response);
}
}
2 changes: 1 addition & 1 deletion src/ComicsPage.php
Expand Up @@ -8,7 +8,7 @@ public function __invoke($request, $response, $next)
error_log('In ' . get_class($this));
if (! $request->getAttribute('user', false)) {
error_log('Returning 401 error');
return $next(401, $response->withStatus(401));
return $next($request, $response->withStatus(401), 401);
}

error_log('Rendering page');
Expand Down
6 changes: 3 additions & 3 deletions src/Contact/LandingPage.php
Expand Up @@ -22,11 +22,11 @@ public function __invoke($request, $response, $next)
{
$path = $request->getUri()->getPath();
if ($path !== $this->path) {
return $next();
return $next($request, $response);
}

if ($request->getMethod() !== 'GET') {
return $next('GET', $response->withStatus(405));
return $next($request, $response->withStatus(405), 'GET');
}

$basePath = $request->getOriginalRequest()->getUri()->getPath();
Expand All @@ -38,6 +38,6 @@ public function __invoke($request, $response, $next)
return $next($request->withAttribute('view', (object) [
'template' => $this->page,
'model' => $view,
]));
]), $response);
}
}
6 changes: 3 additions & 3 deletions src/Contact/Process.php
Expand Up @@ -27,7 +27,7 @@ public function __construct(
public function __invoke($request, $response, $next)
{
if ($request->getMethod() !== 'POST') {
return $next('POST', $response->withStatus(405));
return $next($request, $response->withStatus(405), 'POST');
}

$this->session->start();
Expand All @@ -44,7 +44,7 @@ public function __invoke($request, $response, $next)
$token,
$request,
$response
));
), $response);
}

$filter = new InputFilter();
Expand All @@ -57,7 +57,7 @@ public function __invoke($request, $response, $next)
$token,
$request,
$response
));
), $response);
}

$this->sendEmail($filter->getValues());
Expand Down
6 changes: 3 additions & 3 deletions src/Contact/ThankYouPage.php
Expand Up @@ -16,11 +16,11 @@ public function __invoke($request, $response, $next)
{
$path = $request->getUri()->getPath();
if ($path !== $this->path) {
return $next();
return $next($request, $response);
}

if ($request->getMethod() !== 'GET') {
return $next('GET', $response->withStatus(405));
return $next($request, $response->withStatus(405), 'GET');
}

$parentUrl = str_replace('/thank-you', '', $request->originalUrl);
Expand All @@ -36,6 +36,6 @@ public function __invoke($request, $response, $next)
return $next($request->withAttribute('view', (object) [
'template' => $this->page,
'model' => [],
]));
]), $response);
}
}
2 changes: 1 addition & 1 deletion src/NotAllowed.php
Expand Up @@ -6,7 +6,7 @@ class NotAllowed
public function __invoke($err, $req, $res, $next)
{
if ($res->getStatusCode() !== 405) {
return $next($err);
return $next($req, $res, $err);
}

if (is_array($err) || is_string($err)) {
Expand Down
2 changes: 1 addition & 1 deletion src/NotFound.php
Expand Up @@ -5,6 +5,6 @@ class NotFound
{
public function __invoke($req, $res, $next)
{
return $next('Not Found', $res->withStatus(404));
return $next($req, $res->withStatus(404), 'Not Found');
}
}
6 changes: 3 additions & 3 deletions src/Page.php
Expand Up @@ -18,15 +18,15 @@ public function __construct($path, $page)
public function __invoke($request, $response, $next)
{
if ($request->getOriginalRequest()->getUri()->getPath() !== $this->path) {
return $next();
return $next($request, $response);
}

if ($request->getMethod() !== 'GET') {
return $next('GET', $response->withStatus(405));
return $next($request, $response->withStatus(405), 'GET');
}

$view = $request->getAttribute('view', new stdClass);
$view->template = $this->page;
$next($request->withAttribute('view', $view));
$next($request->withAttribute('view', $view), $response);
}
}
4 changes: 2 additions & 2 deletions src/Redirects.php
Expand Up @@ -10,7 +10,7 @@ public function __invoke($req, $res, $next)

// Ensure php.net is able to retrieve PHP RSS feed without a problem
if ('/blog/tag/php.xml' === $path) {
return $next();
return $next($req, $res);
}

// PhlyBlog style pagination
Expand Down Expand Up @@ -83,7 +83,7 @@ public function __invoke($req, $res, $next)
return $this->redirect('/blog', $url, $res);
}

return $next();
return $next($req, $res);
}

private function redirect($path, $url, $res, $query = [])
Expand Down
2 changes: 1 addition & 1 deletion src/Templated.php
Expand Up @@ -42,7 +42,7 @@ public function render(Request $request, Response $response, callable $next)
$view = $request->getAttribute('view', false);

if (false === $view || ! $view->template) {
return $next();
return $next($request, $response);
}

return $response->write($this->renderer->render(
Expand Down
2 changes: 1 addition & 1 deletion src/Unauthorized.php
Expand Up @@ -19,7 +19,7 @@ public function __invoke($err, $req, $res, $next)
error_log('In ' . get_class($this));
if ($res->getStatusCode() !== 401) {
error_log('Invalid status code; passing to next handler');
return $next($err);
return $next($req, $res, $err);
}

$new = $req->getUri()->withPath('/auth');
Expand Down

0 comments on commit 986b059

Please sign in to comment.