-
-
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.
Added integration between api, spa and ws
1. Added integration with Github API 2. Fixed SPA grid 3. Added subscription on WS events
- Loading branch information
1 parent
6c72134
commit f8fa834
Showing
55 changed files
with
4,965 additions
and
85 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
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,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Spiral\Broadcasting\Driver\NullBroadcast; | ||
|
||
return [ | ||
'default' => env('BROADCAST_CONNECTION', 'centrifugo'), | ||
'aliases' => [], | ||
'connections' => [ | ||
'centrifugo' => [ | ||
'driver' => 'centrifugo', | ||
], | ||
'null' => [ | ||
'driver' => NullBroadcast::class, | ||
], | ||
], | ||
]; |
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,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use App\Endpoint\Centrifugo\ConnectService; | ||
use App\Endpoint\Centrifugo\RPCService; | ||
use RoadRunner\Centrifugo\Request\RequestType; | ||
|
||
return [ | ||
'services' => [ | ||
RequestType::Connect->value => ConnectService::class, | ||
RequestType::RPC->value => RPCService::class, | ||
], | ||
'interceptors' => [ | ||
'*' => [], | ||
], | ||
]; |
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,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
return [ | ||
'interceptors' => [ | ||
\App\Application\Broadcasting\BroadcastEventInterceptor::class | ||
] | ||
]; |
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,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Application\Bootloader; | ||
|
||
use App\Github\Client; | ||
use App\Github\ClientInterface; | ||
use App\Github\WebhookGate; | ||
use Spiral\Boot\Bootloader\Bootloader; | ||
use Spiral\Boot\EnvironmentInterface; | ||
use Spiral\Cache\CacheStorageProviderInterface; | ||
|
||
final class GithubBootloader extends Bootloader | ||
{ | ||
public function defineSingletons(): array | ||
{ | ||
return [ | ||
ClientInterface::class => static fn(CacheStorageProviderInterface $cache) => new Client( | ||
client: new \GuzzleHttp\Client([ | ||
'base_uri' => 'https://api.github.com/', | ||
'headers' => [ | ||
'Accept' => 'application/vnd.github.v3+json', | ||
], | ||
]), | ||
cache: $cache, | ||
), | ||
|
||
WebhookGate::class => static fn( | ||
EnvironmentInterface $env, | ||
) => new WebhookGate(secret: $env->get('GITHUB_WEBHOOK_SECRET', 'secret')), | ||
]; | ||
} | ||
} |
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
35 changes: 35 additions & 0 deletions
35
app/app/src/Application/Broadcasting/BroadcastEventInterceptor.php
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,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Application\Broadcasting; | ||
|
||
use Spiral\Broadcasting\BroadcastInterface; | ||
use Spiral\Core\CoreInterceptorInterface; | ||
use Spiral\Core\CoreInterface; | ||
|
||
final readonly class BroadcastEventInterceptor implements CoreInterceptorInterface | ||
{ | ||
public function __construct( | ||
private BroadcastInterface $broadcast, | ||
) { | ||
} | ||
|
||
public function process(string $controller, string $action, array $parameters, CoreInterface $core): mixed | ||
{ | ||
$event = $parameters['event']; | ||
$result = $core->callAction($controller, $action, $parameters); | ||
|
||
if ($event instanceof ShouldBroadcastInterface) { | ||
$this->broadcast->publish( | ||
$event->getBroadcastTopics(), | ||
\json_encode([ | ||
'event' => $event->getEventName(), | ||
'data' => $event->jsonSerialize(), | ||
], JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE | JSON_INVALID_UTF8_SUBSTITUTE), | ||
); | ||
} | ||
|
||
return $result; | ||
} | ||
} |
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,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Application\Broadcasting\Channel; | ||
|
||
class Channel implements \Stringable | ||
{ | ||
public function __construct( | ||
public readonly string $name | ||
) {} | ||
|
||
public function __toString(): string | ||
{ | ||
return $this->name; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
app/app/src/Application/Broadcasting/Channel/EventsChannel.php
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,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Application\Broadcasting\Channel; | ||
|
||
final class EventsChannel extends Channel | ||
{ | ||
public function __construct() | ||
{ | ||
parent::__construct('events'); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
app/app/src/Application/Broadcasting/ShouldBroadcastInterface.php
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,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Application\Broadcasting; | ||
|
||
use Stringable; | ||
|
||
interface ShouldBroadcastInterface extends \JsonSerializable | ||
{ | ||
public function getEventName(): string; | ||
|
||
public function getBroadcastTopics(): iterable|Stringable; | ||
} |
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,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Endpoint\Centrifugo; | ||
|
||
use RoadRunner\Centrifugo\Payload\ConnectResponse; | ||
use RoadRunner\Centrifugo\Request; | ||
use RoadRunner\Centrifugo\Request\RequestInterface; | ||
use Spiral\RoadRunnerBridge\Centrifugo\ServiceInterface; | ||
|
||
class ConnectService implements ServiceInterface | ||
{ | ||
/** | ||
* @param Request\Connect $request | ||
*/ | ||
public function handle(RequestInterface $request): void | ||
{ | ||
try { | ||
$request->respond( | ||
new ConnectResponse( | ||
user: (string)$request->getAttribute('user_id'), | ||
channels: ['events'], | ||
), | ||
); | ||
} catch (\Throwable $e) { | ||
$request->error($e->getCode(), $e->getMessage()); | ||
} | ||
} | ||
} |
Oops, something went wrong.