Skip to content

Commit cd6bda5

Browse files
committed
Add Slack Jira Pipeline
Add /slack_jira POST route Validate Body
1 parent 6b21dd5 commit cd6bda5

File tree

5 files changed

+53
-3
lines changed

5 files changed

+53
-3
lines changed

config/autoload/dependencies.global.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
use App\Pipeline\SlackJiraPipeline;
3+
use App\Validator\ValidateBody;
24
use Zend\Expressive\Application;
35
use Zend\Expressive\Container\ApplicationFactory;
46
use Zend\Expressive\Helper;
@@ -14,11 +16,13 @@
1416
'invokables' => [
1517
// Fully\Qualified\InterfaceName::class => Fully\Qualified\ClassName::class,
1618
Helper\ServerUrlHelper::class => Helper\ServerUrlHelper::class,
19+
ValidateBody::class => ValidateBody::class,
1720
],
1821
// Use 'factories' for services provided by callbacks/factory classes.
19-
'factories' => [
20-
Application::class => ApplicationFactory::class,
21-
Helper\UrlHelper::class => Helper\UrlHelperFactory::class,
22+
'factories' => [
23+
Application::class => ApplicationFactory::class,
24+
Helper\UrlHelper::class => Helper\UrlHelperFactory::class,
25+
SlackJiraPipeline::class => SlackJiraPipeline::class,
2226
],
2327
],
2428
];

config/autoload/middleware-pipeline.global.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
'middleware' => [
4949
ApplicationFactory::ROUTING_MIDDLEWARE,
5050
Helper\UrlHelperMiddleware::class,
51+
Helper\BodyParams\BodyParamsMiddleware::class,
5152
// Add more middleware here that needs to introspect the routing
5253
// results; this might include:
5354
// - route-based authentication

config/autoload/routes.global.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
use App\Pipeline\SlackJiraPipeline;
4+
35
return [
46
'dependencies' => [
57
'invokables' => [
@@ -24,5 +26,11 @@
2426
'middleware' => App\Action\PingAction::class,
2527
'allowed_methods' => ['GET'],
2628
],
29+
[
30+
'name' => '/slack_jira',
31+
'path' => '/slack_jira',
32+
'middleware' => [SlackJiraPipeline::class],
33+
'allowed_methods' => ['POST'],
34+
],
2735
],
2836
];
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace App\Pipeline;
4+
5+
use App\Validator\ValidateBody;
6+
use Interop\Container\ContainerInterface;
7+
use Zend\Stratigility\MiddlewarePipe;
8+
9+
class SlackJiraPipeline
10+
{
11+
public function __invoke(ContainerInterface $container)
12+
{
13+
$pipeline = new MiddlewarePipe();
14+
$pipeline->pipe($container->get(ValidateBody::class));
15+
16+
return $pipeline;
17+
}
18+
}

src/App/Validator/ValidateBody.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace App\Validator;
4+
5+
use Psr\Http\Message\ServerRequestInterface;
6+
use Zend\Expressive\Container\Exception\InvalidArgumentException;
7+
use Zend\Stratigility\Http\ResponseInterface;
8+
9+
class ValidateBody
10+
{
11+
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
12+
{
13+
$body = $request->getParsedBody();
14+
if (!$body) {
15+
throw new InvalidArgumentException("Invalid Body");
16+
}
17+
return $next($request, $response);
18+
}
19+
}

0 commit comments

Comments
 (0)