mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #9461 from creative-commoners/pulls/4/remove-db-config-glob
Cache results of _configure_database.php glob
This commit is contained in:
commit
e08bf1cdd9
@ -33,3 +33,7 @@ SilverStripe\Core\Injector\Injector:
|
|||||||
factory: SilverStripe\Core\Cache\CacheFactory
|
factory: SilverStripe\Core\Cache\CacheFactory
|
||||||
constructor:
|
constructor:
|
||||||
namespace: 'ThemeResourceLoader'
|
namespace: 'ThemeResourceLoader'
|
||||||
|
Psr\SimpleCache\CacheInterface.DatabaseAdapterRegistry:
|
||||||
|
factory: SilverStripe\Core\Cache\CacheFactory
|
||||||
|
constructor:
|
||||||
|
namespace: 'DatabaseAdapterRegistry'
|
||||||
|
@ -3,7 +3,10 @@
|
|||||||
namespace SilverStripe\Dev\Install;
|
namespace SilverStripe\Dev\Install;
|
||||||
|
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
|
use Psr\SimpleCache\CacheInterface;
|
||||||
|
use SilverStripe\Core\Injector\Injector;
|
||||||
use SilverStripe\Dev\Deprecation;
|
use SilverStripe\Dev\Deprecation;
|
||||||
|
use SilverStripe\Core\Flushable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class keeps track of the available database adapters
|
* This class keeps track of the available database adapters
|
||||||
@ -12,7 +15,7 @@ use SilverStripe\Dev\Deprecation;
|
|||||||
*
|
*
|
||||||
* @author Tom Rix
|
* @author Tom Rix
|
||||||
*/
|
*/
|
||||||
class DatabaseAdapterRegistry
|
class DatabaseAdapterRegistry implements Flushable
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -144,14 +147,48 @@ class DatabaseAdapterRegistry
|
|||||||
} else {
|
} else {
|
||||||
$databaseConfig = $config;
|
$databaseConfig = $config;
|
||||||
}
|
}
|
||||||
// Search through all composer packages in vendor, updating $databaseConfig
|
foreach (static::getConfigureDatabasePaths() as $configureDatabasePath) {
|
||||||
foreach (glob(BASE_PATH . '/vendor/*/*/_configure_database.php') as $configFile) {
|
include_once $configureDatabasePath;
|
||||||
include_once $configFile;
|
|
||||||
}
|
}
|
||||||
// Update modified variable
|
// Update modified variable
|
||||||
$config = $databaseConfig;
|
$config = $databaseConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Including _configure_database.php is a legacy method of configuring a database
|
||||||
|
* It's still used by https://github.com/silverstripe/silverstripe-sqlite3
|
||||||
|
*/
|
||||||
|
protected static function getConfigureDatabasePaths(): array
|
||||||
|
{
|
||||||
|
// autoconfigure() will get called before flush() on ?flush, so manually flush just to ensure no weirdness
|
||||||
|
if (isset($_GET['flush'])) {
|
||||||
|
static::flush();
|
||||||
|
}
|
||||||
|
$cache = static::getCache();
|
||||||
|
$key = __FUNCTION__;
|
||||||
|
if ($cache->has($key)) {
|
||||||
|
return (array) $cache->get($key);
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
$paths = glob(BASE_PATH . '/vendor/*/*/_configure_database.php');
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$paths = [];
|
||||||
|
}
|
||||||
|
$cache->set($key, $paths);
|
||||||
|
return $paths;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getCache(): CacheInterface
|
||||||
|
{
|
||||||
|
return Injector::inst()->get(CacheInterface::class . '.DatabaseAdapterRegistry');
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function flush()
|
||||||
|
{
|
||||||
|
static::getCache()->clear();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return all registered adapters
|
* Return all registered adapters
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user