Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solve SF 7 deprecation #190

Merged
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
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
"config": {
"sort-packages": true,
"allow-plugins": {
"symfony/flex": true
"symfony/flex": true,
"php-http/discovery": true
}
}
}
2 changes: 1 addition & 1 deletion src/Bridge/Symfony/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function getConfigTreeBuilder(): TreeBuilder
->validate()
->ifTrue(fn (array $config): bool => $config['default_connection'] && !\array_key_exists($config['default_connection'], $config['connections']))
->then(function (array $v) {
throw new InvalidConfigurationException(sprintf('The default connection "%s" does not exists. Available connections are: "%s".', $v['default_connection'], implode('", "', array_keys($v['connections']))));
throw new InvalidConfigurationException(\sprintf('The default connection "%s" does not exists. Available connections are: "%s".', $v['default_connection'], implode('", "', array_keys($v['connections']))));
})
->end()
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

class ElasticallyExtension extends Extension
{
Expand Down
10 changes: 5 additions & 5 deletions src/IndexBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ public function createIndex(string $indexName, array $context = []): Index
{
$mapping = $this->mappingProvider->provideMapping($indexName, $context);

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

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

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

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

$taskId = $response->getData()['task'];
Expand Down Expand Up @@ -172,14 +172,14 @@ public function purgeOldIndices(string $indexName, bool $dryRun = false): array
$index = new \Elastica\Index($this->client, $realIndexName);
$index->delete();
}
$operations[] = sprintf('%s deleted.', $realIndexName);
$operations[] = \sprintf('%s deleted.', $realIndexName);
} elseif ($livePassed && 1 === $afterLiveCounter) {
// Close
if (false === $dryRun) {
$index = new \Elastica\Index($this->client, $realIndexName);
$index->close();
}
$operations[] = sprintf('%s closed.', $realIndexName);
$operations[] = \sprintf('%s closed.', $realIndexName);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/IndexNameMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct(?string $prefix, array $indexClassMapping)
public function getPrefixedIndex(string $name): string
{
if ($this->prefix) {
return sprintf('%s_%s', $this->prefix, $name);
return \sprintf('%s_%s', $this->prefix, $name);
}

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

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

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

return $this->indexClassMapping[$indexName];
Expand All @@ -63,7 +63,7 @@ public function getClassFromIndexName(string $indexName): string
public function getPureIndexName(string $fullIndexName): string
{
if ($this->prefix) {
$pattern = sprintf('/%s_(.+)_\d{4}-\d{2}-\d{2}-\d+/i', preg_quote($this->prefix, '/'));
$pattern = \sprintf('/%s_(.+)_\d{4}-\d{2}-\d{2}-\d+/i', preg_quote($this->prefix, '/'));
} else {
$pattern = '/(.+)_\d{4}-\d{2}-\d{2}-\d+/i';
}
Expand Down
2 changes: 1 addition & 1 deletion src/Mapping/PhpProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function provideMapping(string $indexName, array $context = []): ?array
$fileName = $context['filename'] ?? ($indexName . '_mapping.php');
$mappingFilePath = $this->configurationDirectory . \DIRECTORY_SEPARATOR . $fileName;
if (!is_file($mappingFilePath)) {
throw new InvalidException(sprintf('Mapping file "%s" not found.', $mappingFilePath));
throw new InvalidException(\sprintf('Mapping file "%s" not found.', $mappingFilePath));
}

$mapping = require $mappingFilePath;
Expand Down
2 changes: 1 addition & 1 deletion src/Mapping/YamlProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function provideMapping(string $indexName, array $context = []): ?array
$fileName = $context['filename'] ?? ($indexName . '_mapping.yaml');
$mappingFilePath = $this->configurationDirectory . \DIRECTORY_SEPARATOR . $fileName;
if (!is_file($mappingFilePath)) {
throw new InvalidException(sprintf('Mapping file "%s" not found. Please check your configuration.', $mappingFilePath));
throw new InvalidException(\sprintf('Mapping file "%s" not found. Please check your configuration.', $mappingFilePath));
}

$mapping = $this->parser->parseFile($mappingFilePath);
Expand Down
2 changes: 1 addition & 1 deletion src/Messenger/IndexationRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final class IndexationRequest implements IndexationRequestInterface
public function __construct(string $className, string $id, string $operation = IndexationRequestHandler::OP_INDEX)
{
if (!\in_array($operation, IndexationRequestHandler::OPERATIONS, true)) {
throw new \InvalidArgumentException(sprintf('Not supported operation "%s" given.', $operation));
throw new \InvalidArgumentException(\sprintf('Not supported operation "%s" given.', $operation));
}

$this->className = $className;
Expand Down
4 changes: 2 additions & 2 deletions tests/Symfony/TestKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ protected function configureRoutes($routes): void
$routes->add('/with_response', TestController::class . '::withResponse', 'with_response');
} else {
$routeConfigurator = $routes->add('with_exception', '/with_exception');
$routeConfigurator->controller(sprintf('%s::withException', TestController::class));
$routeConfigurator->controller(\sprintf('%s::withException', TestController::class));

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