Skip to content

Commit

Permalink
allow array of options on filesystem operations
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Nov 29, 2016
1 parent dec2512 commit 481f760
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 29 deletions.
30 changes: 14 additions & 16 deletions src/Illuminate/Filesystem/FilesystemAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,25 +70,23 @@ public function get($path)
*
* @param string $path
* @param string|resource $contents
* @param string $visibility
* @param array $options
* @return bool
*/
public function put($path, $contents, $visibility = null)
public function put($path, $contents, $options = [])
{
if ($contents instanceof File || $contents instanceof UploadedFile) {
return $this->putFile($path, $contents, $visibility);
if (is_string($options)) {
$options = ['visibility' => $options];
}

if ($visibility = $this->parseVisibility($visibility)) {
$config = ['visibility' => $visibility];
} else {
$config = [];
if ($contents instanceof File || $contents instanceof UploadedFile) {
return $this->putFile($path, $contents, $options);
}

if (is_resource($contents)) {
return $this->driver->putStream($path, $contents, $config);
return $this->driver->putStream($path, $contents, $options);
} else {
return $this->driver->put($path, $contents, $config);
return $this->driver->put($path, $contents, $options);
}
}

Expand All @@ -97,12 +95,12 @@ public function put($path, $contents, $visibility = null)
*
* @param string $path
* @param \Illuminate\Http\UploadedFile $file
* @param string $visibility
* @param array $options
* @return string|false
*/
public function putFile($path, $file, $visibility = null)
public function putFile($path, $file, $options = [])
{
return $this->putFileAs($path, $file, $file->hashName(), $visibility);
return $this->putFileAs($path, $file, $file->hashName(), $options);
}

/**
Expand All @@ -111,14 +109,14 @@ public function putFile($path, $file, $visibility = null)
* @param string $path
* @param \Illuminate\Http\File|\Illuminate\Http\UploadedFile $file
* @param string $name
* @param string $visibility
* @param array $options
* @return string|false
*/
public function putFileAs($path, $file, $name, $visibility = null)
public function putFileAs($path, $file, $name, $options = [])
{
$stream = fopen($file->getRealPath(), 'r+');

$result = $this->put($path = trim($path.'/'.$name, '/'), $stream, $visibility);
$result = $this->put($path = trim($path.'/'.$name, '/'), $stream, $options);

if (is_resource($stream)) {
fclose($stream);
Expand Down
44 changes: 31 additions & 13 deletions src/Illuminate/Http/UploadedFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Illuminate\Http;

use Illuminate\Support\Arr;
use Illuminate\Container\Container;
use Illuminate\Support\Traits\Macroable;
use Illuminate\Contracts\Filesystem\Factory as FilesystemFactory;
Expand All @@ -15,53 +16,70 @@ class UploadedFile extends SymfonyUploadedFile
* Store the uploaded file on a filesystem disk.
*
* @param string $path
* @param string|null $disk
* @param array $options
* @return string|false
*/
public function store($path, $disk = null)
public function store($path, $options = [])
{
return $this->storeAs($path, $this->hashName(), $disk);
if (is_string($options)) {
$options = ['disk' => $options];
}

return $this->storeAs($path, $this->hashName(), $options);
}

/**
* Store the uploaded file on a filesystem disk with public visibility.
*
* @param string $path
* @param string|null $disk
* @param array $options
* @return string|false
*/
public function storePublicly($path, $disk = null)
public function storePublicly($path, $options = [])
{
return $this->storeAs($path, $this->hashName(), $disk, 'public');
if (is_string($options)) {
$options = ['disk' => $options];
}

$options['visibility'] = 'public';

return $this->storeAs($path, $this->hashName(), $options);
}

/**
* Store the uploaded file on a filesystem disk with public visibility.
*
* @param string $path
* @param string $name
* @param string|null $disk
* @param array $options
* @return string|false
*/
public function storePubliclyAs($path, $name, $disk = null)
public function storePubliclyAs($path, $name, $options = [])
{
return $this->storeAs($path, $name, $disk, 'public');
if (is_string($options)) {
$options = ['disk' => $options];
}

$options['visibility'] = 'public';

return $this->storeAs($path, $name, $options);
}

/**
* Store the uploaded file on a filesystem disk.
*
* @param string $path
* @param string $name
* @param string|null $disk
* @param string|null $visibility
* @param array $options
* @return string|false
*/
public function storeAs($path, $name, $disk = null, $visibility = null)
public function storeAs($path, $name, $options = [])
{
$factory = Container::getInstance()->make(FilesystemFactory::class);

return $factory->disk($disk)->putFileAs($path, $this, $name, $visibility);
$disk = Arr::pull($options, 'disk');

return $factory->disk($disk)->putFileAs($path, $this, $name, $options);
}

/**
Expand Down

0 comments on commit 481f760

Please sign in to comment.