This repository has been archived by the owner on Mar 1, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes #316 | cs fixes | bug fixes | added copy and move dir functions
- Loading branch information
Showing
25 changed files
with
580 additions
and
228 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
declare(strict_types=1); | ||
namespace Viserio\Contracts\Cache; | ||
|
||
interface Manager | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
declare(strict_types=1); | ||
namespace Viserio\Contracts\Cache\Traits; | ||
|
||
use RuntimeException; | ||
use Viserio\Contracts\Cache\Manager; | ||
|
||
trait CacheAwareTrait | ||
{ | ||
/** | ||
* Cache Manager instance. | ||
* | ||
* @var \Viserio\Contracts\Cache\Manager|null | ||
*/ | ||
protected $cache; | ||
|
||
/** | ||
* Set a Cache Manager. | ||
* | ||
* @param \Viserio\Contracts\Cache\Manager $cache | ||
* | ||
* @return $this | ||
*/ | ||
public function setCacheManager(Manager $cache) | ||
{ | ||
$this->cache = $cache; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Get the Cache Manager. | ||
* | ||
* @throws \RuntimeException | ||
* | ||
* @return \Viserio\Contracts\Cache\Manager | ||
*/ | ||
public function getCacheManager(): Manager | ||
{ | ||
if (! $this->cache) { | ||
throw new RuntimeException('Cache Manager is not set up.'); | ||
} | ||
|
||
return $this->cache; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
declare(strict_types=1); | ||
namespace Viserio\Filesystem\Cache; | ||
|
||
use InvalidArgumentException; | ||
use League\Flysystem\Cached\CacheInterface; | ||
use League\Flysystem\Cached\Storage\Adapter; | ||
use League\Flysystem\Cached\Storage\Psr6Cache; | ||
use Viserio\Contracts\Cache\Manager as CacheManagerContract; | ||
use Viserio\Filesystem\FilesystemManager; | ||
|
||
class CachedFactory | ||
{ | ||
/** | ||
* Instance of FilesystemManager. | ||
* | ||
* @var \Viserio\Filesystem\FilesystemManager | ||
*/ | ||
protected $manager; | ||
|
||
/** | ||
* Instance of CacheManager. | ||
* | ||
* @var \Viserio\Contracts\Cache\Manager | ||
*/ | ||
protected $cacheManager; | ||
|
||
/** | ||
* Create a new cached factory instance. | ||
* | ||
* @param \Viserio\Filesystem\FilesystemManager $manager | ||
*/ | ||
public function __construct(FilesystemManager $manager, CacheManagerContract $cacheManager = null) | ||
{ | ||
$this->manager = $manager; | ||
$this->cacheManager = $cacheManager; | ||
} | ||
|
||
/** | ||
* Establish a cache connection. | ||
* | ||
* @param array $config | ||
* | ||
* @throws \InvalidArgumentException | ||
* | ||
* @return \League\Flysystem\Cached\CacheInterface | ||
*/ | ||
public function connection(array $config): CacheInterface | ||
{ | ||
if (! isset($config['cache'], $config['cache']['driver'])) { | ||
throw new InvalidArgumentException('A driver must be specified.'); | ||
} | ||
|
||
return $this->createConnector($config); | ||
} | ||
|
||
/** | ||
* 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'])); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.