Created
January 5, 2014 22:37
-
-
Save andreia/8274989 to your computer and use it in GitHub Desktop.
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
<?php | |
namespace Acme\Component; | |
use OldSound\RabbitMqBundle\RabbitMq\Producer; | |
class UploadImage | |
{ | |
protected $options = array(); | |
protected $generateFolder = null; | |
protected $generateImageProducer = null; | |
/** | |
* Construtor | |
* | |
* @param Producer $generateImageProducer | |
* @param array $options | |
* | |
* @return void | |
*/ | |
public function __construct(Producer $generateImageProducer, array $options) | |
{ | |
$this->options = $options; | |
$this->generateFolder = $options['generate_folder']; | |
$this->generateImageProducer = $generateImageProducer; | |
} | |
/** | |
* Upload da imagem | |
* | |
* @param SplFileInfo $file Arquivo da imagem para fazer o upload | |
* | |
* @return boolean Status do upload | |
*/ | |
public function upload(\SplFileInfo $file) | |
{ | |
// ... | |
// realiza o upload da imagem e outras operações adicionais como salvar no banco de dados | |
// ... | |
// caminho da imagem que foi realizado o upload | |
$imagePath = $file->getRealPath(); | |
// imagem para publicar | |
$imageToGenerate = json_encode(array | |
( | |
'imageToGenerate' => $imagePath, | |
'imageFilename' => $this->generateFolder.$this->generateFilename('jpg'), | |
)); | |
// publica as informações da imagem a ser gerada | |
$this->generateImageProducer->publish($imageToGenerate); | |
return true; | |
} | |
public function generateFilename($ext = 'jpg') | |
{ | |
return sha1(uniqid(mt_rand(), true)).'.'.$ext; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment