public function createImageForTag(UploadFileDTO $uploadFileDTO, UuidInterface $tagId) { $managedFile = $this->fileManager->saveFile($uploadFileDTO->getFilePath()); $image = new Image(); $image->setPath($managedFile->getUri()); $image->setWidth($managedFile->getWidth()); $image->setHeight($managedFile->getHeight()); $tag = $this->tagRepository->findOneById($tagId); $tag->addImage($image); $this->create($image); }
public function testCreate() { $origName = '42-348301152.jpg'; $mimeType = 'image/jpeg'; $filePath = '/tmp/phpupuP2I'; $size = 236390; $uploadFile = new UploadFileDTO($origName, $mimeType, $filePath, $size); $this->assertSame($origName, $uploadFile->getOrigName()); $this->assertSame($mimeType, $uploadFile->getMimeType()); $this->assertSame($filePath, $uploadFile->getFilePath()); $this->assertSame($size, $uploadFile->getSize()); }
public function post(Request $request) { $orderItemId = $request->input('orderItemId'); $orderItem = $this->getOrderItemWithAllData($orderItemId); $image = Arr::get($_FILES, 'image'); $uploadFileDTO = new UploadFileDTO(Arr::get($image, 'name'), Arr::get($image, 'type'), Arr::get($image, 'tmp_name'), Arr::get($image, 'size')); if (!is_uploaded_file($uploadFileDTO->getFilePath())) { abort(400); } try { $this->dispatch(new CreateAttachmentForOrderItemCommand($uploadFileDTO, $orderItem->id->getHex())); $this->flashSuccess('Attachment uploaded.'); } catch (KommerceException $e) { $this->flashError('Unable to upload attachment.'); } return redirect()->route('admin.order.view', ['orderId' => $orderItem->order->id->getHex()]); }
public function post(Request $request) { $productId = $request->input('productId'); $product = $this->getProductWithAllData($productId); $image = Arr::get($_FILES, 'image'); $uploadFileDTO = new UploadFileDTO(Arr::get($image, 'name'), Arr::get($image, 'type'), Arr::get($image, 'tmp_name'), Arr::get($image, 'size')); if (!is_uploaded_file($uploadFileDTO->getFilePath())) { abort(400); } try { $this->dispatch(new CreateImageForProductCommand($uploadFileDTO, $product->id->getHex())); $this->flashSuccess('Image uploaded.'); } catch (KommerceException $e) { $this->flashError('Unable to upload image.'); } return redirect()->route('admin.product.images', ['productId' => $product->id->getHex()]); }
public function post(Request $request) { $userId = ''; // TODO: Grab authenticated userId $productId = $request->input('productId'); $product = $this->getProduct($productId); $image = Arr::get($_FILES, 'image'); $uploadFileDTO = new UploadFileDTO(Arr::get($image, 'name'), Arr::get($image, 'type'), Arr::get($image, 'tmp_name'), Arr::get($image, 'size')); dd(get_defined_vars()); if (!is_uploaded_file($uploadFileDTO->getFilePath())) { abort(400); } try { $this->dispatch(new CreateAttachmentForUserProductCommand($uploadFileDTO, $userId, $product->id->getHex())); $this->flashSuccess('Attachment uploaded.'); return redirect()->route('product.show', ['slug' => $product->slug, 'productId' => $product->id->getHex()]); } catch (KommerceException $e) { $this->flashError('Unable to upload attachment.'); return redirect()->route('user.attachment.createForProduct', ['productId' => $product->id->getHex()]); } }
/** * @param UploadFileDTO $uploadFileDTO * @return Attachment */ private function createAttachment(UploadFileDTO $uploadFileDTO) { $managedFile = $this->fileManager->saveFile($uploadFileDTO->getFilePath()); $attachment = new Attachment($managedFile->getUri()); $this->attachmentRepository->create($attachment); return $attachment; }