Skip to content

Commit 68377ea

Browse files
committed
Added proxy
1 parent abc34dd commit 68377ea

File tree

14 files changed

+1719
-1204
lines changed

14 files changed

+1719
-1204
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[*.php]
2+
indent_style = space
3+
indent_size = 4

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
"tests/ImageTestCase.php"
3737
],
3838
"psr-0": {
39-
"Folklore\\Image\\": "src/"
39+
"Folklore\\Image\\": "src/",
40+
"Folklore\\Image\\Tests": "tests/"
4041
}
4142
},
4243
"minimum-stability": "stable"

phpunit.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
>
1313
<testsuites>
1414
<testsuite name="Folklore/Image Test Suite">
15-
<directory suffix=".php">./tests/</directory>
15+
<file>./tests/ImageTestCase.php</file>
16+
<file>./tests/ImageServeTestCase.php</file>
17+
<file>./tests/ImageProxyTestCase.php</file>
1618
</testsuite>
1719
</testsuites>
1820
</phpunit>

src/Folklore/Image/ImageController.php

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,38 @@
1111
use App;
1212
use Image;
1313

14-
class ImageController extends BaseController {
15-
16-
use DispatchesJobs, ValidatesRequests;
17-
18-
public function serve($path)
19-
{
20-
$app = app();
21-
22-
//Get the full path of an image
23-
$fullPath = $app->make('path.public').'/'.$path;
24-
25-
// Serve the image response. If there is a file missing
26-
// exception or parse exception, throw a 404.
27-
try
28-
{
29-
$response = $app['image']->serve($fullPath);
30-
31-
return $response;
32-
}
33-
catch(ParseException $e)
34-
{
35-
return abort(404);
36-
}
37-
catch(FileMissingException $e)
38-
{
39-
return abort(404);
40-
}
41-
42-
}
43-
14+
class ImageController extends BaseController
15+
{
16+
17+
use DispatchesJobs, ValidatesRequests;
18+
19+
public function serve($path)
20+
{
21+
// Serve the image response. If there is a file missing
22+
// exception or parse exception, throw a 404.
23+
try {
24+
return app('image')->serve($path);
25+
} catch (ParseException $e) {
26+
return abort(404);
27+
} catch (FileMissingException $e) {
28+
return abort(404);
29+
} catch (Exception $e) {
30+
return abort(500);
31+
}
32+
}
33+
34+
public function proxy($path)
35+
{
36+
// Serve the image response from proxy. If there is a file missing
37+
// exception or parse exception, throw a 404.
38+
try {
39+
return app('image')->proxy($path);
40+
} catch (ParseException $e) {
41+
return abort(404);
42+
} catch (FileMissingException $e) {
43+
return abort(404);
44+
} catch (Exception $e) {
45+
return abort(500);
46+
}
47+
}
4448
}

0 commit comments

Comments
 (0)