-
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.
- Loading branch information
Showing
48 changed files
with
2,289 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: "github-actions" | ||
directory: "/" | ||
schedule: | ||
interval: "weekly" |
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,54 @@ | ||
name: GrumPHP | ||
|
||
on: [push, pull_request] | ||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
run: | ||
runs-on: ${{ matrix.operating-system }} | ||
strategy: | ||
matrix: | ||
operating-system: [ubuntu-latest, macos-latest] | ||
php-versions: ['8.1', '8.2', '8.3'] | ||
composer-options: ['', '--prefer-lowest'] | ||
composer-versions: ['composer:v2'] | ||
fail-fast: false | ||
name: PHP ${{ matrix.php-versions }} @ ${{ matrix.operating-system }} with ${{ matrix.composer-versions }} ${{ matrix.composer-options }} | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@master | ||
- name: Install PHP | ||
uses: shivammathur/setup-php@master | ||
with: | ||
php-version: ${{ matrix.php-versions }} | ||
tools: ${{ matrix.composer-versions }} | ||
extensions: xdebug, mbstring, posix | ||
- name: Check Versions | ||
run: | | ||
php -v | ||
php -m | ||
composer --version | ||
- name: Get composer cache directory | ||
id: composercache | ||
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT | ||
- name: Cache dependencies | ||
uses: actions/cache@v3 | ||
with: | ||
path: ${{ steps.composercache.outputs.dir }} | ||
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} | ||
restore-keys: ${{ runner.os }}-composer- | ||
- name: Install dependencies | ||
if: matrix.php-versions != '8.3' | ||
run: composer update --prefer-dist --no-progress --no-suggest ${{ matrix.composer-options }} | ||
- name: Install dependencies (Ignore platform) | ||
if: matrix.php-versions == '8.3' | ||
run: composer update --prefer-dist --no-progress --no-suggest ${{ matrix.composer-options }} --ignore-platform-req=php+ | ||
- name: Set git variables | ||
run: | | ||
git config --global user.email "[email protected]" | ||
git config --global user.name "Your Name" | ||
git config --global protocol.file.allow always | ||
- name: Run the tests on unix | ||
run: php vendor/bin/grumphp run --no-interaction | ||
continue-on-error: ${{ matrix.php-versions == '8.1' && matrix.composer-options == '--prefer-lowest' }} |
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 |
---|---|---|
|
@@ -3,3 +3,5 @@ composer.lock | |
.idea/ | ||
.idea/* | ||
vendor | ||
.phpunit.result.cache | ||
.php-cs-fixer.cache |
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,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
$finder = PhpCsFixer\Finder::create()->in(__DIR__); | ||
|
||
return (new PhpCsFixer\Config()) | ||
->setRules([ | ||
'nullable_type_declaration' => false, | ||
'fully_qualified_strict_types' => true, | ||
'ordered_imports' => true, | ||
'@PSR12' => true, | ||
'no_unused_imports' => true, | ||
'concat_space' => ['spacing' => 'one'], | ||
'array_syntax' => ['syntax' => 'short'], | ||
'class_attributes_separation' => true, | ||
'no_extra_blank_lines' => true, | ||
'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline'], | ||
'phpdoc_align' => false, | ||
'strict_param' => false, | ||
'yoda_style' => false, | ||
'phpdoc_separation' => true, | ||
'no_superfluous_phpdoc_tags' => [ | ||
'allow_mixed' => true, | ||
], | ||
'global_namespace_import' => [ | ||
'import_classes' => true, | ||
], | ||
'phpdoc_order' => true, | ||
'single_quote' => true, | ||
]) | ||
->setFinder($finder); |
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 @@ | ||
## WORK IN PROGRESS!! | ||
# Nats monitoring | ||
|
||
```php | ||
use EJTJ3\NatsMonitoring\Jms\Serializer\Handler\NatsDateImmutableHandler; | ||
use EJTJ3\NatsMonitoring\Jms\Serializer\Handler\NatsDateIntervalHandler; | ||
use EJTJ3\NatsMonitoring\Model\ConnectionRequest; | ||
use EJTJ3\NatsMonitoring\NatsMonitoringClient; | ||
use JMS\Serializer\Handler\HandlerRegistry; | ||
use JMS\Serializer\SerializerBuilder; | ||
use Symfony\Component\HttpClient\Psr18Client; | ||
|
||
$serializerBuilder = new SerializerBuilder(); | ||
$serializerBuilder->configureHandlers(static function (HandlerRegistry $registry): void { | ||
$registry->registerSubscribingHandler(new NatsDateIntervalHandler()); | ||
$registry->registerSubscribingHandler(new NatsDateImmutableHandler()); | ||
}); | ||
$serializer = $serializerBuilder->build(); | ||
|
||
$client = new NatsMonitoringClient( | ||
serializer: $serializer, | ||
client: new Psr18Client(), | ||
); | ||
|
||
$requestOptions = new ConnectionRequest(); | ||
$requestOptions->setAuth(true); | ||
|
||
$connections = $client->getConnections('https://demo.nats.io:8222', $requestOptions); | ||
|
||
``` |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
grumphp: | ||
process_timeout: 120 | ||
parallel: | ||
enabled: false | ||
ascii: | ||
succeeded: | ||
failed: | ||
tasks: | ||
phpcsfixer: | ||
config: .php-cs-fixer.php | ||
phpunit: ~ | ||
phpstan: | ||
configuration: "phpstan.neon" | ||
ignore_patterns: | ||
- "test" |
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,2 @@ | ||
parameters: | ||
level: max |
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,7 @@ | ||
<phpunit colors="true"> | ||
<testsuites> | ||
<testsuite name="Intergration"> | ||
<directory>test/Intergration</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
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,78 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace EJTJ3\NatsMonitoring\Enum; | ||
|
||
enum ConnectionRequestSort: string | ||
{ | ||
/** | ||
* Sort by connection ID. | ||
*/ | ||
case CID = 'cid'; | ||
|
||
/** | ||
* Sort by connection start time, same as CID. | ||
*/ | ||
case START = 'start'; | ||
|
||
/** | ||
* Sort by number of subscriptions. | ||
*/ | ||
case SUBS = 'subs'; | ||
|
||
/** | ||
* Sort by amount of data in bytes waiting to be sent to client. | ||
*/ | ||
case PENDING = 'pending'; | ||
|
||
/** | ||
* Sort bynumber of messages sent. | ||
*/ | ||
case MSG_SENT = 'msgs_to'; | ||
|
||
/** | ||
* Sort by Number of messages received. | ||
*/ | ||
case MSG_REC = 'msgs_from'; | ||
|
||
/** | ||
* Sort by: number of bytes sent. | ||
*/ | ||
case BYTES_SENT = 'bytes_to'; | ||
|
||
/** | ||
* sort by Number of bytes received. | ||
*/ | ||
case BYTES_REC = 'bytes_from'; | ||
|
||
/** | ||
* Sort by Lifetime of the connection. | ||
*/ | ||
case UPTIME = 'uptime'; | ||
|
||
/** | ||
* Sort by Last activity. | ||
*/ | ||
case LAST = 'last'; | ||
|
||
/** | ||
* Sort by Amount of inactivity. | ||
*/ | ||
case IDLE = 'idle'; | ||
|
||
/** | ||
* Sort by: Stop time for a closed connection. | ||
*/ | ||
case STOP_TIME = 'stop'; | ||
|
||
/** | ||
* Sort by: reason for a closed connection. | ||
*/ | ||
case REASON = 'reason'; | ||
|
||
/** | ||
* Sort by Round trip time. | ||
*/ | ||
case RTT = 'rtt'; | ||
} |
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,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace EJTJ3\NatsMonitoring\Enum; | ||
|
||
enum ConnectionRequestState: string | ||
{ | ||
case OPEN = 'open'; | ||
case CLOSED = 'closed'; | ||
case ANY = 'any'; | ||
} |
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,52 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace EJTJ3\NatsMonitoring\Jms\Serializer\Handler; | ||
|
||
use DateTimeImmutable; | ||
use DateTimeZone; | ||
use Exception; | ||
use JMS\Serializer\Context; | ||
use JMS\Serializer\GraphNavigatorInterface; | ||
use JMS\Serializer\Handler\SubscribingHandlerInterface; | ||
use JMS\Serializer\JsonDeserializationVisitor; | ||
|
||
final class NatsDateImmutableHandler implements SubscribingHandlerInterface | ||
{ | ||
private static ?DateTimeZone $utc = null; | ||
|
||
/** | ||
* @return array<int, array{direction: int, format: string, type: string, method: string}> | ||
*/ | ||
public static function getSubscribingMethods(): array | ||
{ | ||
return [ | ||
[ | ||
'direction' => GraphNavigatorInterface::DIRECTION_DESERIALIZATION, | ||
'format' => 'json', | ||
'type' => 'NatsDateTimeImmutable', | ||
'method' => 'deserializeDateTimeToJson', | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* @param array<string, mixed> $type | ||
* | ||
* @throws Exception | ||
*/ | ||
public static function deserializeDateTimeToJson( | ||
JsonDeserializationVisitor $visitor, | ||
string $dateString, | ||
array $type, | ||
Context $context | ||
): DateTimeImmutable { | ||
return new DateTimeImmutable(explode('.', $dateString)[0], self::getUtc()); | ||
} | ||
|
||
private static function getUtc(): DateTimeZone | ||
{ | ||
return self::$utc ??= new DateTimeZone('UTC'); | ||
} | ||
} |
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,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace EJTJ3\NatsMonitoring\Jms\Serializer\Handler; | ||
|
||
use EJTJ3\NatsMonitoring\Util\NatsDateUtil; | ||
use Exception; | ||
use JMS\Serializer\Context; | ||
use JMS\Serializer\GraphNavigatorInterface; | ||
use JMS\Serializer\Handler\SubscribingHandlerInterface; | ||
use JMS\Serializer\JsonDeserializationVisitor; | ||
use DateInterval; | ||
|
||
final class NatsDateIntervalHandler implements SubscribingHandlerInterface | ||
{ | ||
/** | ||
* @return array<int, array{direction: int, format: string, type: string, method: string}> | ||
*/ | ||
public static function getSubscribingMethods(): array | ||
{ | ||
return [ | ||
[ | ||
'direction' => GraphNavigatorInterface::DIRECTION_DESERIALIZATION, | ||
'format' => 'json', | ||
'type' => 'NatsDateInterval', | ||
'method' => 'deserializeDateTimeToJson', | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* @param array<string, mixed> $type | ||
* | ||
* @throws Exception | ||
*/ | ||
public function deserializeDateTimeToJson( | ||
JsonDeserializationVisitor $visitor, | ||
string $interval, | ||
array $type, | ||
Context $context | ||
): DateInterval { | ||
return NatsDateUtil::createDateInterval($interval); | ||
} | ||
} |
Oops, something went wrong.