litespeedtech / lscache-laravel

LSCache for Laravel framework
GNU General Public License v3.0
51 stars 14 forks source link

Support Lumen #20

Open maicol07 opened 3 years ago

maicol07 commented 3 years ago

Hi,

can you support Lumen (a micro-framework derivated from Laravel, by the same authors). Here is a discussion about the package incompatibilities: forum.openlitespeed.org/threads/lumen-composer-lscache-remove-illuminati-folder.4032

Thanks

lucasRolff commented 3 years ago

Hi @maicol07,

I've removed laravel/framework from composer.json as a requirement, and instead using illuminate/support (Which are both a requirement in Laravel and Lumen) - this will allow installing the composer package on Lumen as well.

However, keep in mind the package does not (yet) add full Lumen support, so no automatic registration of service providers or anything - the way Lumen and Laravel handles this are rather different, so will require some more work and testing.

In bootstrap/app.php, you'll have to add the routeMiddleware to be able to use lscache and lstags middlewares:

$app->routeMiddleware([
    'lscache' => \Litespeed\LSCache\LSCacheMiddleware::class,
    'lstags' => \Litespeed\LSCache\LSTagsMiddleware::class
]);

If you want to use the LSCache Facade, you'll have to add:

$app->withFacades(true, [
    '\Litespeed\LSCache\LSCache' => 'LSCache'
]);

In your bootstrap/app.php file as well.

Those two changes, should at least allow using the Facade, and be able to use the middlewares on routes.

To use the config file, you'll have to add a middleware directly to bootstrap/app.php, as well as adding your lscache.php configuration:

$app->middleware([
    \Litespeed\LSCache\LSCacheMiddleware::class
]);

$app->configure('lscache');

And make sure the the config from https://github.com/litespeedtech/lscache-laravel/blob/master/config/lscache.php are copied to config/lscache.php in your root directory of your Lumen application.

I'm trying to figure out the best way to automatically register the majority of the steps above.