Skip to content

Commit

Permalink
Merge pull request #4 from rstgroup/psr-15
Browse files Browse the repository at this point in the history
Add psr-15 support
  • Loading branch information
snapshotpl authored May 24, 2017
2 parents e34daee + c1e0368 commit e28ed6c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ Use [Expressive Configuration Manager](https://github.com/mtymek/expressive-conf
After this you can enable middleware in your middleware-stack using `RstGroup\HttpMethodOverride\HttpMethodOverrideMiddleware`
service name in your container.

### Specific installation for Zend Framework 2
### Specific installation for Zend Framework 2 & 3

Add module `RstGroup\HttpMethodOverride` to `application.config.php` file.
8 changes: 6 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,18 @@
"zendframework/zend-eventmanager": "^2.4 || ^3.0",
"zendframework/zend-mvc": "^2.4 || ^3.0",
"zendframework/zend-diactoros": "^1.3.3",
"zendframework/zend-modulemanager": "^2.4"
"zendframework/zend-modulemanager": "^2.4",
"php-middleware/double-pass-compatibility": "^1.0",
"http-interop/http-middleware": "^0.4.1"
},
"suggest": {
"zendframework/zend-http": "To use rstgroup/http-method-override as ZF module",
"zendframework/zend-eventmanager": "To use rstgroup/http-method-override as ZF module",
"zendframework/zend-mvc": "To use rstgroup/http-method-override as ZF module",
"zendframework/zend-modulemanager": "To use rstgroup/http-method-override as ZF module",
"psr/http-message": "To use rstgroup/http-method-override as middleware"
"psr/http-message": "To use rstgroup/http-method-override as middleware",
"php-middleware/double-pass-compatibility": "To use rstgroup/http-method-override as middleware",
"http-interop/http-middleware": "To use rstgroup/http-method-override as middleware"
},
"autoload": {
"psr-4": {
Expand Down
21 changes: 9 additions & 12 deletions src/HttpMethodOverrideMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,23 @@

namespace RstGroup\HttpMethodOverride;

use Psr\Http\Message\ResponseInterface;
use Interop\Http\ServerMiddleware\DelegateInterface;
use Interop\Http\ServerMiddleware\MiddlewareInterface;
use PhpMiddleware\DoublePassCompatibilityTrait;
use Psr\Http\Message\ServerRequestInterface;

final class HttpMethodOverrideMiddleware
final class HttpMethodOverrideMiddleware implements MiddlewareInterface
{
use DoublePassCompatibilityTrait;

private $service;

public function __construct(HttpMethodOverrideService $service)
{
$this->service = $service;
}

/**
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @param callable $next
*
* @return $response
*/
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
public function process(ServerRequestInterface $request, DelegateInterface $delegate)
{
$method = $request->getMethod();
$headers = $this->getHeadersFromRequest($request);
Expand All @@ -32,7 +29,7 @@ public function __invoke(ServerRequestInterface $request, ResponseInterface $res
$request = $request->withMethod($overridedHeader);
}

return $next($request, $response);
return $delegate->process($request);
}

/**
Expand All @@ -51,4 +48,4 @@ private function getHeadersFromRequest(ServerRequestInterface $request)
}
return $headerNames;
}
}
}

0 comments on commit e28ed6c

Please sign in to comment.