Skip to content

Commit

Permalink
Reformat configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
fre5h authored Feb 7, 2021
1 parent d88ada8 commit 3f79c6c
Show file tree
Hide file tree
Showing 17 changed files with 46 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Command/ArgumentDataTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected function initializeDataArgument(InputInterface $input): void
}

try {
$this->data = \json_decode($data, true, 512, JSON_THROW_ON_ERROR);
$this->data = \json_decode($data, true, 512, \JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
throw new InvalidArgumentException('Argument "data" is not a valid JSON.');
}
Expand Down
2 changes: 1 addition & 1 deletion Command/HistoryCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$io->title('Publications');

foreach ($data['publications'] as $info) {
$io->writeln(\json_encode($info['data'], JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR));
$io->writeln(\json_encode($info['data'], \JSON_PRETTY_PRINT | \JSON_THROW_ON_ERROR));
$io->newLine();
$io->writeln('<info>------------</info>');
$io->newLine();
Expand Down
2 changes: 1 addition & 1 deletion Command/InfoCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private function writeParameter(SymfonyStyle $io, string $key, $value, int $padd
if ($padding > 0) {
$formattedKey = $last ? '' : '';
$formattedKey .= $key;
$formattedKey = \str_pad($formattedKey, \strlen($formattedKey) + $padding, ' ', STR_PAD_LEFT);
$formattedKey = \str_pad($formattedKey, \strlen($formattedKey) + $padding, ' ', \STR_PAD_LEFT);
}

if (!\is_array($value)) {
Expand Down
2 changes: 1 addition & 1 deletion Command/PresenceCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
*/
private function formatConnInfo(array $connInfo): string
{
$json = \json_encode($connInfo, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR);
$json = \json_encode($connInfo, \JSON_PRETTY_PRINT | \JSON_THROW_ON_ERROR);

return array_reduce(
\explode("\n", $json),
Expand Down
4 changes: 2 additions & 2 deletions DependencyInjection/Compiler/RegisterCentrifugoPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public function process(ContainerBuilder $container): void
$definition = new Definition(
Centrifugo::class,
[
$container->resolveEnvPlaceholders('%env(CENTRIFUGO_API_ENDPOINT)%'),
$container->resolveEnvPlaceholders('%env(CENTRIFUGO_API_KEY)%'),
$container->getParameter('centrifugo.api_endpoint'),
$container->getParameter('centrifugo.api_key'),
$container->findDefinition('http_client'),
$container->findDefinition(ResponseProcessor::class),
$container->findDefinition(CommandHistoryLogger::class),
Expand Down
12 changes: 12 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ public function getConfigTreeBuilder(): TreeBuilder
->defaultFalse()
->info('Enables fake mode for Centrifugo client, no real request will be sent.')
->end()
->scalarNode('api_key')
->defaultValue('%env(CENTRIFUGO_API_KEY)%')
->info('Centrifugo API key')
->end()
->scalarNode('api_endpoint')
->defaultValue('%env(CENTRIFUGO_API_ENDPOINT)%')
->info('Centrifugo API endpoint')
->end()
->scalarNode('secret')
->defaultValue('%env(CENTRIFUGO_SECRET)%')
->info('Centrifugo secret')
->end()
->end()
;

Expand Down
3 changes: 3 additions & 0 deletions DependencyInjection/FreshCentrifugoExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public function load(array $configs, ContainerBuilder $container): void
$container->setParameter('centrifugo.channel_max_length', (int) $config['channel_max_length']);
$container->setParameter('centrifugo.jwt.ttl', $config['jwt']['ttl']);
$container->setParameter('centrifugo.fake_mode', $config['fake_mode']);
$container->setParameter('centrifugo.api_key', $config['api_key']);
$container->setParameter('centrifugo.api_endpoint', $config['api_endpoint']);
$container->setParameter('centrifugo.secret', $config['secret']);
$container->registerForAutoconfiguration(ChannelAuthenticatorInterface::class)->addTag('centrifugo.channel_authenticator');
}
}
2 changes: 1 addition & 1 deletion Model/BatchRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function prepareLineDelimitedJson(): string
$serializedCommands = [];

foreach ($this->getCommands() as $command) {
$serializedCommands[] = \json_encode($command, JSON_THROW_ON_ERROR);
$serializedCommands[] = \json_encode($command, \JSON_THROW_ON_ERROR);
}

if (!empty($serializedCommands)) {
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ return [

###> fresh/centrifugo-bundle ###
CENTRIFUGO_API_KEY=secret-api-key
CENTRIFUGO_API_ENDPOINT=http://centrifugo:8000/api
CENTRIFUGO_API_ENDPOINT=http://localhost:8000/api
CENTRIFUGO_SECRET=secret
###< fresh/centrifugo-bundle ###
```
Expand Down
2 changes: 1 addition & 1 deletion Resources/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ services:
bind:
$centrifugoChannelMaxLength: '%centrifugo.channel_max_length%'
$centrifugoJwtTtl: '%centrifugo.jwt.ttl%'
$centrifugoSecret: '%env(CENTRIFUGO_SECRET)%'
$centrifugoSecret: '%centrifugo.secret%'
iterable $channelAuthenticators: !tagged_iterator 'centrifugo.channel_authenticator'

Fresh\DateTime\DateTimeHelper:
Expand Down
3 changes: 3 additions & 0 deletions Resources/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ fresh_centrifugo:
# Default NULL value means that tokens will not be expired
ttl: 86400
fake_mode: true # Enables fake mode for Centrifugo client, no real request will be sent.
api_key: '%env(CENTRIFUGO_API_KEY)%' # You can change API key here
api_endpoint: '%env(CENTRIFUGO_API_ENDPOINT)%' # You can change API endpoint here
secret: '%env(CENTRIFUGO_SECRET)%' # You can change secret here
```
## More features
Expand Down
2 changes: 1 addition & 1 deletion Service/Centrifugo.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ private function doSendCommand(CommandInterface $command): ?array
if ($command instanceof Model\BatchRequest) {
$json = $command->prepareLineDelimitedJson();
} else {
$json = \json_encode($command, JSON_THROW_ON_ERROR);
$json = \json_encode($command, \JSON_THROW_ON_ERROR);
}

if ($this->profilerEnabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private function findAppropriateChannelAuthenticator(string $channel): ?ChannelA
private function processRequest(Request $request): array
{
try {
$content = \json_decode((string) $request->getContent(), true, 512, JSON_THROW_ON_ERROR);
$content = \json_decode((string) $request->getContent(), true, 512, \JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
throw new BadRequestHttpException('Invalid JSON.');
} catch (\Exception $e) {
Expand Down
2 changes: 1 addition & 1 deletion Service/Jwt/JwtGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private function buildSignaturePart(string $headerPartDecoded, string $payloadPa
*/
private function convertArrayToJsonString(array $array): string
{
return \json_encode($array, JSON_THROW_ON_ERROR);
return \json_encode($array, \JSON_THROW_ON_ERROR);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Service/ResponseProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function processResponse(CommandInterface $command, ResponseInterface $re
private function decodeAndProcessResponseResult(CommandInterface $command, string $content): ?array
{
try {
$data = \json_decode($content, true, 512, JSON_THROW_ON_ERROR);
$data = \json_decode($content, true, 512, \JSON_THROW_ON_ERROR);
} catch (\Exception $e) {
throw new CentrifugoException('Centrifugo response payload is not a valid JSON');
}
Expand Down
14 changes: 12 additions & 2 deletions Tests/DependencyInjection/Compiler/RegisterCentrifugoPassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public function testProcessFakeCentrifugo(): void
$this->containerBuilder
->expects(self::once())
->method('getParameter')
->with('centrifugo.fake_mode')
->willReturn(true)
;

Expand All @@ -70,9 +71,18 @@ public function testProcessFakeCentrifugo(): void
public function testProcessCentrifugo(): void
{
$this->containerBuilder
->expects(self::once())
->expects(self::exactly(3))
->method('getParameter')
->willReturn(false)
->withConsecutive(
['centrifugo.fake_mode'],
['centrifugo.api_endpoint'],
['centrifugo.api_key'],
)
->willReturnOnConsecutiveCalls(
false,
'%env(CENTRIFUGO_API_ENDPOINT)%',
'%env(CENTRIFUGO_API_KEY)%'
)
;

$this->containerBuilder
Expand Down
3 changes: 3 additions & 0 deletions Tests/DependencyInjection/FreshCentrifugoExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ public function testLoadExtension(): void
self::assertTrue($this->container->hasParameter('centrifugo.jwt.ttl'));
self::assertNull($this->container->getParameter('centrifugo.jwt.ttl'));
self::assertFalse($this->container->getParameter('centrifugo.fake_mode'));
self::assertNotEmpty($this->container->getParameter('centrifugo.api_key'));
self::assertNotEmpty($this->container->getParameter('centrifugo.api_endpoint'));
self::assertNotEmpty($this->container->getParameter('centrifugo.secret'));

$childDefinitions = $this->container->getAutoconfiguredInstanceof();
foreach ($childDefinitions as $childDefinition) {
Expand Down

0 comments on commit 3f79c6c

Please sign in to comment.