dida/servicebus

A lightweight PHP Service Bus library.

v1.0.0 2021-05-31 08:04 UTC

This package is auto-updated.

Last update: 2021-12-02 07:45:35 UTC


README

A lightweight PHP Service Bus library. MIT License.

API

public static function set($name, $service);
public static function get($name, array $parameters = []);
public static function setSingleton($name, $service);
public static function getNew($name, phparray $parameters = []);
public static function remove($name);
public static function names();
public static function has($name);

Examples

set

// set a classname as service
ServiceBus::set('Request', \Dida\Http\Request::class);

// Set an instance as service.
ServiceBus::set("App", $app);

// Set a closure as service
ServiceBus::set("Db", function () use ($foo, $bar) {
    $conf = require __DIR__ . "/conf/mysql.php";
    $db = new \Dida\Db\Db($conf);
    return $db;
});