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
2 changes: 1 addition & 1 deletion src/Authorization.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function createCookie(Request $request, array $subscribe = [], array $pub
$hubInstance = $this->registry->getHub($hub);
$tokenFactory = $hubInstance->getFactory();
if (null === $tokenFactory) {
throw new InvalidArgumentException(sprintf('The hub "%s" does not contain a token factory.', $hubInstance->getName()));
throw new InvalidArgumentException(sprintf('The %s hub does not contain a token factory.', $hub ? '"'.$hub.'"' : 'default'));
}

$token = $tokenFactory->create($subscribe, $publish, $additionalClaims);
Expand Down
5 changes: 0 additions & 5 deletions src/Debug/TraceableHub.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ public function __construct(HubInterface $hub, Stopwatch $stopwatch)
$this->stopwatch = $stopwatch;
}

public function getName(): string
{
return $this->hub->getName();
}

public function getUrl(): string
{
return $this->hub->getUrl();
Expand Down
11 changes: 0 additions & 11 deletions src/Hub.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,37 +26,26 @@
*/
final class Hub implements HubInterface
{
private $name;
private $url;
private $jwtProvider;
private $jwtFactory;
private $publicUrl;
private $httpClient;

public function __construct(
string $name,
string $url,
TokenProviderInterface $jwtProvider,
TokenFactoryInterface $jwtFactory = null,
string $publicUrl = null,
HttpClientInterface $httpClient = null
) {
$this->name = $name;
$this->url = $url;
$this->jwtProvider = $jwtProvider;
$this->publicUrl = $publicUrl;
$this->jwtFactory = $jwtFactory;
$this->httpClient = $httpClient ?? HttpClient::create();
}

/**
* {@inheritDoc}
*/
public function getName(): string
{
return $this->name;
}

/**
* {@inheritDoc}
*/
Expand Down
5 changes: 0 additions & 5 deletions src/HubInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@
*/
interface HubInterface
{
/**
* Return the name of this Hub.
*/
public function getName(): string;

/**
* Returns the Hub internal URL.
*/
Expand Down
8 changes: 5 additions & 3 deletions src/HubRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

namespace Symfony\Component\Mercure;

use Psr\Container\ContainerInterface;
use Symfony\Component\Mercure\Exception\InvalidArgumentException;

final class HubRegistry
Expand All @@ -24,15 +23,18 @@ final class HubRegistry
/**
* @param array<string, HubInterface> $hubs An array of hub instances, where the keys are the names
*/
public function __construct(string $defaultHub, array $hubs)
public function __construct(HubInterface $defaultHub, array $hubs)
{
$this->defaultHub = $defaultHub;
$this->hubs = $hubs;
}

public function getHub(string $name = null): HubInterface
{
$name = $name ?? $this->defaultHub;
if (null === $name) {
return $this->defaultHub;
}

if (!isset($this->hubs[$name])) {
throw new InvalidArgumentException('Invalid hub name provided.');
}
Expand Down
2 changes: 1 addition & 1 deletion src/Publisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ final class Publisher implements PublisherInterface
private $httpClient;

/**
* @param (callable(Update $update):string)|TokenProviderInterface $jwtProvider
* @param TokenProviderInterface|callable(Update $update):string $jwtProvider
*/
public function __construct(string $hubUrl, $jwtProvider, HttpClientInterface $httpClient = null)
{
Expand Down
6 changes: 3 additions & 3 deletions tests/HubTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function testPublish()
});

$provider = new StaticTokenProvider(self::JWT);
$hub = new Hub('default', self::URL, $provider, null, null, $httpClient);
$hub = new Hub(self::URL, $provider, null, null, $httpClient);
$id = $hub->publish(new Update(
'https://demo.mercure.rocks/demo/books/1.jsonld',
'Hi from Symfony!',
Expand All @@ -70,7 +70,7 @@ public function testNetworkIssue()
});

$provider = new StaticTokenProvider(self::JWT);
$hub = new Hub('default', self::URL, $provider, null, null, $httpClient);
$hub = new Hub(self::URL, $provider, null, null, $httpClient);

$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('Failed to send an update.');
Expand All @@ -91,7 +91,7 @@ public function testInvalidJwt()
$this->expectExceptionMessage('The provided JWT is not valid');

$provider = new StaticTokenProvider("invalid\r\njwt");
$hub = new Hub('default', self::URL, $provider, null, null);
$hub = new Hub(self::URL, $provider, null, null);

$hub->publish(new Update('https://demo.mercure.rocks/demo/books/1.jsonld', 'Hi from Symfony!'));
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Messenger/UpdateHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function testInvoke()
});

$provider = new StaticTokenProvider(self::JWT);
$hub = new Hub('default', self::URL, $provider, null, null, $httpClient);
$hub = new Hub(self::URL, $provider, null, null, $httpClient);
$handler = new UpdateHandler($hub);

$handler(new Update(
Expand Down