public static function createFilesystemManager(ContainerInterface $container) : FilesystemManager
 {
     $manager = new FilesystemManager($container->get(ConfigManager::class));
     if ($container->has(CacheManagerContract::class)) {
         $manager->setCacheManager($container->get(CacheManagerContract::class));
     }
     return $manager;
 }
Example #2
0
 /**
  * Create a connector instance based on the configuration.
  *
  * @param array $config
  *
  * @throws \InvalidArgumentException
  *
  * @return \League\Flysystem\Cached\CacheInterface
  */
 protected function createConnector(array $config) : CacheInterface
 {
     $cacheConfig = $config['cache'];
     if (($cache = $this->cacheManager) !== null) {
         if ($cache->hasDriver($cacheConfig['driver'])) {
             return new Psr6Cache($cache->driver($cacheConfig['driver']), $cacheConfig['key'], $cacheConfig['expire']);
         }
     }
     if ($this->manager->hasConnection($cacheConfig['driver'])) {
         return new Adapter($this->manager->createConnection($config), $cacheConfig['key'], $cacheConfig['expire']);
     }
     throw new InvalidArgumentException(sprintf('Unsupported driver [%s].', $cacheConfig['driver']));
 }
 public function testCachedAdapter()
 {
     $config = $this->mock(ConfigManger::class);
     $config->shouldReceive('get')->once()->with('filesystem.connections', [])->andReturn(['local' => ['path' => __DIR__, 'cache' => 'local']]);
     $config->shouldReceive('get')->once()->with('filesystem.cached')->andReturn(['local' => ['driver' => 'local', 'key' => 'test', 'expire' => 6000]]);
     $manager = new FilesystemManager($config);
     $this->assertInstanceOf(FilesystemAdapter::class, $manager->connection('local'));
 }