Explorar el Código

Moved hardcoded class alias to a namespaced constant

Alejandro Celaya hace 4 años
padre
commit
4539ab2dcf

+ 3 - 3
config/autoload/locks.global.php

@@ -8,7 +8,7 @@ use Shlinkio\Shlink\Common\Lock\RetryLockStoreDelegatorFactory;
 use Shlinkio\Shlink\Common\Logger\LoggerAwareDelegatorFactory;
 use Symfony\Component\Lock;
 
-$localLockFactory = 'Shlinkio\Shlink\LocalLockFactory';
+use const Shlinkio\Shlink\Core\LOCAL_LOCK_FACTORY;
 
 return [
 
@@ -21,7 +21,7 @@ return [
             Lock\Store\FlockStore::class => ConfigAbstractFactory::class,
             Lock\Store\RedisStore::class => ConfigAbstractFactory::class,
             Lock\LockFactory::class => ConfigAbstractFactory::class,
-            $localLockFactory => ConfigAbstractFactory::class,
+            LOCAL_LOCK_FACTORY => ConfigAbstractFactory::class,
         ],
         'aliases' => [
             // With this config, a user could alias 'lock_store' => 'redis_lock_store' to override the default
@@ -44,7 +44,7 @@ return [
         Lock\Store\FlockStore::class => ['config.locks.locks_dir'],
         Lock\Store\RedisStore::class => [RedisFactory::SERVICE_NAME],
         Lock\LockFactory::class => ['lock_store'],
-        $localLockFactory => ['local_lock_store'],
+        LOCAL_LOCK_FACTORY => ['local_lock_store'],
     ],
 
 ];

+ 5 - 2
config/container.php

@@ -5,13 +5,16 @@ declare(strict_types=1);
 use Laminas\ServiceManager\ServiceManager;
 use Symfony\Component\Lock;
 
+use const Shlinkio\Shlink\Core\LOCAL_LOCK_FACTORY;
+
 chdir(dirname(__DIR__));
 
 require 'vendor/autoload.php';
 
 // This class alias tricks the ConfigAbstractFactory to return Lock\Factory instances even with a different service name
-if (! class_exists('Shlinkio\Shlink\LocalLockFactory')) {
-    class_alias(Lock\LockFactory::class, 'Shlinkio\Shlink\LocalLockFactory');
+// It needs to be placed here as individual config files will not be loaded once config is cached
+if (! class_exists(LOCAL_LOCK_FACTORY)) {
+    class_alias(Lock\LockFactory::class, LOCAL_LOCK_FACTORY);
 }
 
 // Build container

+ 3 - 1
module/CLI/config/dependencies.config.php

@@ -19,6 +19,8 @@ use Symfony\Component\Console as SymfonyCli;
 use Symfony\Component\Lock\LockFactory;
 use Symfony\Component\Process\PhpExecutableFinder;
 
+use const Shlinkio\Shlink\Core\LOCAL_LOCK_FACTORY;
+
 return [
 
     'dependencies' => [
@@ -52,7 +54,7 @@ return [
     ],
 
     ConfigAbstractFactory::class => [
-        GeolocationDbUpdater::class => [DbUpdater::class, Reader::class, 'Shlinkio\Shlink\LocalLockFactory'],
+        GeolocationDbUpdater::class => [DbUpdater::class, Reader::class, LOCAL_LOCK_FACTORY],
 
         Command\ShortUrl\GenerateShortUrlCommand::class => [
             Service\UrlShortener::class,

+ 1 - 0
module/Core/functions/functions.php

@@ -12,6 +12,7 @@ use function sprintf;
 
 const DEFAULT_SHORT_CODES_LENGTH = 5;
 const MIN_SHORT_CODES_LENGTH = 4;
+const LOCAL_LOCK_FACTORY = 'Shlinkio\Shlink\LocalLockFactory';
 
 function generateRandomShortCode(int $length): string
 {