dlundgren / slim-turbo
SlimTurbo is an add on to Slim to enable full route caching
Requires
- middlewares/utils: ^2.2 | ^3.0
- psr/simple-cache: ^1.0
- slim/slim: ^4.4
Requires (Dev)
- cache/filesystem-adapter: ^1.0
- cache/simple-cache-bridge: ^1.0
- guzzlehttp/psr7: ^1.5
- http-interop/http-factory-guzzle: ^1.0
- laminas/laminas-diactoros: ^2.1
- nyholm/psr7: ^1.1
- nyholm/psr7-server: ^0.3.0
- php-di/php-di: ^6.0
- phpspec/prophecy: ^1.8
- phpstan/phpstan: ^0.11.5
- phpunit/phpunit: ^7.5
- slim/http: ^1.2
- slim/psr7: ^1.3
- squizlabs/php_codesniffer: ^3.4.2
- syberisle/coding-standards: ^2.0
- symfony/dependency-injection: ^4.3
README
Slim Turbo is an extension to Slim Framework that allows you to cache the Route names and Routes directly in a compiled Dependency Injection container.
It's recommended to use Slim without this package, for DI containers that do not compile.
Installation
It's recommended to use Composer to install Slim Turbo.
$ composer require dlundgren/slim-turbo
This will install Slim Turbo and all required dependencies. Like Slim, Slim Turbo requires PHP 7.1.
Usage
Create a class that extends Slim\Turbo\Provider\RouteProvider and implement
the register()
method. Routes are defined similarly to using Slim\App
and it's recommended to use class names,
service names, or strings when adding middleware and route callables. These will be loaded from the Container as
needed.
NOTE Closures may be used with SlimTurbo, but it's recommended to only use them while in development. It is undefined behavior (from SlimTurbo's perspective) to use Closures in production.
Domain Routing
Domain based routing is available by using Router::domain($domain, $callable)
. This operates in a similar manner to
how Router::group($pattern, $callable)
works.
There are a few options that you can provide to the DomainResolver
when setting it up.
Using subdomain only
This currently implements a very basic count of .
and drops the parts near the last dot.
Examples:
api.example.com > api
api.service.example.com > api.service
Caching Routing information
In order to cache the route information that is generated you MUST set a routing.cache
key in your DI
container to a SimpleCache implementation.
Service Provider Initialization
Slim Turbo provides service providers for the following Dependency Injection containers:
Contributing
Please see CONTRIBUTING for details.
Security
If you discover security related issues, please email dlundgren@syberisle.net instead of using the issue tracker.
License
Slim Turbo is licensed under the MIT license. See License File for more information.