-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from zfegg/develop
implement PSR-15
- Loading branch information
Showing
8 changed files
with
251 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,31 @@ | ||
<?php | ||
|
||
|
||
namespace Zfegg\ContentValidation; | ||
|
||
use Psr\Container\ContainerInterface; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Zend\InputFilter\InputFilterPluginManager; | ||
|
||
class ContentValidationMiddlewareFactory | ||
{ | ||
|
||
public function __invoke(ContainerInterface $container) | ||
{ | ||
return new ContentValidationMiddleware( | ||
$container->get(InputFilterPluginManager::class) | ||
public function __invoke( | ||
ContainerInterface $container, | ||
$requestedName = null, | ||
array $options = null | ||
) { | ||
$requestedName = $requestedName ?: ContentValidationMiddleware::class; | ||
|
||
$response = $container->has(ResponseInterface::class) ? | ||
$container->get(ResponseInterface::class) : null; | ||
|
||
$inputFilterManager = $container->has(InputFilterPluginManager::class) ? | ||
$container->get(InputFilterPluginManager::class) : null; | ||
|
||
return new $requestedName( | ||
$inputFilterManager, | ||
null, | ||
$response | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
|
||
namespace Zfegg\ContentValidation\Exception; | ||
|
||
class InvalidRequestException extends \RuntimeException | ||
{ | ||
protected $inputFilter; | ||
|
||
public function __construct($msg, $code, $inputFilter, $previous = null) | ||
{ | ||
parent::__construct($msg, $code, $previous); | ||
|
||
$this->inputFilter = $inputFilter; | ||
} | ||
|
||
public function getInputFilter() | ||
{ | ||
return $this->inputFilter; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace Zfegg\ContentValidation; | ||
|
||
use Psr\Http\Message\ServerRequestInterface; | ||
use Psr\Http\Server\RequestHandlerInterface; | ||
use Psr\Http\Message\ResponseInterface; | ||
|
||
class RouteNameContentValidationMiddleware extends ContentValidationMiddleware | ||
{ | ||
public function process( | ||
ServerRequestInterface $request, | ||
RequestHandlerInterface $handler | ||
): ResponseInterface { | ||
// Set expressive route name or slim route name | ||
if ($route = $request->getAttribute('Zend\Expressive\Router\RouteResult')) { | ||
$request = $request->withAttribute( | ||
ContentValidationMiddleware::INPUT_FILTER_NAME, | ||
$route->getMatchedRouteName() | ||
); | ||
} elseif ($route = $request->getAttribute('route')) { | ||
$request = $request->withAttribute( | ||
ContentValidationMiddleware::INPUT_FILTER_NAME, | ||
$route->getName() ? : $route->getIdentifier() | ||
); | ||
} | ||
|
||
return parent::process($request, $handler); | ||
} | ||
} |
Oops, something went wrong.