Git Product home page Git Product logo

disco-1's Introduction

bitexpert/disco

This package provides a PSR-11 compatible, annotation-based dependency injection container. Have a look at the disco-demos project to find out how to use Disco.

Build Status Coverage Status

Installation

The preferred way of installing bitexpert/disco is through Composer. You can add bitexpert/disco as a dependency, as follows:

composer.phar require bitexpert/disco

Usage

To instantiate Disco use the following code in your bootstrapping logic. Create an instance of the \bitExpert\Disco\AnnotationBeanFactory and register the instance with the \bitExpert\Disco\BeanFactoryRegistry. The second step is important as Disco needs to grab the active container instance in a few locations where it does not have access to the container instance itself.

<?php

$beanFactory = new \bitExpert\Disco\AnnotationBeanFactory(MyConfiguration::class);
\bitExpert\Disco\BeanFactoryRegistry::register($beanFactory);

Next up you need to create a configuration class MyConfiguration and document it with a @Configuration annotation.

<?php

use bitExpert\Disco\Annotations\Configuration;

/**
 * @Configuration
 */
class MyConfiguration
{
}

To declare a configuration entry, 1) add a method to your MyConfiguration class, and 2) annotate the method with the @Bean annotation. Doing this registers the instance with Disco and uses the type specified by the method’s return value. The primary identifier is the method name:

<?php

use bitExpert\Disco\Annotations\Bean;
use bitExpert\Disco\Annotations\Configuration;
use bitExpert\Disco\Helper\SampleService;

/**
 * @Configuration
 */
class MyConfiguration
{
    /**
     * @Bean
     */
    public function mySampleService() : SampleService
    {
        return new SampleService();
    }
}

To let Disco return the entry with the id mySampleService call the get() method of \bitExpert\Disco\AnnotationBeanFactory, as follows:

<?php

$beanFactory->get('mySampleService');

Documentation

Documentation is in the docs tree, and can be compiled using bookdown.

$ php ./vendor/bin/bookdown docs/bookdown.json
$ php -S 0.0.0.0:8080 -t docs/html/

Then point your browser to http://localhost:8080/

Contribute

Please feel free to fork and extend existing or add new features and send a pull request with your changes! To establish a consistent code quality, please provide unit tests for all your changes and adapt the documentation.

Want To Contribute?

If you feel that you have something to share, then we’d love to have you. Check out the contributing guide to find out how, as well as what we expect from you.

Resources

License

Disco is released under the Apache 2.0 license.

disco-1's People

Contributors

be-heiglandreas avatar codeliner avatar dropdevcoding avatar heiglandreas avatar jaapio avatar kalessil avatar lavary avatar ocramius avatar senseexception avatar settermjd avatar shochdoerfer avatar skoop 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.