Skip to content

Commit 6e04fd7

Browse files
fix(symfony): Solve SF 7 deprecation (#190)
1 parent 66b66fd commit 6e04fd7

File tree

9 files changed

+18
-17
lines changed

9 files changed

+18
-17
lines changed

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@
5353
"config": {
5454
"sort-packages": true,
5555
"allow-plugins": {
56-
"symfony/flex": true
56+
"symfony/flex": true,
57+
"php-http/discovery": true
5758
}
5859
}
5960
}

src/Bridge/Symfony/DependencyInjection/Configuration.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public function getConfigTreeBuilder(): TreeBuilder
108108
->validate()
109109
->ifTrue(fn (array $config): bool => $config['default_connection'] && !\array_key_exists($config['default_connection'], $config['connections']))
110110
->then(function (array $v) {
111-
throw new InvalidConfigurationException(sprintf('The default connection "%s" does not exists. Available connections are: "%s".', $v['default_connection'], implode('", "', array_keys($v['connections']))));
111+
throw new InvalidConfigurationException(\sprintf('The default connection "%s" does not exists. Available connections are: "%s".', $v['default_connection'], implode('", "', array_keys($v['connections']))));
112112
})
113113
->end()
114114
;

src/Bridge/Symfony/DependencyInjection/ElasticallyExtension.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
use Symfony\Component\Config\FileLocator;
1919
use Symfony\Component\DependencyInjection\ChildDefinition;
2020
use Symfony\Component\DependencyInjection\ContainerBuilder;
21+
use Symfony\Component\DependencyInjection\Extension\Extension;
2122
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
2223
use Symfony\Component\DependencyInjection\Reference;
23-
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
2424

2525
class ElasticallyExtension extends Extension
2626
{

src/IndexBuilder.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ public function createIndex(string $indexName, array $context = []): Index
4040
{
4141
$mapping = $this->mappingProvider->provideMapping($indexName, $context);
4242

43-
$realName = sprintf('%s_%s', $indexName, date('Y-m-d-His'));
43+
$realName = \sprintf('%s_%s', $indexName, date('Y-m-d-His'));
4444
$index = $this->client->getIndex($realName);
4545

4646
if ($index->exists()) {
47-
throw new RuntimeException(sprintf('Index "%s" is already created, something is wrong.', $index->getName()));
47+
throw new RuntimeException(\sprintf('Index "%s" is already created, something is wrong.', $index->getName()));
4848
}
4949

5050
$index->create($mapping ?? []);
@@ -97,7 +97,7 @@ public function migrate(Index $currentIndex, array $params = [], array $context
9797
$response = $reindex->run();
9898

9999
if (!$response->isOk()) {
100-
throw new RuntimeException(sprintf('Reindex call failed. %s', $response->getError()));
100+
throw new RuntimeException(\sprintf('Reindex call failed. %s', $response->getError()));
101101
}
102102

103103
$taskId = $response->getData()['task'];
@@ -172,14 +172,14 @@ public function purgeOldIndices(string $indexName, bool $dryRun = false): array
172172
$index = new \Elastica\Index($this->client, $realIndexName);
173173
$index->delete();
174174
}
175-
$operations[] = sprintf('%s deleted.', $realIndexName);
175+
$operations[] = \sprintf('%s deleted.', $realIndexName);
176176
} elseif ($livePassed && 1 === $afterLiveCounter) {
177177
// Close
178178
if (false === $dryRun) {
179179
$index = new \Elastica\Index($this->client, $realIndexName);
180180
$index->close();
181181
}
182-
$operations[] = sprintf('%s closed.', $realIndexName);
182+
$operations[] = \sprintf('%s closed.', $realIndexName);
183183
}
184184
}
185185

src/IndexNameMapper.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function __construct(?string $prefix, array $indexClassMapping)
2828
public function getPrefixedIndex(string $name): string
2929
{
3030
if ($this->prefix) {
31-
return sprintf('%s_%s', $this->prefix, $name);
31+
return \sprintf('%s_%s', $this->prefix, $name);
3232
}
3333

3434
return $name;
@@ -42,7 +42,7 @@ public function getIndexNameFromClass(string $className): string
4242
$indexName = array_search($className, $this->indexClassMapping, true);
4343

4444
if (!$indexName) {
45-
throw new RuntimeException(sprintf('The given type (%s) does not exist in the configuration.', $className));
45+
throw new RuntimeException(\sprintf('The given type (%s) does not exist in the configuration.', $className));
4646
}
4747

4848
return $this->getPrefixedIndex($indexName);
@@ -54,7 +54,7 @@ public function getIndexNameFromClass(string $className): string
5454
public function getClassFromIndexName(string $indexName): string
5555
{
5656
if (!isset($this->indexClassMapping[$indexName])) {
57-
throw new RuntimeException(sprintf('Unknown class for index "%s". Please check your configuration.', $indexName));
57+
throw new RuntimeException(\sprintf('Unknown class for index "%s". Please check your configuration.', $indexName));
5858
}
5959

6060
return $this->indexClassMapping[$indexName];
@@ -63,7 +63,7 @@ public function getClassFromIndexName(string $indexName): string
6363
public function getPureIndexName(string $fullIndexName): string
6464
{
6565
if ($this->prefix) {
66-
$pattern = sprintf('/%s_(.+)_\d{4}-\d{2}-\d{2}-\d+/i', preg_quote($this->prefix, '/'));
66+
$pattern = \sprintf('/%s_(.+)_\d{4}-\d{2}-\d{2}-\d+/i', preg_quote($this->prefix, '/'));
6767
} else {
6868
$pattern = '/(.+)_\d{4}-\d{2}-\d{2}-\d+/i';
6969
}

src/Mapping/PhpProvider.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function provideMapping(string $indexName, array $context = []): ?array
2929
$fileName = $context['filename'] ?? ($indexName . '_mapping.php');
3030
$mappingFilePath = $this->configurationDirectory . \DIRECTORY_SEPARATOR . $fileName;
3131
if (!is_file($mappingFilePath)) {
32-
throw new InvalidException(sprintf('Mapping file "%s" not found.', $mappingFilePath));
32+
throw new InvalidException(\sprintf('Mapping file "%s" not found.', $mappingFilePath));
3333
}
3434

3535
$mapping = require $mappingFilePath;

src/Mapping/YamlProvider.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function provideMapping(string $indexName, array $context = []): ?array
3434
$fileName = $context['filename'] ?? ($indexName . '_mapping.yaml');
3535
$mappingFilePath = $this->configurationDirectory . \DIRECTORY_SEPARATOR . $fileName;
3636
if (!is_file($mappingFilePath)) {
37-
throw new InvalidException(sprintf('Mapping file "%s" not found. Please check your configuration.', $mappingFilePath));
37+
throw new InvalidException(\sprintf('Mapping file "%s" not found. Please check your configuration.', $mappingFilePath));
3838
}
3939

4040
$mapping = $this->parser->parseFile($mappingFilePath);

src/Messenger/IndexationRequest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ final class IndexationRequest implements IndexationRequestInterface
2020
public function __construct(string $className, string $id, string $operation = IndexationRequestHandler::OP_INDEX)
2121
{
2222
if (!\in_array($operation, IndexationRequestHandler::OPERATIONS, true)) {
23-
throw new \InvalidArgumentException(sprintf('Not supported operation "%s" given.', $operation));
23+
throw new \InvalidArgumentException(\sprintf('Not supported operation "%s" given.', $operation));
2424
}
2525

2626
$this->className = $className;

tests/Symfony/TestKernel.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ protected function configureRoutes($routes): void
5757
$routes->add('/with_response', TestController::class . '::withResponse', 'with_response');
5858
} else {
5959
$routeConfigurator = $routes->add('with_exception', '/with_exception');
60-
$routeConfigurator->controller(sprintf('%s::withException', TestController::class));
60+
$routeConfigurator->controller(\sprintf('%s::withException', TestController::class));
6161

6262
$routeConfigurator = $routes->add('with_response', '/with_response');
63-
$routeConfigurator->controller(sprintf('%s::withResponse', TestController::class));
63+
$routeConfigurator->controller(\sprintf('%s::withResponse', TestController::class));
6464
}
6565
}
6666
}

0 commit comments

Comments
 (0)