Skip to content

Commit

Permalink
chore: first release (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
EJTJ3 authored Dec 18, 2023
1 parent 5e74f86 commit 1d64472
Show file tree
Hide file tree
Showing 48 changed files with 2,289 additions and 7 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
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"
54 changes: 54 additions & 0 deletions .github/workflows/grumphp.yml
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' }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ composer.lock
.idea/
.idea/*
vendor
.phpunit.result.cache
.php-cs-fixer.cache
32 changes: 32 additions & 0 deletions .php-cs-fixer.php
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);
30 changes: 30 additions & 0 deletions README.md
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);

```
15 changes: 8 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
],
"autoload-dev": {
"psr-4": {
"Tests\\EJTJ3\\NatsMonitoring\\": "tests/"
"Test\\EJTJ3\\NatsMonitoring\\": "test/"
}
},
"require": {
Expand All @@ -26,18 +26,19 @@
"require-dev": {
"symfony/var-dumper": "^6.3",
"jms/serializer": "3.28.0",
"symfony/http-client": "6.3.*",
"symfony/http-client": "6.4.*",
"phpunit/phpunit": "^10.0",
"friendsofphp/php-cs-fixer": "^3.35",
"phpstan/phpstan": "^1.10"

"friendsofphp/php-cs-fixer": "^3.41",
"phpstan/phpstan": "^1.10",
"phpro/grumphp-shim": "^2.3"
},
"config": {
"allow-plugins": {
"php-http/discovery": true
"php-http/discovery": true,
"phpro/grumphp-shim": true
}
},
"scripts": {
"test": "vendor/bin/phpunit tests"
"test": "vendor/bin/phpunit test"
}
}
15 changes: 15 additions & 0 deletions grumphp.yml
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"
2 changes: 2 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
parameters:
level: max
7 changes: 7 additions & 0 deletions phpunit.xml
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>
78 changes: 78 additions & 0 deletions src/Enum/ConnectionRequestSort.php
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';
}
12 changes: 12 additions & 0 deletions src/Enum/ConnectionRequestState.php
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';
}
52 changes: 52 additions & 0 deletions src/Jms/Serializer/Handler/NatsDateImmutableHandler.php
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');
}
}
45 changes: 45 additions & 0 deletions src/Jms/Serializer/Handler/NatsDateIntervalHandler.php
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);
}
}
Loading

0 comments on commit 1d64472

Please sign in to comment.