Giter Club home page Giter Club logo

voodoo-module's Introduction

voodoo-module

This package provides an implementation of the plugin pattern.

Quick start

A module must implement Voodoo\Module\Contracts\ModuleInterface and/or implement one of the ProviderInterfaces specified in that namespace.

The ModuleManager manages Modules and resolves them by using an implementation of ModuleResolverInterface

<?php

$modules = [
    FirstModule::class,
    SecondModule::class,
];

$container = new DiContainer();
$resolver = new \Voodoo\Module\ContainerModuleResolver($container);
$moduleManager = new \Voodoo\Module\ModuleManager($modules, $resolver);

// calls di() method on modules implementing DiProvider
$diConfig = $moduleManager->getContainerConfiguration();

// calls routes() method on modules implementing RouteProvider
$routerConfig = $moduleManager->getRouterConfiguration();

// calls configuration() method on modules implementing ConfigurationProvider
$moduleConfig = $moduleManager->getModuleConfiguration();

// calls events() method on modules implementing EventProvider
$eventConfig = $moduleManager->getEventConfiguration();

// calls middleware() method on modules implementing MiddlewareProvider
$middleware = $moduleManager->getMiddlewareConfiguration();

// calls bootstrap($container) modules
$moduleManager->bootstrapModules($container);

This is what a module looks like:

<?php

use Voodoo\Module\Contracts\DiProvider;
use Voodoo\Module\Contracts\RouteProvider;
use Voodoo\Module\Contracts\MiddlewareProvider;

class FirstModule implements DiProvider, RouteProvider, MiddlewareProvider
{
    public function bootstrap(ContainerInterface $container)
    {
     // Some bootstrapping code for this module
    }
    
    public function di() : array
    {
         return [];
    }
    
    public function routes() : array
    {
        return []; 
    }
    
    public function middleware() : array
    {
        return [];
    }
}

voodoo-module's People

Watchers

Max Schröter avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.