Skip to content
This repository has been archived by the owner on Jun 11, 2019. It is now read-only.

Commit

Permalink
Really
Browse files Browse the repository at this point in the history
  • Loading branch information
joselfonseca committed Mar 18, 2015
1 parent c83ceaf commit d50eebf
Show file tree
Hide file tree
Showing 21 changed files with 683 additions and 0 deletions.
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;
}

}
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);
}

}
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;
}
}
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;
}
}
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;
}

}
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);
}

}
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;
}

}
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;
}
}
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;
}

}
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;
}

}
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 src/joselfonseca/image-manager/Exceptions/AlocateFileException.php
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
}
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 src/joselfonseca/image-manager/Exceptions/ValidationExeption.php
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;
}

}
56 changes: 56 additions & 0 deletions src/joselfonseca/image-manager/ImageManager.php
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>';
}



}
Loading

0 comments on commit d50eebf

Please sign in to comment.