Skip to content
This repository has been archived by the owner on Jan 27, 2022. It is now read-only.

Commit

Permalink
fix #25 (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
max107 committed Dec 1, 2020
1 parent 9e93eaf commit 0ccd581
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 62 deletions.
124 changes: 65 additions & 59 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,63 +1,69 @@
{
"description": "The LeNats is a Symfony bundle. it's implements event-based architecture with nats streaming on php",
"name": "vseinstrumentiru/lenats",
"type": "symfony-bundle",
"license": "GPL-3.0-only",
"keywords": ["nats", "nats streaming", "cloud events", "symfony", "php", "event-driven"],
"authors": [
{
"name": "Ilya Shtrikul",
"email": "shtricul@gmail.comm"
}
],
"config": {
"preferred-install": {
"*": "dist"
"description": "The LeNats is a Symfony bundle. it's implements event-based architecture with nats streaming on php",
"name": "vseinstrumentiru/lenats",
"type": "symfony-bundle",
"license": "GPL-3.0-only",
"keywords": [
"nats",
"nats streaming",
"cloud events",
"symfony",
"php",
"event-driven"
],
"authors": [
{
"name": "Ilya Shtrikul",
"email": "shtricul@gmail.comm"
}
],
"config": {
"preferred-install": {
"*": "dist"
},
"sort-packages": true
},
"sort-packages": true
},
"autoload": {
"psr-4": {
"LeNats\\": "src/",
"GPBMetadata\\": "gen/GPBMetadata/",
"NatsStreamingProtocol\\": "gen/NatsStreamingProtocol/"
}
},
"autoload-dev": {
"psr-4": {
"LeNats\\Tests\\": "tests/"
"autoload": {
"psr-4": {
"LeNats\\": "src/",
"GPBMetadata\\": "gen/GPBMetadata/",
"NatsStreamingProtocol\\": "gen/NatsStreamingProtocol/"
}
},
"autoload-dev": {
"psr-4": {
"LeNats\\Tests\\": "tests/"
}
},
"require": {
"php": "^7.3",
"ext-ctype": "*",
"ext-iconv": "*",
"ext-json": "*",
"clue/block-react": "^1.3",
"google/protobuf": "^3.7",
"jms/serializer-bundle": "^2.4|^3.3",
"mhujer/jms-serializer-uuid": "^1.0|^3.1",
"psr/event-dispatcher": "^0.6|^1.0",
"rakit/validation": "^1.1",
"react/promise-timer": "^1.5",
"react/socket": "^1.2",
"react/stream": "^1.1",
"symfony/console": "^4.4",
"symfony/event-dispatcher": "^4.4",
"symfony/framework-bundle": "^4.4",
"symfony/yaml": "^4.4"
},
"require-dev": {
"phpstan/phpstan": "^0.11.2",
"phpstan/phpstan-symfony": "^0.11.1",
"symfony/phpunit-bridge": "^4.4",
"symplify/easy-coding-standard": "^5.4",
"phpunit/phpunit": "^8.0"
},
"scripts": {
"ecs": "vendor/bin/ecs check ./src --fix",
"test": "bin/phpunit",
"stan": "vendor/bin/phpstan analyze ./src"
}
},
"require": {
"php": "^7.3",
"ext-ctype": "*",
"ext-iconv": "*",
"ext-json": "*",
"clue/block-react": "^1.3",
"google/protobuf": "^3.7",
"illuminate/support": "^5.8",
"jms/serializer-bundle": "^2.4|^3.3",
"mhujer/jms-serializer-uuid": "^1.0|^3.1",
"psr/event-dispatcher": "^0.6|^1.0",
"rakit/validation": "^1.1",
"react/promise-timer": "^1.5",
"react/socket": "^1.2",
"react/stream": "^1.1",
"symfony/console": "^4.4",
"symfony/event-dispatcher": "^4.4",
"symfony/framework-bundle": "^4.4",
"symfony/yaml": "^4.4"
},
"require-dev": {
"phpstan/phpstan": "^0.11.2",
"phpstan/phpstan-symfony": "^0.11.1",
"symfony/phpunit-bridge": "^4.4",
"symplify/easy-coding-standard": "^5.4",
"phpunit/phpunit": "^8.0"
},
"scripts": {
"ecs": "vendor/bin/ecs check ./src --fix",
"test": "bin/phpunit",
"stan": "vendor/bin/phpstan analyze ./src"
}
}
38 changes: 35 additions & 3 deletions src/Services/EventTypeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace LeNats\Services;

use Illuminate\Support\Str;

class EventTypeResolver
{
/** @var string[] */
Expand All @@ -19,12 +17,46 @@ public function getClass(string $eventType): ?string
$class = null;

foreach ($this->types as $typeWildcard => $eventClass) {
if ($typeWildcard === $eventType || Str::is($typeWildcard, $eventType)) {
if ($typeWildcard === $eventType || $this->is($typeWildcard, $eventType)) {
$class = $eventClass;
break;
}
}

return $class;
}

/**
* Determine if a given string matches a given pattern.
*
* @param string|array $pattern
* @param string $value
* @return bool
*/
public function is($pattern, $value)
{
if (empty($pattern)) {
return false;
}

// If the given value is an exact match we can of course return true right
// from the beginning. Otherwise, we will translate asterisks and do an
// actual pattern match against the two strings to see if they match.
if ($pattern == $value) {
return true;
}

$pattern = preg_quote($pattern, '#');

// Asterisks are translated into zero-or-more regular expression wildcards
// to make it convenient to check if the strings starts with the given
// pattern such as "library/*", making any string check convenient.
$pattern = str_replace('\*', '.*', $pattern);

if (preg_match('#^'.$pattern.'\z#u', $value) === 1) {
return true;
}

return false;
}
}

0 comments on commit 0ccd581

Please sign in to comment.