voodoo / kernel
个人项目骨架的内核包
1.0.0
2019-07-22 19:44 UTC
Requires
- voodoo/configuration: ^1.0
- voodoo/di: ^1.0
- voodoo/event: ^1.0
- voodoo/module: ^1.0
- voodoo/router: ^1.0
- zendframework/zend-diactoros: ^2.1
- zendframework/zend-httphandlerrunner: ^1.1
Requires (Dev)
- codeception/codeception: ^3.0
This package is auto-updated.
Last update: 2024-09-23 07:39:47 UTC
README
这是一个PSR兼容的PHP内核包。
快速开始
首先,创建您的内核类
<?php namespace My\Project; /** * Class Kernel * @package My\Project */ class Kernel extends \Voodoo\Kernel\Kernel { protected function middleware() : array { return [ My\Psr\Middleware::class => 99, ]; } protected function routes() : array { return [ "welcome" => [ "path" => "/", "method" => "GET", "action" => My\Action::class, ], "welcome_name" => [ "path" => "/{name}", "method" => "GET", "action" => My\Action::class, ], ]; } protected function di() : array { return [ "definitions" => [ My\Class::class => [ "arguments" => [ My\Dependency::class, "string argument" ], "setters" => [ "injectConfiguration" => [ "argument1", "argument2" ], ], ], ], "factories" => [ My\Class::class => function() { return new My\Class("Argument"), }, ], "aliases" => [ My\ClassInterface::class => My\ClassImplementation::class, ], ]; } protected function events() : array { // Hand over invokables return [ My\Event::class => [ new My\EventListenerObject(), function (My\Event $event) { // Do something }. My\OtherEventListener::class, ], ]; } protected function modules() : array { // Instances of voodoo/module ModuleInterface return [ My\FirstModule::class, My\SecondModule::class, ]; } }
然后,创建您的前端控制器(index.php)
<?php include __DIR__.'/../vendor/autoload.php'; use My\Project\Kernel; $kernel = new Kernel(); $kernel->dispatch();
扩展
您可以自己定义IoC容器、事件监听器、配置管理器、模块管理器等。
<?php // Must implement Voodoo\Di\Contracts\ContainerConfiguratorInterface $containerConfigurator = new MyContainerConfigurator(); // Must implement Voodoo\Di\Configuration\Contracts\ConfigurationManagerInterface $configurationManager = new MyConfigurationManager(); // Must implement Voodoo\Event\Contracts\EventDispatcherConfiguratorInterface $eventDispatcherConfigurator = new MyEventDispatcherConfigurator(); // Must implement Voodoo\Module\Contracts\ModuleManagerInterface; $moduleManager = new MyModuleManager(); $kernel = new Kernel($containerConfigurator, $configurationManager, $eventDispatcherConfigurator, $moduleManager):
默认容器配置器:Voodoo\Di\Configurators\LeagueContainerConfigurator
默认配置管理器:Voodoo\Configuration\ConfigurationManager
默认事件调度器配置器:Voodoo\Event\Configurators\PhlyEventDispatcherConfigurator
默认模块管理器:Voodoo\Module\ModuleManager