Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions composer.json.dist
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@
"require": {
"php": "^7.1",
"psr/container": "^1.0",
"prooph/event-store" : "^7.0",
"prooph/event-store" : "^7.1.1",
"prooph/pdo-event-store": "^1.3.1",
"roave/security-advisories": "dev-master",
"sandrokeil/interop-config": "^2.1",
"zendframework/zend-config-aggregator": "^0.2.0",
"zendframework/zend-config-aggregator": "^1.0",
"zendframework/zend-diactoros": "^1.4",
"zendframework/zend-expressive": "^2.0",
"zendframework/zend-expressive": "^2.0.3",
"zendframework/zend-expressive-fastroute": "^2.0",
"zendframework/zend-expressive-helpers": "^4.0",
"zendframework/zend-servicemanager": "^3.3",
Expand All @@ -48,9 +49,6 @@
"conflict": {
"container-interop/container-interop": "<1.2.0"
},
"suggest" : {
"prooph/pdo-event-store": "^1.0 for usage with MySQL or Postgres as EventStore"
},
"autoload": {
"psr-4": {
"Prooph\\EventStore\\Http\\Api\\": "src/"
Expand Down
53 changes: 51 additions & 2 deletions src/Action/Load.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
use Prooph\EventStore\EventStore;
use Prooph\EventStore\Exception\StreamNotFound;
use Prooph\EventStore\Http\Api\Transformer\Transformer;
use Prooph\EventStore\Metadata\FieldType;
use Prooph\EventStore\Metadata\MetadataMatcher;
use Prooph\EventStore\Metadata\Operator;
use Prooph\EventStore\StreamName;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
Expand Down Expand Up @@ -87,11 +90,13 @@ public function process(ServerRequestInterface $request, DelegateInterface $dele
return new EmptyResponse(400);
}

$metadataMatcher = $this->buildMetadataMatcher($request);

try {
if ($direction === 'backward') {
$streamEvents = $this->eventStore->loadReverse(new StreamName($streamName), $start, $count);
$streamEvents = $this->eventStore->loadReverse(new StreamName($streamName), $start, $count, $metadataMatcher);
} else {
$streamEvents = $this->eventStore->load(new StreamName($streamName), $start, $count);
$streamEvents = $this->eventStore->load(new StreamName($streamName), $start, $count, $metadataMatcher);
}
} catch (StreamNotFound $e) {
return new EmptyResponse(404);
Expand Down Expand Up @@ -151,6 +156,50 @@ public function process(ServerRequestInterface $request, DelegateInterface $dele
return $transformer->createResponse($result);
}

private function buildMetadataMatcher(ServerRequestInterface $request): MetadataMatcher
{
$metadata = [];
$messageProperty = [];

foreach ($request->getQueryParams() as $queryParam => $value) {
$matches = [];

if (preg_match('/^meta_(\d+)_field$/', $queryParam, $matches)) {
$metadata[$matches[1]]['field'] = $value;
} elseif (preg_match('/^meta_(\d+)_operator$/', $queryParam, $matches)
&& defined(Operator::class . '::' . $value)
) {
$metadata[$matches[1]]['operator'] = Operator::byName($value);
} elseif (preg_match('/^meta_(\d+)_value$/', $queryParam, $matches)) {
$metadata[$matches[1]]['value'] = $value;
} elseif (preg_match('/^property_(\d+)_field$/', $queryParam, $matches)) {
$messageProperty[$matches[1]]['field'] = $value;
} elseif (preg_match('/^property_(\d+)_operator$/', $queryParam, $matches)
&& defined(Operator::class . '::' . $value)
) {
$messageProperty[$matches[1]]['operator'] = Operator::byName($value);
} elseif (preg_match('/^property_(\d+)_value$/', $queryParam, $matches)) {
$messageProperty[$matches[1]]['value'] = $value;
}
}

$metadataMatcher = new MetadataMatcher();

foreach ($metadata as $key => $match) {
if (isset($match['field'], $match['operator'], $match['value'])) {
$metadataMatcher = $metadataMatcher->withMetadataMatch($match['field'], $match['operator'], $match['value'], FieldType::METADATA());
}
}

foreach ($messageProperty as $key => $match) {
if (isset($match['field'], $match['operator'], $match['value'])) {
$metadataMatcher = $metadataMatcher->withMetadataMatch($match['field'], $match['operator'], $match['value'], FieldType::MESSAGE_PROPERTY());
}
}

return $metadataMatcher;
}

private function returnDescription(ServerRequestInterface $request, string $streamName): JsonResponse
{
$id = $this->host($request) . $this->urlHelper->generate('page::query-stream', [
Expand Down
Loading