Coder Social home page Coder Social logo

bnf / service-provider-bridge-bundle Goto Github PK

View Code? Open in Web Editor NEW

This project forked from thecodingmachine/service-provider-bridge-bundle

0.0 2.0 0.0 77 KB

This Symfony Bundle enables Symfony applications to use service providers as defined in container-interop/service-provider

License: MIT License

PHP 100.00%

service-provider-bridge-bundle's Introduction

Scrutinizer Code Quality Build Status Coverage Status

container-interop/service-provider bridge bundle

Import service-provider as defined in container-interop into a Symfony application.

This is a fork of thecodingmachine/service-provider-bridge-bundle to support Symfony 4. Credits go to David Négrier.

Usage

Installation

Add Bnf\Interop\ServiceProviderBridgeBundle\InteropServiceProviderBridgeBundle in your kernel (the app/AppKernel.php file).

AppKernel.php

    public function registerBundles()
    {
        $bundles = [
            ...
            new \Bnf\Interop\ServiceProviderBridgeBundle\InteropServiceProviderBridgeBundle()
        ];
        ...
    }

Usage

You have to declare service providers manually in the constructor of the bundle.

AppKernel.php

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = [
            ...
            new \Bnf\Interop\ServiceProviderBridgeBundle\InteropServiceProviderBridgeBundle([
                new MyServiceProvide1(),
                new MyServiceProvide2()
            ])
        ];
        ...
    }
}

Alternatively, you can also pass the service provider class name. This is interesting because the service-provider bundle will not instantiate the service provider unless it is needed for a service. You can therefore improve performances of your application.

AppKernel.php

    public function registerBundles()
    {
        $bundles = [
            ...
            new \Bnf\Interop\ServiceProviderBridgeBundle\InteropServiceProviderBridgeBundle([
                MyServiceProvide1::class,
                MyServiceProvide2::class
            ])
        ];
        ...
    }

Finally, if you need to pass parameters to the constructors of the service providers, you can do this by passing an array:

AppKernel.php

    public function registerBundles()
    {
        $bundles = [
            ...
            new \Bnf\Interop\ServiceProviderBridgeBundle\InteropServiceProviderBridgeBundle([
                [ MyServiceProvide1::class, [ "param1", "param2" ] ],
                [ MyServiceProvide2::class, [ 42 ] ],
            ])
        ];
        ...
    }

service-provider-bridge-bundle's People

Contributors

moufmouf avatar bnf avatar

Watchers

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