diff --git a/src/Illuminate/Cache/CacheManager.php b/src/Illuminate/Cache/CacheManager.php index 012a7d161425..21fd243c0622 100755 --- a/src/Illuminate/Cache/CacheManager.php +++ b/src/Illuminate/Cache/CacheManager.php @@ -90,6 +90,19 @@ public function resolve($name) $config = Arr::add($config, 'store', $name); + return $this->build($config); + } + + /** + * Build a cache repository with the given configuration. + * + * @param array $config + * @return \Illuminate\Cache\Repository + */ + public function build(array $config) + { + $config = Arr::add($config, 'store', $config['name'] ?? 'ondemand'); + if (isset($this->customCreators[$config['driver']])) { return $this->callCustomCreator($config); } diff --git a/src/Illuminate/Support/Facades/Cache.php b/src/Illuminate/Support/Facades/Cache.php index 70951bf9b579..afa320256632 100755 --- a/src/Illuminate/Support/Facades/Cache.php +++ b/src/Illuminate/Support/Facades/Cache.php @@ -6,6 +6,7 @@ * @method static \Illuminate\Contracts\Cache\Repository store(string|null $name = null) * @method static \Illuminate\Contracts\Cache\Repository driver(string|null $driver = null) * @method static \Illuminate\Contracts\Cache\Repository resolve(string $name) + * @method static \Illuminate\Contracts\Cache\Repository build(array $config) * @method static \Illuminate\Cache\Repository repository(\Illuminate\Contracts\Cache\Store $store, array $config = []) * @method static void refreshEventDispatcher() * @method static string getDefaultDriver() diff --git a/tests/Cache/CacheManagerTest.php b/tests/Cache/CacheManagerTest.php index d4e9d133827e..a557914e3ee2 100644 --- a/tests/Cache/CacheManagerTest.php +++ b/tests/Cache/CacheManagerTest.php @@ -59,6 +59,18 @@ public function testCustomDriverOverridesInternalDrivers() $this->assertSame('mm(u_u)mm', $driver->flag); } + public function testItCanBuildRepositories() + { + $app = $this->getApp([]); + $cacheManager = new CacheManager($app); + + $arrayCache = $cacheManager->build(['driver' => 'array']); + $nullCache = $cacheManager->build(['driver' => 'null']); + + $this->assertInstanceOf(ArrayStore::class, $arrayCache->getStore()); + $this->assertInstanceOf(NullStore::class, $nullCache->getStore()); + } + public function testItMakesRepositoryWhenContainerHasNoDispatcher() { $userConfig = [