Skip to content

Commit

Permalink
Making Handler class a Controller instance so it route can be cached
Browse files Browse the repository at this point in the history
  • Loading branch information
weotch committed Apr 10, 2015
1 parent 23f57cd commit b8163ca
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"require": {
"php": ">=5.4.0",
"illuminate/support": "4 - 5",
"illuminate/routing": "4 - 5",
"league/flysystem": "~1.0",
"symfony/http-foundation": "~2.0",
"symfony/http-kernel": "~2.0",
Expand Down
3 changes: 2 additions & 1 deletion src/Bkwld/Croppa/Handler.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<?php namespace Bkwld\Croppa;

// Deps
use Illuminate\Routing\Controller;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;

/**
* Handle a Croppa-style request, forwarding the actual work onto other classes.
*/
class Handler {
class Handler extends Controller {

/**
* @var Bkwld\Croppa\Storage
Expand Down
26 changes: 13 additions & 13 deletions src/Bkwld/Croppa/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@ public function register() {
if ($this->version() == 5) $this->registerLaravel5();

// Bind the Croppa URL generator and parser
$this->app->singleton('croppa.url', function($app) {
$this->app->singleton('Bkwld\Croppa\URL', function($app) {
return new URL($this->getConfig());
});

// Handle the request for an image, this cooridnates the main logic
$this->app->singleton('croppa.handler', function($app) {
return new Handler($app['croppa.url'], $app['croppa.storage']);
$this->app->singleton('Bkwld\Croppa\Handler', function($app) {
return new Handler($app['Bkwld\Croppa\URL'], $app['Bkwld\Croppa\Storage']);
});

// Interact with the disk
$this->app->singleton('croppa.storage', function($app) {
$this->app->singleton('Bkwld\Croppa\Storage', function($app) {
return Storage::make($app, $this->getConfig());
});

// API for use in apps
$this->app->singleton('croppa.helpers', function($app) {
return new Helpers($app['croppa.url'], $app['croppa.storage']);
$this->app->singleton('Bkwld\Croppa\Helpers', function($app) {
return new Helpers($app['Bkwld\Croppa\URL'], $app['Bkwld\Croppa\Storage']);
});
}

Expand Down Expand Up @@ -67,9 +67,9 @@ public function boot() {
}

// Listen for Cropa style URLs, these are how Croppa gets triggered
$this->app['router']->get('{path}', function($path) {
return $this->app['croppa.handler']->handle($path);
})->where('path', app('croppa.url')->routePattern());
$this->app['router']
->get('{path}', 'Bkwld\Croppa\Handler@handle')
->where('path', $this->app['Bkwld\Croppa\URL']->routePattern());
}

/**
Expand Down Expand Up @@ -111,10 +111,10 @@ public function getConfig() {
*/
public function provides() {
return [
'croppa.url',
'croppa.handler',
'croppa.storage',
'croppa.helpers',
'Bkwld\Croppa\URL',
'Bkwld\Croppa\Handler',
'Bkwld\Croppa\Storage',
'Bkwld\Croppa\Helpers',
];
}
}

0 comments on commit b8163ca

Please sign in to comment.