Skip to content

Commit

Permalink
new process
Browse files Browse the repository at this point in the history
  • Loading branch information
mostafabarmshory committed Mar 8, 2021
1 parent 7ba242e commit 04a5285
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
18 changes: 15 additions & 3 deletions src/Process/Http/IfPathAndMethodIs.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,23 @@
class IfPathAndMethodIs
{

private string $regex;
private array $regex;

private array $methods;

private bool $removePrefix = true;

public function __construct(string $regex, array $methods = [
public function __construct(string|array $regex, array $methods = [
'GET',
'POST',
'DELETE'
], bool $removePrefix = true)
{
if (is_string($regex)) {
$regex = [
$regex
];
}
$this->regex = $regex;
$this->methods = $methods;
$this->removePrefix = $removePrefix;
Expand All @@ -47,7 +52,14 @@ public function __invoke(RequestInterface $request, UnitTrackerInterface $unitTr
$requestPath = $uri->getPath();
$method = $request->getMethod();
$match = [];
if (! in_array($method, $this->methods) || ! preg_match($this->regex, $requestPath, $match)) {
$matched = false;
foreach ($this->regex as $regex){
if(preg_match($regex, $requestPath, $match)){
$matched = true;
break;
}
}
if (! in_array($method, $this->methods) || ! $matched) {
return $unitTracker->jump();
}
if ($this->removePrefix) {
Expand Down
1 change: 0 additions & 1 deletion src/Process/Http/RequestToEntityQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public function __invoke(ServerRequestInterface $request, EntityManager $entityM
$collectionQuery = $objectMapperArray->readValue($request->getQueryParams(), CollectionQuery::class);

// TODO: maso, 2021: validate the collection query

$query = $entityManager->query()
->limit($collectionQuery->count, $collectionQuery->start);

Expand Down

0 comments on commit 04a5285

Please sign in to comment.