• Stars
    star
    139
  • Rank 262,161 (Top 6 %)
  • Language
    PHP
  • License
    Apache License 2.0
  • Created almost 9 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

PSR-11 compatible Dependency Injection Container for PHP.

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.

More Repositories

1

magento2-force-login

Force Customer Login Module for Magento 2
PHP
166
star
2

phpstan-magento

Magento specific extension for PHPStan
PHP
133
star
3

adrenaline

[DEPRECATED] A PSR-7 micro framework built on top of the Adroit middleware to speed up your development ;)
PHP
31
star
4

adroit

[DEPRECATED] ADR/PSR-7 middleware
PHP
27
star
5

magerun2-list-api-endpoints

Plugin for netz98 Magerun2 to list all API endpoints
PHP
16
star
6

phing-securitychecker

[DEPRECATED] Security Checker Phing Task
PHP
15
star
7

eclipse-smartsprites

[DEPRECATED] Eclipse Plugin offering Smartsprites integration
Java
11
star
8

etcetera

Extract Transform Library
PHP
9
star
9

ng2-combobox

[DEPRECATED] The only true Angular Combobox component ;)
TypeScript
9
star
10

magerun2-password-normalizer

n98-Magerun2 Plugin for normalizing all customer-email-addresses and passwords
PHP
9
star
11

eclipse-vagrant

[DEPRECATED] Eclipse Vagrant Plugin
Java
9
star
12

captainhook-infection

Captain Hook Plugin to run InfectionPHP only against the changed files of a commit
PHP
9
star
13

composer-phive-bridge

PHP
7
star
14

liquibase-phing

[DEPRECATED] Phing tasks to interact with Liquibase for database change management
PHP
7
star
15

prophiler-psr7-middleware

[DEPRECATED] Prophiler PSR7 Middleware
PHP
7
star
16

captainhook-validateauthor

Captain Hook Plugin to check if commit author is valid (e.g. email in whitelist)
PHP
7
star
17

addItEasy

[DEPRECATED] addItEasy - a PSR-7 compatible flat file CMS
PHP
7
star
18

slf4psrlog

Simple Logging Facade for Loggers implementing PSR-3 logging interface.
PHP
6
star
19

html5-offline-demo

[DEPRECATED] HTML5 Offline Todolist Demo
JavaScript
5
star
20

composer-authstore-plugin

[DEPRECATED] Composer Authstore plugin
PHP
5
star
21

mntyjs

[DEPRECATED] Lightweight plugin system based on require.js, jQuery and Base.js.
JavaScript
5
star
22

pathfinder

[DEPRECATED] A PSR-7 based router
PHP
5
star
23

ssbjs

Simple Service Bus for Javascript
TypeScript
5
star
24

disco-demos

Demo applications to showcase how to use Disco.
4
star
25

captainhook-rejectpush

Captain Hook Plugin to reject a remote push when certain commit Ids are found in history
PHP
4
star
26

grunt-mntyjs

[DEPRECATED] Grunt task for mnty.js
JavaScript
4
star
27

sulu-securitytxt-bundle

Sulu Bundle to manage security.txt files
PHP
4
star
28

eclipse-yuicompressor

[DEPRECATED] Eclipse YUICompressor Plugin
Java
4
star
29

eclipse-composer

[DEPRECATED] Eclipse Plugin offering Composer integration
4
star
30

cs-jshint

[DEPRECATED] bitExpert jshint configuration
3
star
31

just-run-phing

[DEPRECATED] Allow developers to "just run phing."
3
star
32

typo3-basicauth

TYPO3 Basic Auth extension
PHP
3
star
33

sylius-force-login

Force Customer Login Plugin for Sylius
PHP
3
star
34

cs-scsslint

[DEPRECATED] bitExpert scsslint style configuration
2
star
35

silex-twig-translation

[DEPRECATED] Silex / Twig extension to deal with Symfony/Translation in templates.
PHP
2
star
36

mattermost-client-node

[DEPRECATED] Mattermost client for node js
TypeScript
2
star
37

eclipse-svn-export

[DEPRECATED] Eclipse Plugin to export files based on their svn revisions
Java
2
star
38

specialist

[DEPRECATED] A simple array container implementing container-interop. Array all the things!
PHP
2
star
39

etcetera-demo

etcetera demo project
PHP
1
star
40

psql-nosql-workshop-dwx16

Developer Week 2016 PostgreSQL / NoSQL Dev Session
1
star
41

testiat-api-client-node

[DEPRECATED]
JavaScript
1
star
42

testiat-api-client-php

[DEPRECATED]
PHP
1
star
43

profitbricks-php-cli

[DEPRECATED] PHP CLI Client to interact with the profitbricks API
PHP
1
star
44

cs-jscs

[DEPRECATED] bitExpert jscs configuration
JavaScript
1
star
45

profitbricks-php-sdk

[DEPRECATED] PHP SDK for the profitbricks API
PHP
1
star
46

composer-webasset-installer

[DEPRECATED] Composer Webasset Installer
PHP
1
star
47

oauth2-server-storage-dbal

[DEPRECATED] Dbal storage implementation for OAuth 2.0 Server
PHP
1
star
48

ngx-radial-progress

[DEPRECATED]
TypeScript
1
star