Skip to content

Commit

Permalink
Merge d63d5e9 into 6cff37b
Browse files Browse the repository at this point in the history
  • Loading branch information
Westin Shafer committed Sep 14, 2017
2 parents 6cff37b + d63d5e9 commit dbba1ea
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 157 deletions.
113 changes: 57 additions & 56 deletions README.md
Expand Up @@ -480,7 +480,7 @@ return [
'adaptors' => [
// Array Keys are the names used for the adaptor
'default' => [
'type' => 'local', #A daptor name or pre-configured service from the container
'type' => 'local', # Adaptor name or pre-configured service from the container

// Adaptor specific options. See adaptors below
'options' => [
Expand Down Expand Up @@ -516,7 +516,7 @@ return [

'adaptorTwo' => [
'type' => 'null', // Adaptor name or pre-configured service from the container
'options' => [], // Adaptor specific options. See adaptors below
'options' => [], // Adaptor specific options. See adaptors below
],
],

Expand All @@ -535,7 +535,7 @@ return [
],
],

'cache_two' => [
'cacheTwo' => [
'type' => 'psr6',
// Cache specific options. See caches below
'options' => [
Expand All @@ -554,8 +554,8 @@ return [
// default file system
'default' => [
'adaptor' => 'default', // Adaptor name from adaptor configuration
'cache' => 'default', // Cache name from adaptor configuration
'plugins' => [] // User defined plugins to be injected into the file system
'cache' => 'default', // Cache name from adaptor configuration
'plugins' => [] // User defined plugins to be injected into the file system
],

// Mount Manager Config
Expand All @@ -564,14 +564,14 @@ return [
'fileSystems' => [
'local' => [
'adaptor' => 'default', // Adaptor name from adaptor configuration
'cache' => 'cache_one', // PSR-6 pre-configured service
'plugins' => [] // User defined plugins to be injected into the file system
'cache' => 'default', // PSR-6 pre-configured service
'plugins' => [] // User defined plugins to be injected into the file system
],

'anotherFileSystem' => [
'adaptor' => 'adaptor_two', // Adaptor name from adaptor configuration
'cache' => 'cache_two', // PSR-6 pre-configured service
'plugins' => [] // User defined plugins to be injected into the file system
'adaptor' => 'adaptorTwo', // Adaptor name from adaptor configuration
'cache' => 'cacheTwo', // PSR-6 pre-configured service
'plugins' => [] // User defined plugins to be injected into the file system
],
],
],
Expand All @@ -590,9 +590,9 @@ return [
'fileSystems' => [
// Array Keys are the file systems identifiers
'myFileSystemName' => [
'adaptor' => 'default', // Adaptor name from adaptor configuration
'cache' => 'default', // Cache name from adaptor configuration
'plugins' => [] // User defined plugins to be injected into the file system
'adaptor' => 'default', // Required : Adaptor name from adaptor configuration
'cache' => 'default', // Optional : Cache name from adaptor configuration
'plugins' => [] // Optional : User defined plugins to be injected into the file system
],
],
],
Expand Down Expand Up @@ -631,9 +631,11 @@ return [
'default' => [
'type' => 'local',
'options' => [
'root' => '/path/to/root', // Path on local filesystem
'writeFlags' => LOCK_EX, // PHP flags. See: file_get_contents for more info
'linkBehavior' => League\Flysystem\Adapter\Local::DISALLOW_LINKS, #Link behavior
'root' => '/path/to/root', // Required : Path on local filesystem
'writeFlags' => LOCK_EX, // Optional : PHP flags. See: file_get_contents for more info
'linkBehavior' => League\Flysystem\Adapter\Local::DISALLOW_LINKS, // Optional : Link behavior

// Optional: Optional set of permissions to set for files
'permissions' => [
'file' => [
'public' => 0644,
Expand Down Expand Up @@ -664,11 +666,11 @@ return [
'default' => [
'type' => 'ftp',
'options' => [
'host' => 'ftp.example.com',
'username' => 'username',
'password' => 'password',
'host' => 'ftp.example.com', // Required : Host
'username' => 'username', // Required : Username
'password' => 'password', // Required : Password

/** optional config settings */
// optional config settings
'port' => 21,
'root' => '/path/to/root',
'passive' => true,
Expand Down Expand Up @@ -697,15 +699,15 @@ return [
'flysystem' => [
'adaptors' => [
'default' => [
'type' => 'ftp',
'type' => 'sftp',
'options' => [
'host' => 'example.com',
'port' => 21,
'username' => 'username',
'password' => 'password',
'privateKey' => 'path/to/or/contents/of/privatekey',
'root' => '/path/to/root',
'timeout' => 10,
'host' => 'example.com', // Required : Host
'port' => 21, // Optional : Port
'username' => 'username', // Optional : Username
'password' => 'password', // Optional : Password
'privateKey' => 'path/to/or/contents/of/privatekey', // Optional : Host
'root' => '/path/to/root', // Required : Root Path
'timeout' => 10, // Optional : Timeout
],
],
],
Expand All @@ -731,7 +733,7 @@ return [
'adaptors' => [
'default' => [
'type' => 'memory',
'options' => [],
'options' => [], // No options available
],
],
],
Expand All @@ -757,7 +759,7 @@ return [
'default' => [
'type' => 'zip',
'options' => [
'path' => '/some/path/to/file.zip'
'path' => '/some/path/to/file.zip' // Required : File name and path to use for zip file
],
],
],
Expand All @@ -784,10 +786,10 @@ return [
'default' => [
'type' => 'azure',
'options' => [
'accountName' => 'account-name',
'apiKey' => 'api-key',
'container' => 'container-name',
'prefix' => 'prefix_', // Optional
'accountName' => 'account-name', // Required : Account Name
'apiKey' => 'api-key', // Required : API Key
'container' => 'container-name', // Required : Container name
'prefix' => 'prefix_', // Optional
],
],
],
Expand All @@ -814,12 +816,12 @@ return [
'default' => [
'type' => 's3',
'options' => [
'key' => 'aws-key',
'secret' => 'aws-secret',
'region' => 'us-east-1',
'bucket' => 'bucket-name',
'prefix' => 'some/prefix', #optional
'version' => 'latest' // Default: 'latest'
'key' => 'aws-key', // Required : Key
'secret' => 'aws-secret', // Required : Secret
'region' => 'us-east-1', // Required : Region
'bucket' => 'bucket-name', // Required : Bucket Name
'prefix' => 'some/prefix', // Optional : Prefix
'version' => 'latest' // Optional : Api Version. Default: 'latest'
],
],
],
Expand All @@ -845,8 +847,8 @@ return [
'default' => [
'type' => 'dropbox',
'options' => [
'token' => 'my-token',
'prefix' => 'prefix', #optional
'token' => 'my-token', // Required : API Token
'prefix' => 'prefix', // Optional : Prefix
],
],
],
Expand All @@ -868,7 +870,7 @@ return [
'caches' => [
'default' => [
'type' => 'memory',
'options' => [], #No options available
'options' => [], // No options available
],
],
],
Expand All @@ -890,10 +892,9 @@ return [
'default' => [
'type' => 'adaptor',
'options' => [
'managerServiceName' => \WShafer\PSR11FlySystem\FlySystemManager::class, // Optional. Only needed if you change the service name of the Fly Manager
'fileSystem' => 'MyFileSystemName', // Filesystem name found in the FileSystems config
'fileName' => 'my_cache_file', // File name for cache file
'ttl' => 300
'adaptor' => 'MyAdaptorName', // Required : Adaptor name found in the adaptor config
'fileName' => 'my_cache_file', // Required : File name for cache file
'ttl' => 300 // Optional : Time to live
],
],
],
Expand All @@ -913,9 +914,9 @@ return [
'default' => [
'type' => 'psr6',
'options' => [
'service' => 'my_psr6_service_from_container', // Service to be used from the container
'key' => 'my_key_', // Cache Key
'ttl' => 3000 // Expires
'service' => 'my_psr6_service_from_container', // Required : Service to be used from the container
'key' => 'my_key_', // Required : Cache Key
'ttl' => 3000 // Optional : Time to live
],
],
],
Expand All @@ -935,9 +936,9 @@ return [
'default' => [
'type' => 'predis',
'options' => [
'service' => 'my_predis_client_from_container', // Configured Predis Client Service to pull from container
'key' => 'my_key_', // Cache Key
'ttl' => 3000 // Expires
'service' => 'my_predis_client_from_container', // Required : Configured Predis Client Service to pull from container
'key' => 'my_key_', // Required : Cache Key
'ttl' => 3000 // Optional : Time to live
],
],
],
Expand All @@ -957,9 +958,9 @@ return [
'default' => [
'type' => 'memcached',
'options' => [
'service' => 'my_memcached_client_from_container', // Configured Memcached Client Service to pull from container
'key' => 'my_key_', // Cache Key
'ttl' => 3000 // Expires
'service' => 'my_memcached_client_from_container', // Required : Configured Memcached Client Service to pull from container
'key' => 'my_key_', // Required : Cache Key
'ttl' => 3000 // Optional : Time to live
],
],
],
Expand Down
16 changes: 8 additions & 8 deletions src/Cache/AdaptorCacheFactory.php
Expand Up @@ -6,33 +6,33 @@
use League\Flysystem\Cached\Storage\Adapter;
use WShafer\PSR11FlySystem\Exception\MissingConfigException;
use WShafer\PSR11FlySystem\Exception\MissingServiceException;
use WShafer\PSR11FlySystem\FlySystemFactory;
use WShafer\PSR11FlySystem\FlySystemManager;

class AdaptorCacheFactory extends ContainerAwareCacheAbstract
{
public function __invoke(array $options)
{
$managerServiceName = $options['managerServiceName'] ?? FlySystemManager::class;

if (empty($options['fileSystem'])) {
if (empty($options['adaptor'])) {
throw new MissingConfigException(
'Unable to locate cache file adaptor in config'
);
}

$fileSystem = $options['fileSystem'];
$adaptor = $options['adaptor'];
$fileName = $options['fileName'] ?? 'file_cache';
$ttl = $options['ttl'] ?? null;

/** @var FlySystemManager $manager */
$manager = $this->getService($managerServiceName);
$manager = FlySystemFactory::getFlySystemManager($this->getContainer());
$adaptorManager = $manager->getAdaptorManager();

if (!$manager->has($fileSystem)) {
if (!$adaptorManager->has($adaptor)) {
throw new MissingServiceException(
'Unable to locate file system: '.$fileSystem
'Unable to locate file system: '.$adaptor
);
}

return new Adapter($manager->get($fileSystem), $fileName, $ttl);
return new Adapter($adaptorManager->get($adaptor), $fileName, $ttl);
}
}
20 changes: 20 additions & 0 deletions src/FlySystemManager.php
Expand Up @@ -138,4 +138,24 @@ public function has($id)
{
return $this->config->hasFileSystemConfig($id);
}

/**
* Get the Adaptor manager
*
* @return ContainerInterface
*/
public function getAdaptorManager()
{
return $this->adaptorManager;
}

/**
* Get the Cache Manager
*
* @return mixed
*/
public function getCacheManager()
{
return $this->cacheManager;
}
}

0 comments on commit dbba1ea

Please sign in to comment.