buzzingpixel / craft-slim-bridge
Bridge for using Slim with Craft
Installs: 215
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Type:craft-plugin
Requires (Dev)
- codedungeon/phpunit-result-printer: ^0.31.0
- craftcms/cms: ^3.7
- doctrine/coding-standard: ^9
- friendsofphp/php-cs-fixer: ^2.18
- php-di/php-di: ^6.3
- phpstan/phpstan: ^1
- phpstan/phpstan-deprecation-rules: ^1
- phpstan/phpstan-strict-rules: ^1
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: ^3.5
- symfony/var-dumper: ^5.3
README
This is probably only of interest to me, but you're welcome to use this project if you come across it and like it.
I really like working in Slim, with FastRoute, and PSR standard interfaces. To that end, I've created this extremely simple Craft Plugin that let's me do the front-end of Craft sites in Slim and mostly ignore that Craft is there in the background.
Here's how to use it:
- In your craft project, run
composer require buzzingpixel/craft-slim-bridge
- Then run
php craft plugin/install slim-bridge
- Create a config file in your
/config
directory namedslim-bridge.php
. See Config section below for configuration. - Add the following catch-all route as the last route in your craft
routes.php
file:'<path:.*>' => 'slim-bridge/route-handler/index',
- For Category or Entry routing through Slim, use the following format in the site settings
template
field to route to custom class's__invoke
method:_slimBridge/\My\Custom\Action\Class
- If you want to add route middleware or manipulate the route in other ways, implement
\BuzzingPixel\SlimBridge\ElementSetRoute\SetRouteFromParsed\RoutingCallbackContract
Example:
return [ '/some/craft/route' => 'some-template-or-action', '/another/craft/route' => 'another-template-or-action', '<path:.*>' => 'slim-bridge/route-handler/index', ];
Config
Two keys are available in the config file (See example):
containerInterface
Slim requires an implementation of \Psr\Container\ContainerInterface
and I've left this to project owners to provide. I, personally like PHP-DI.
appCreatedCallback
This is optional, but if you don't use it, then you won't have set any routes or middlewares and it will be useless to you. Once the app has been created, this callback will be run and the argument recieved will be the Slim App instance which you can use to set routes and middleware.