Skip to content

Commit

Permalink
Add Slack Jira Pipeline
Browse files Browse the repository at this point in the history
Add /slack_jira POST route
Validate Body
  • Loading branch information
stringerbell committed May 29, 2016
1 parent 6b21dd5 commit cd6bda5
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 3 deletions.
10 changes: 7 additions & 3 deletions config/autoload/dependencies.global.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
use App\Pipeline\SlackJiraPipeline;
use App\Validator\ValidateBody;
use Zend\Expressive\Application;
use Zend\Expressive\Container\ApplicationFactory;
use Zend\Expressive\Helper;
Expand All @@ -14,11 +16,13 @@
'invokables' => [
// Fully\Qualified\InterfaceName::class => Fully\Qualified\ClassName::class,
Helper\ServerUrlHelper::class => Helper\ServerUrlHelper::class,
ValidateBody::class => ValidateBody::class,
],
// Use 'factories' for services provided by callbacks/factory classes.
'factories' => [
Application::class => ApplicationFactory::class,
Helper\UrlHelper::class => Helper\UrlHelperFactory::class,
'factories' => [
Application::class => ApplicationFactory::class,
Helper\UrlHelper::class => Helper\UrlHelperFactory::class,
SlackJiraPipeline::class => SlackJiraPipeline::class,
],
],
];
1 change: 1 addition & 0 deletions config/autoload/middleware-pipeline.global.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
'middleware' => [
ApplicationFactory::ROUTING_MIDDLEWARE,
Helper\UrlHelperMiddleware::class,
Helper\BodyParams\BodyParamsMiddleware::class,
// Add more middleware here that needs to introspect the routing
// results; this might include:
// - route-based authentication
Expand Down
8 changes: 8 additions & 0 deletions config/autoload/routes.global.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use App\Pipeline\SlackJiraPipeline;

return [
'dependencies' => [
'invokables' => [
Expand All @@ -24,5 +26,11 @@
'middleware' => App\Action\PingAction::class,
'allowed_methods' => ['GET'],
],
[
'name' => '/slack_jira',
'path' => '/slack_jira',
'middleware' => [SlackJiraPipeline::class],
'allowed_methods' => ['POST'],
],
],
];
18 changes: 18 additions & 0 deletions src/App/Pipeline/SlackJiraPipeline.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace App\Pipeline;

use App\Validator\ValidateBody;
use Interop\Container\ContainerInterface;
use Zend\Stratigility\MiddlewarePipe;

class SlackJiraPipeline
{
public function __invoke(ContainerInterface $container)
{
$pipeline = new MiddlewarePipe();
$pipeline->pipe($container->get(ValidateBody::class));

return $pipeline;
}
}
19 changes: 19 additions & 0 deletions src/App/Validator/ValidateBody.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Validator;

use Psr\Http\Message\ServerRequestInterface;
use Zend\Expressive\Container\Exception\InvalidArgumentException;
use Zend\Stratigility\Http\ResponseInterface;

class ValidateBody
{
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
{
$body = $request->getParsedBody();
if (!$body) {
throw new InvalidArgumentException("Invalid Body");
}
return $next($request, $response);
}
}

0 comments on commit cd6bda5

Please sign in to comment.