buzzingpixel / craft-slim-bridge
Craft中使用Slim的桥梁
1.1.5
2024-02-27 05:57 UTC
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
这可能只对我有影响,但如果你在寻找它并且喜欢它,欢迎使用此项目。
我非常喜欢使用Slim,与FastRoute和PSR标准接口一起。为此,我创建了这个极其简单的Craft插件,它让我可以在Slim中进行Craft网站的端前端开发,并几乎忽略背景中的Craft。
以下是使用方法
- 在你的Craft项目中运行
composer require buzzingpixel/craft-slim-bridge
- 然后运行
php craft plugin/install slim-bridge
- 在你的
/config
目录中创建一个名为slim-bridge.php
的配置文件。有关配置信息,请参阅下文的配置部分。 - 在Craft的
routes.php
文件中将以下捕获所有路由作为最后一个路由添加'<path:.*>' => 'slim-bridge/route-handler/index',
- 要通过Slim进行分类或条目路由,请在站点设置的
template
字段中使用以下格式来路由到自定义类的__invoke
方法_slimBridge/\My\Custom\Action\Class
- 如果你想要添加路由中间件或以其他方式操作路由,实现
\BuzzingPixel\SlimBridge\ElementSetRoute\SetRouteFromParsed\RoutingCallbackContract
示例
return [ '/some/craft/route' => 'some-template-or-action', '/another/craft/route' => 'another-template-or-action', '<path:.*>' => 'slim-bridge/route-handler/index', ];
配置
在配置文件中有两个键可用(查看示例)
containerInterface
Slim需要一个实现\Psr\Container\ContainerInterface
的实现,我已经留给项目所有者来提供。我个人喜欢PHP-DI。
appCreatedCallback
这是可选的,但如果你不使用它,那么你将不会设置任何路由或中间件,这将对你没有用处。一旦应用被创建,这个回调将被运行,并且接收到的参数将是Slim应用实例,你可以使用它来设置路由和中间件。