Giter Club home page Giter Club logo

mediawiki-libs-services's Introduction

Latest Stable Version License

Services

A PSR-11-compliant services framework. Services are created by instantiators (callables), which are usually defined in separate wiring files.

Usage

$services = new ServiceContainer();

$services->defineService(
    'MyService',
    static function ( ServiceContainer $services ): MyService {
        return new MyService();
    }
);

$services->loadWiringFiles( [
    'path/to/ServiceWiring.php',
] );

Where ServiceWiring.php looks like this:

return [

    'MyOtherService' => static function ( ServiceContainer $services ): MyOtherService {
        return new MyOtherService( $services->get( 'MyService' ) );
    },

    // ...

];

Each instantiator receives the service container as the first argument, from which it may retrieve further services as needed. Additional arguments for each instantiator may be specified when constructing the ServiceContainer.

Custom subclasses of ServiceContainer may offer easier access to certain services:

class MyServiceContainer extends ServiceContainer {

    public function getMyService(): MyService {
        return $this->get( 'MyService' );
    }

    public function getMyOtherService(): MyOtherService {
        return $this->get( 'MyOtherService' );
    }

}

// ServiceWiring.php
return [

    'MyOtherService' => static function ( MyServiceContainer $services ): MyOtherService {
        return new MyOtherService( $services->getMyService() );
    },

];

Running tests

composer install --prefer-dist
composer test

History

This library was first introduced in MediaWiki 1.27 (I3c25c0ac17). It was split out of the MediaWiki codebase and published as an independent library during the MediaWiki 1.33 and MediaWiki 1.34 development cycles.


mediawiki-libs-services's People

Contributors

aaronschulz avatar ayg avatar daimona avatar jdforrester avatar krinkle avatar legoktm avatar lucaswerkmeister avatar maxsem avatar reedy avatar somechris avatar thiemowmde avatar umherirrender avatar

Stargazers

 avatar

Watchers

 avatar  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.