PHP code example of voodoo / kernel

1. Go to this page and download the library: Download voodoo/kernel library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

voodoo / kernel example snippets




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,    
     ];
   }
}



y\Project\Kernel;

$kernel = new Kernel();
$kernel->dispatch();




// 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):