Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/Uploadify/AbstractDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ protected function getSourceType($source)
protected function setFileInfo()
{
switch ($this->sourceType) {
case 'path': case 'url':
case 'path':
case 'url':
$this->setBasename(pathinfo($this->source, PATHINFO_FILENAME));
$this->setExtension(pathinfo($this->source, PATHINFO_EXTENSION));
break;
Expand Down Expand Up @@ -239,7 +240,7 @@ public function delete()
*/
public function getName()
{
return $this->basename.'.'.$this->extension;
return $this->basename . '.' . $this->extension;
}

/**
Expand All @@ -251,7 +252,7 @@ protected function uploadFromPath()
{
$path = $this->storage->disk($this->getDisk())->getDriver()->getAdapter()->getPathPrefix();

return copy($this->source, $path.DIRECTORY_SEPARATOR.$this->getPath().DIRECTORY_SEPARATOR.$this->getName());
return copy($this->source, $path . DIRECTORY_SEPARATOR . $this->getPath() . DIRECTORY_SEPARATOR . $this->getName());
}

/**
Expand All @@ -263,7 +264,7 @@ protected function uploadFromUrl()
{
$contents = file_get_contents($this->source);

return $this->storage->disk($this->getDisk())->put($this->getPath().DIRECTORY_SEPARATOR.$this->getName(), $contents);
return $this->storage->disk($this->getDisk())->put($this->getPath() . DIRECTORY_SEPARATOR . $this->getName(), $contents);
}

/**
Expand All @@ -289,13 +290,13 @@ protected function rename()
$name = $this->getName();

$i = 1;
while ($this->storage->disk($this->getDisk())->exists($this->getPath().DIRECTORY_SEPARATOR.$name)) {
$name = $this->basename.'-'.$i.'.'.$this->extension;
while ($this->storage->disk($this->getDisk())->exists($this->getPath() . DIRECTORY_SEPARATOR . $name)) {
$name = $this->basename . '-' . $i . '.' . $this->extension;

$i++;
}

$this->setBasename(rtrim($name, '.'.$this->extension));
$this->setBasename(rtrim($name, '.' . $this->extension));
$this->setModelInfo();

return $name;
Expand Down
108 changes: 8 additions & 100 deletions src/Uploadify/Casts/Cast.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,169 +8,77 @@

abstract class Cast
{
/**
* The full file name with extension
*
* @var string
*/
protected $name;

/**
* The path to file
*
* @var string
*/
protected $path;

/**
* The filesystems disk name
*
* @var string
*/
protected $disk;

/**
* Create new cast instance
*
* @param string $name The full file name with extension
* @param array $settings List of settings => path, path_thumb, disk...
* @return void
*/
protected $name; // Nome completo do arquivo
protected $path; // Caminho para o arquivo
protected $disk; // Nome do disco do sistema de arquivos

public function __construct($name, array $settings = [])
{
$this->name = $name;
$this->saveSettings($settings);
}

/**
* Save setting values from array
*
* @param array $settings
* @return void
*/
protected function saveSettings(array $settings = [])
{
$this->setPath(Arr::has($settings, 'path') ? $settings['path'] : '');
$this->setDisk(Arr::has($settings, 'disk') ? $settings['disk'] : null);
$this->setPath(Arr::get($settings, 'path', ''));
$this->setDisk(Arr::get($settings, 'disk', null));
}

/**
* Set path value
*
* @param string $path
* @return void
*/
protected function setPath($path)
{
$this->path = trim($path, '/');
}

/**
* Set disk value
*
* @param string $disk
* @return void
*/
protected function setDisk($disk = null)
{
$this->disk = $disk ?: Config::get('uploadify.disk');
}

/**
* Get file name with extension
*
* @return string
*/
public function name()
{
return $this->name;
}

/**
* Get file base name without extension
*
* @return string
*/
public function basename()
{
return pathinfo($this->name(), PATHINFO_FILENAME);
}

/**
* Get file extension
*
* @return string
*/
public function extension()
{
return pathinfo($this->name(), PATHINFO_EXTENSION);
}

/**
* Get file size in bytes
*
* @return string
*/
public function filesize()
{
return $this->getStorage()->size($this->path().DIRECTORY_SEPARATOR.$this->name());
return $this->getStorage()->size($this->path() . '/' . $this->name());
}

/**
* Get path
*
* @return string
*/
public function path()
{
return $this->path;
}

/**
* Delete file from filesystem
*
* @return bool
*/
public function delete()
{
return $this->getStorage()->delete($this->path().DIRECTORY_SEPARATOR.$this->name());
return $this->getStorage()->delete($this->path() . '/' . $this->name());
}

/**
* Get filesystem disk name
*
* @return string
*/
public function disk()
{
return $this->getDisk();
}

/**
* Get filesystems storage
*
* @return \Illuminate\Contracts\Filesystem\Filesystem
*/
protected function getStorage()
{
return Storage::disk($this->getDisk());
}

/**
* Get filesystem disk name
*
* @return string
*/
protected function getDisk()
{
return $this->disk;
}

/**
* Get file name with extension
*
* @return string
*/
public function __toString()
{
return $this->name();
Expand Down
11 changes: 2 additions & 9 deletions src/Uploadify/Casts/FileCast.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,10 @@

namespace Uploadify\Casts;

use Uploadify\Casts\Cast as BaseCast;

class FileCast extends BaseCast
class FileCast extends Cast
{
/**
* Get full url to file
*
* @return string
*/
public function url()
{
return $this->getStorage()->url($this->path().'/'.$this->name());
return $this->getStorage()->url($this->path() . '/' . $this->name());
}
}
26 changes: 5 additions & 21 deletions src/Uploadify/Casts/ImageCast.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,8 @@

namespace Uploadify\Casts;

use Uploadify\Casts\Cast as BaseCast;

class ImageCast extends BaseCast
class ImageCast extends Cast
{
/**
* Get full url to file
*
* @param int|array $width
* @param int $height
* @param array $options
* @return string
*/
public function url($width = null, $height = null, array $options = [])
{
if (is_array($width)) {
Expand All @@ -26,30 +16,24 @@ public function url($width = null, $height = null, array $options = [])
$options = array_merge(['w' => $width], $options);
}

if (! empty($options)) {
return $this->getStorage()->url($this->path().'/'.$this->prepareOptions($options).'/'.$this->name());
if (!empty($options)) {
return $this->getStorage()->url($this->path() . '/' . $this->prepareOptions($options) . '/' . $this->name());
}

return $this->getStorage()->url($this->path().'/'.$this->name());
return $this->getStorage()->url($this->path() . '/' . $this->name());
}

/**
* Prepare and convert options from array to string
*
* @param array $options
*/
protected function prepareOptions(array $options = [])
{
$string = implode(',', array_map(
function ($value, $key) {
return $key.'_'.$value;
return $key . '_' . $value;
},
$options,
array_keys($options)
));

$from = ['width', 'height'];

$to = ['w', 'h'];

return str_replace($from, $to, $string);
Expand Down
10 changes: 5 additions & 5 deletions src/Uploadify/Http/Controllers/ImageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ public function show($path, $options, $name, $extension = null)
{
$originalPath = $this->getPath($path);

$imagePath = $originalPath.'/'.$name.($extension ? '.'.$extension : '');
$imageSmallPath = $originalPath.'/'.$this->config->get('uploadify.path').'/'.$this->slugifyName($name.','.$options).'.'.($extension ?: '');
$imagePath = $originalPath . '/' . $name . ($extension ? '.' . $extension : '');
$imageSmallPath = $originalPath . '/' . $this->config->get('uploadify.path') . '/' . $this->slugifyName($name . ',' . $options) . '.' . ($extension ?: '');

if ($this->exists($imagePath, $imageSmallPath)) {
$image = $this->getDisk()->get($imageSmallPath);
Expand All @@ -98,7 +98,7 @@ public function show($path, $options, $name, $extension = null)

try {
$imageNew = $this->imageManager->make($this->getDisk()->get($imagePath));
} catch (FileNotFoundException $e) {
} catch (FileNotFoundException $e) {
$imageNew = null;

abort(404);
Expand All @@ -112,7 +112,7 @@ public function show($path, $options, $name, $extension = null)

if ($this->config->get('uploadify.cache')) {
try {
$imageNew->save($this->getDisk()->getDriver()->getAdapter()->getPathPrefix().$imageSmallPath, 85);
$imageNew->save($this->getDisk()->getDriver()->getAdapter()->getPathPrefix() . $imageSmallPath, 85);
} catch (NotWritableException $e) {
$context = [
'file' => $e->getFile(),
Expand Down Expand Up @@ -227,7 +227,7 @@ protected function processImage(Image $image, $options)
}

if (Arr::has($options, 'effect')) {
switch($options['effect']) {
switch ($options['effect']) {
case 'greyscale':
$image->greyscale();
break;
Expand Down
5 changes: 3 additions & 2 deletions src/Uploadify/Providers/UploadifyServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class UploadifyServiceProvider extends ServiceProvider
public function boot()
{
$this->publishes([
__DIR__.'/../../config/uploadify.php' => config_path('uploadify.php'),
__DIR__ . '/../../config/uploadify.php' => config_path('uploadify.php'),
], 'uploadify');
}

Expand All @@ -30,7 +30,8 @@ public function boot()
public function register()
{
$this->mergeConfigFrom(
__DIR__.'/../../config/uploadify.php', 'uploadify'
__DIR__ . '/../../config/uploadify.php',
'uploadify'
);

$this->app->singleton(UploadifyManager::class, function ($app) {
Expand Down
Loading