Skip to content

Commit

Permalink
Merge pull request #7040 from barryvdh/patch-4
Browse files Browse the repository at this point in the history
[5.0] Add extend functionality to FilesystemManager
  • Loading branch information
taylorotwell committed Jan 19, 2015
2 parents 73f0681 + af72286 commit 32fbe9a
Showing 1 changed file with 51 additions and 2 deletions.
53 changes: 51 additions & 2 deletions src/Illuminate/Filesystem/FilesystemManager.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php namespace Illuminate\Filesystem;

use Closure;
use Aws\S3\S3Client;
use OpenCloud\Rackspace;
use League\Flysystem\FilesystemInterface;
Expand All @@ -24,6 +25,13 @@ class FilesystemManager implements FactoryContract {
* @var array
*/
protected $disks = [];

/**
* The registered custom driver creators.
*
* @var array
*/
protected $customCreators = [];

/**
* Create a new filesystem manager instance.
Expand Down Expand Up @@ -69,8 +77,35 @@ protected function get($name)
protected function resolve($name)
{
$config = $this->getConfig($name);

return $this->{"create".ucfirst($config['driver'])."Driver"}($config);

if (isset($this->customCreators[$config['driver']]))
{
return $this->callCustomCreator($config);
}
else
{
return $this->{"create".ucfirst($config['driver'])."Driver"}($config);
}
}

/**
* Call a custom driver creator.
*
* @param array $config
* @return \Illuminate\Contracts\Filesystem\Filesystem
*/
protected function callCustomCreator(array $config)
{
$driver = $this->customCreators[$config['driver']]($this->app, $config);

if ($driver instanceof FilesystemInterface)
{
return $this->adapt($driver);
}
else
{
return $driver;
}
}

/**
Expand Down Expand Up @@ -161,5 +196,19 @@ public function getDefaultDriver()
{
return $this->app['config']['filesystems.default'];
}

/**
* Register a custom driver creator Closure.
*
* @param string $driver
* @param \Closure $callback
* @return $this
*/
public function extend($driver, Closure $callback)
{
$this->customCreators[$driver] = $callback;

return $this;
}

}

0 comments on commit 32fbe9a

Please sign in to comment.