Skip to content

Commit

Permalink
Capturing file exists and throwing a (possibly) more helpful exception
Browse files Browse the repository at this point in the history
  • Loading branch information
weotch committed Apr 13, 2015
1 parent fe03a34 commit c97b575
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/Bkwld/Croppa/Storage.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php namespace Bkwld\Croppa;

// Deps
use League\Flysystem\Filesystem;
use League\Flysystem\Adapter\Local as Adapter;
use League\Flysystem\Filesystem;
use League\Flysystem\FileExistsException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

/**
Expand Down Expand Up @@ -138,18 +139,26 @@ public function cropExists($path) {
*/
public function readSrc($path) {
if ($this->src_disk->has($path)) return $this->src_disk->read($path);
else throw new NotFoundHttpException('Croppa: Referenced file missing');
else throw new NotFoundHttpException('Croppa: Src image is missing');
}

/**
* Write the cropped image contents to disk
*
* @param string $path Where to save the crop
* @param string $contents The image data
* @param void
* @throws Exception
* @return void
*/
public function writeCrop($path, $contents) {
$this->crops_disk->write($path, $contents);
try {
$this->crops_disk->write($path, $contents);
} catch(FileExistsException $e) {
throw new Exception("Croppa: Crop already exists at $path. You probably
have a misconfiguration. Make sure that the URL to your crop can be
transformed by the `path` config to your `crop_dir`.");
}

}

/**
Expand Down

0 comments on commit c97b575

Please sign in to comment.