This repository has been archived by the owner on Jun 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c83ceaf
commit d50eebf
Showing
21 changed files
with
683 additions
and
0 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
src/joselfonseca/image-manager/Commands/DeleteFile/DeleteFileCommand.php
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,18 @@ | ||
<?php | ||
|
||
namespace Joselfonseca\ImageManager\Commands\DeleteFile; | ||
|
||
/** | ||
* Description of UploadFileCommand | ||
* | ||
* @author desarrollo | ||
*/ | ||
class DeleteFileCommand { | ||
|
||
public $id; | ||
|
||
public function __construct($id) { | ||
$this->id = $id; | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
src/joselfonseca/image-manager/Commands/DeleteFile/DeleteFileCommandHandler.php
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,24 @@ | ||
<?php | ||
|
||
namespace Joselfonseca\ImageManager\Commands\DeleteFile; | ||
|
||
use Joselfonseca\ImageManager\Interfaces\ImageRepositoryInterface; | ||
|
||
use Laracasts\Commander\CommandHandler; | ||
use Laracasts\Commander\Events\DispatchableTrait; | ||
|
||
class DeleteFileCommandHandler implements CommandHandler{ | ||
|
||
use DispatchableTrait; | ||
|
||
private $imageRepository; | ||
|
||
public function __construct(ImageRepositoryInterface $repository){ | ||
$this->imageRepository = $repository; | ||
} | ||
|
||
public function handle($command) { | ||
return $this->imageRepository->DeleteFile($command); | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
src/joselfonseca/image-manager/Commands/DeleteFile/Events/FileWasRemovedFromDb.php
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,18 @@ | ||
<?php | ||
|
||
|
||
namespace Joselfonseca\ImageManager\Commands\DeleteFile\Events; | ||
|
||
/** | ||
* Description of FileWasSavedToDisc | ||
* | ||
* @author desarrollo | ||
*/ | ||
class FileWasRemovedFromDb { | ||
|
||
public $file; | ||
|
||
public function __construct($file){ | ||
$this->file = $file; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/joselfonseca/image-manager/Commands/DeleteFile/Events/FileWasRemovedFromDisc.php
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,18 @@ | ||
<?php | ||
|
||
|
||
namespace Joselfonseca\ImageManager\Commands\DeleteFile\Events; | ||
|
||
/** | ||
* Description of FileWasSavedToDisc | ||
* | ||
* @author desarrollo | ||
*/ | ||
class FileWasRemovedFromDisc { | ||
|
||
public $file; | ||
|
||
public function __construct($file){ | ||
$this->file = $file; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/joselfonseca/image-manager/Commands/RenderFile/RenderFileCommand.php
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,27 @@ | ||
<?php | ||
|
||
namespace Joselfonseca\ImageManager\Commands\RenderFile; | ||
|
||
/** | ||
* Description of UploadFileCommand | ||
* | ||
* @author desarrollo | ||
*/ | ||
class RenderFileCommand { | ||
|
||
public $id; | ||
|
||
public $width; | ||
|
||
public $height; | ||
|
||
public $canvas; | ||
|
||
public function __construct($id, $width, $height, $canvas = false) { | ||
$this->id = $id; | ||
$this->width = $width; | ||
$this->height = $height; | ||
$this->canvas = $canvas; | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
src/joselfonseca/image-manager/Commands/RenderFile/RenderFileCommandHandler.php
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,24 @@ | ||
<?php | ||
|
||
namespace Joselfonseca\ImageManager\Commands\RenderFile; | ||
|
||
use Joselfonseca\ImageManager\Interfaces\ImageRepositoryInterface; | ||
|
||
use Laracasts\Commander\CommandHandler; | ||
use Laracasts\Commander\Events\DispatchableTrait; | ||
|
||
class RenderFileCommandHandler implements CommandHandler{ | ||
|
||
use DispatchableTrait; | ||
|
||
private $imageRepository; | ||
|
||
public function __construct(ImageRepositoryInterface $repository){ | ||
$this->imageRepository = $repository; | ||
} | ||
|
||
public function handle($command) { | ||
return $this->imageRepository->renderImage($command); | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
src/joselfonseca/image-manager/Commands/UploadFile/Events/FileWasSavedToDb.php
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,20 @@ | ||
<?php | ||
|
||
namespace Joselfonseca\ImageManager\Commands\UploadFile\Events; | ||
|
||
use Joselfonseca\ImageManager\Interfaces\ImageDbStorageInterface; | ||
|
||
/** | ||
* Description of FileWasSavedToDb | ||
* | ||
* @author desarrollo | ||
*/ | ||
class FileWasSavedToDb { | ||
|
||
public $file; | ||
|
||
public function __construct(ImageDbStorageInterface $file){ | ||
$this->file = $file; | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
src/joselfonseca/image-manager/Commands/UploadFile/Events/FileWasSavedToDisc.php
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,18 @@ | ||
<?php | ||
|
||
|
||
namespace Joselfonseca\ImageManager\Commands\UploadFile\Events; | ||
|
||
/** | ||
* Description of FileWasSavedToDisc | ||
* | ||
* @author desarrollo | ||
*/ | ||
class FileWasSavedToDisc { | ||
|
||
public $file; | ||
|
||
public function __construct($file){ | ||
$this->file = $file; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/joselfonseca/image-manager/Commands/UploadFile/UploadFileCommand.php
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,18 @@ | ||
<?php | ||
|
||
namespace Joselfonseca\ImageManager\Commands\UploadFile; | ||
|
||
/** | ||
* Description of UploadFileCommand | ||
* | ||
* @author desarrollo | ||
*/ | ||
class UploadFileCommand { | ||
|
||
public $file; | ||
|
||
public function __construct($file) { | ||
$this->file = $file; | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
src/joselfonseca/image-manager/Commands/UploadFile/UploadFileCommandHandler.php
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,26 @@ | ||
<?php | ||
|
||
namespace Joselfonseca\ImageManager\Commands\UploadFile; | ||
|
||
use Joselfonseca\ImageManager\Interfaces\ImageRepositoryInterface; | ||
|
||
use Laracasts\Commander\CommandHandler; | ||
use Laracasts\Commander\Events\DispatchableTrait; | ||
|
||
class UploadFileCommandHandler implements CommandHandler{ | ||
|
||
use DispatchableTrait; | ||
|
||
private $imageRepository; | ||
|
||
public function __construct(ImageRepositoryInterface $repository){ | ||
$this->imageRepository = $repository; | ||
} | ||
|
||
public function handle($command) { | ||
$file = $this->imageRepository->uploadFile($command); | ||
$this->dispatchEventsFor($file); | ||
return $file; | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
src/joselfonseca/image-manager/Commands/UploadFile/UploadFileValidator.php
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,26 @@ | ||
<?php | ||
|
||
namespace Joselfonseca\ImageManager\Commands\UploadFile; | ||
|
||
use \Illuminate\Support\Facades\Validator; | ||
use Joselfonseca\ImageManager\Exceptions\ValidationExeption; | ||
|
||
/** | ||
* Description of UploadFileValidator | ||
* | ||
* @author desarrollo | ||
*/ | ||
class UploadFileValidator { | ||
|
||
public function validate($command) { | ||
$rules = [ | ||
'file' => "image|required|between:1," . \Config::get('image-manager::maxFileSize') . "" | ||
]; | ||
$validator = Validator::make((array)$command, $rules); | ||
if ($validator->fails()) { | ||
$messages = $validator->messages(); | ||
throw new ValidationExeption('Validation Error', 500, null, $messages); | ||
} | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
src/joselfonseca/image-manager/Exceptions/AlocateFileException.php
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,11 @@ | ||
<?php | ||
namespace Joselfonseca\ImageManager\Exceptions; | ||
|
||
/** | ||
* Description of AlocateFileException | ||
* | ||
* @author desarrollo | ||
*/ | ||
class AlocateFileException { | ||
//put your code here | ||
} |
12 changes: 12 additions & 0 deletions
12
src/joselfonseca/image-manager/Exceptions/ModelNotFoundException.php
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,12 @@ | ||
<?php | ||
|
||
namespace Joselfonseca\ImageManager\Exceptions; | ||
|
||
/** | ||
* Description of ModelNotFoundException | ||
* | ||
* @author desarrollo | ||
*/ | ||
class ModelNotFoundException { | ||
//put your code here | ||
} |
23 changes: 23 additions & 0 deletions
23
src/joselfonseca/image-manager/Exceptions/ValidationExeption.php
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,23 @@ | ||
<?php | ||
|
||
namespace Joselfonseca\ImageManager\Exceptions; | ||
|
||
/** | ||
* Description of ValidationExeption | ||
* | ||
* @author desarrollo | ||
*/ | ||
class ValidationExeption extends \Exception{ | ||
|
||
private $validationErrors; | ||
|
||
public function __construct($message, $code, $previous, $validationErrors) { | ||
parent::__construct($message, $code, $previous); | ||
$this->validationErrors = $validationErrors; | ||
} | ||
|
||
public function getErrors(){ | ||
return $this->validationErrors; | ||
} | ||
|
||
} |
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,56 @@ | ||
<?php | ||
|
||
namespace Joselfonseca\ImageManager; | ||
|
||
use Joselfonseca\ImageManager\Commands\UploadFile\UploadFileCommand; | ||
use Laracasts\Commander\CommanderTrait; | ||
use Joselfonseca\ImageManager\Interfaces\ImageRepositoryInterface; | ||
use Joselfonseca\ImageManager\Commands\RenderFile\RenderFileCommand; | ||
|
||
/** | ||
* Description of ImageManager | ||
* | ||
* @author jfonseca | ||
*/ | ||
class ImageManager { | ||
|
||
use CommanderTrait; | ||
|
||
private $ImageRepository; | ||
|
||
public function __construct(ImageRepositoryInterface $imageRepository) { | ||
$this->ImageRepository = $imageRepository; | ||
} | ||
|
||
public function doUpload() { | ||
return $this->execute(UploadFileCommand::class, ['file' => \Input::file('file')]); | ||
} | ||
|
||
public function resize($id, $width = null, $height = null){ | ||
return $this->execute(RenderFileCommand::class, ['id' => $id, 'width' => $width, 'height' => $height]); | ||
} | ||
|
||
public function imageInfo($id){ | ||
return $this->ImageRepository->getFileModel($id); | ||
} | ||
|
||
public static function getField($params) { | ||
$text = ($params['text']) ? $params['text'] : 'Select File'; | ||
$class = ($params['class']) ? $params['class'] : 'btn btn-default'; | ||
$field_name = (isset($params['field_name'])) ? $params['field_name'] : 'image'; | ||
$default = (isset($params['default'])) ? $params['default'] : \Input::old($params['field_name']);; | ||
if(!empty($default)){ | ||
$image = '<img src="'.action('media', ['id' => $default, 'width' => 300]).'" class="imageManagerImage" />'; | ||
}else{ | ||
$image = '<img src="" style="display:none" class="imageManagerImage" />'; | ||
} | ||
return '<div class="ImageManager">' | ||
. $image .'<br /><br />' | ||
. '<button class="fileManager ' . $class . '" type="Button" data-url="' . action('ImageManager') . '">' . $text . '</button>' | ||
. \Form::hidden($field_name, $default, ['class' => 'inputFile']) | ||
. '</div>'; | ||
} | ||
|
||
|
||
|
||
} |
Oops, something went wrong.