예제 #1
0
 public static function register($app, $config)
 {
     //TODO :: externalize that
     $toolkit = 'gd';
     $app->container->singleton('imagecache', function () use($config, $toolkit) {
         return new Manager($config, $toolkit);
     });
     $url = "/{$config['images_url']}/:preset/:file";
     $app->get($url, function ($preset, $file) use($app) {
         try {
             $final_file = $app->imagecache->handleRequest($preset, $file);
         } catch (InvalidPresetException $e) {
             header('HTTP/1.0 404 Not Found');
             echo $e->getMessage();
             exit;
         } catch (NotFoundException $e) {
             header('HTTP/1.0 404 Not Found');
             echo $e->getMessage();
             exit;
         }
         if (!$final_file) {
             header('HTTP/1.0 500 Internal Server Error');
             echo 'dunno ...';
             exit;
         }
         $transfer = new Transfer();
         $transfer->transfer($final_file);
         exit;
     })->conditions(array('file' => '.*'));
 }
 /**
  * Register the service provider.
  *
  * @return void
  */
 public function register()
 {
     // Add the namespace to config
     $this->app['config']->package('onigoetz/imagecache', __DIR__ . '/../../config');
     $config = $this->app['config']->get('imagecache::imagecache');
     //TODO :: externalize that
     $toolkit = 'gd';
     // Stopwatch - must be registered so the application doesn't fail if the profiler is disabled
     $this->app['imagecache'] = $this->app->share(function () use($config, $toolkit) {
         return new Manager($config, $toolkit);
     });
     //PHP 5.3 compatibility
     $app = $this->app;
     $url = "{$config['path_images']}/{$config['path_cache']}/{preset}/{file}";
     $this->app['router']->get($url, function ($preset, $file) use($app) {
         try {
             $final_file = $app['imagecache']->handleRequest($preset, $file);
         } catch (InvalidPresetException $e) {
             return \Response::make('Invalid preset', 404);
         } catch (NotFoundException $e) {
             return \Response::make('File not found', 404);
         }
         if (!$final_file) {
             return \Response::make('Dunno what happened', 500);
         }
         //TODO :: be more "symfony reponse" friendly
         $transfer = new Transfer();
         $transfer->transfer($final_file);
         exit;
     })->where('file', '.*');
 }