Coder Social home page Coder Social logo

thecodingmachine / interop.silex.di Goto Github PK

View Code? Open in Web Editor NEW
7.0 14.0 0.0 196 KB

This project is a very simple extension to the Silex microframework. It adds to Silex the capability to use any DI container (not only Pimple).

License: MIT License

PHP 100.00%

interop.silex.di's Introduction

Run Silex with any Dependency Injection container

This project is a very simple extension to the Silex microframework. It makes Silex able to use any other dependency container compatible with container-interop (and not only Pimple).

To use this, you simply need to use the Mouf\Interop\Silex\Application class that extends the Silex\Application class.

Why?

Silex is a microframework. It is designed on top of Pimple, a very simple dependency injection container (DIC) written in about 80 lines of code. Pimple is a nice DIC, but it can become quite verbose as your project grows. And natively, Silex has no way to use another DIC (the Application class of Silex extends the Pimple class).

This project lets you add any other dependency injection framework directly in your Silex project. Instead of injecting your dependencies by filling the $app variable, you can register entries in your own container. Instances declared in your container will be accessible using the Pimple $app['my.instance'] syntax.

How?

The extended Application class has a modified constructor:

  • __construct(ContainerInterface $container = null, array $values = array())

The container passed in parameter is a delegate lookup container.

When this is done, you can access any instance declared of your container using the $app object, just like you would in any Silex project.

Your DI container must respect the ContainerInterface described in this the container-interop project.

What DI containers can I plug in Silex?

Out of the box, you can plug any of the DI containers supported by container-interop. There are an awful lot of them!

Installation

This class is distributed as a Composer package:

{
	require: {
		"mouf/interop.silex.di" : "~2.0"
	}
}

See a working sample

Check out this use case: creating a Silex controller with the Mouf framework

You are a Symfony 2 user?

There is a very similar package for Symfony 2 application. It lets you add additional containers to the main Symfony 2 container: check it out: interop.symfony.di

interop.silex.di's People

Contributors

moufmouf avatar

Stargazers

Tomasz Darmetko avatar Ainun Nazieb avatar Jorge Mudry avatar  avatar Ecor avatar Marcos Sader avatar  avatar

Watchers

James Cloos avatar Jérémie Posé avatar  avatar Hugo Averty avatar  avatar Kevin Nguyen avatar Marc TEYSSIER avatar Nicolas Peguin avatar David Maechler avatar  avatar Camille Koppel avatar  avatar Huberty Xavier 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.