PHPackages                             inviqa/magento-symfony-container - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. inviqa/magento-symfony-container

ActiveMagento-module[Utility &amp; Helpers](/categories/utility)

inviqa/magento-symfony-container
================================

Provides Magento with an instance of a Symfony DI Container

1.3.0(7y ago)2436.5k9[1 PRs](https://github.com/inviqa/magento-symfony-container/pulls)proprietaryPHP

Since Aug 20Pushed 5y ago14 watchersCompare

[ Source](https://github.com/inviqa/magento-symfony-container)[ Packagist](https://packagist.org/packages/inviqa/magento-symfony-container)[ RSS](/packages/inviqa-magento-symfony-container/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (3)Versions (17)Used By (0)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/ceaa0ba1d3f890b0021ac1eeeb152fb07c23cc91724c5f42aae6aacc6fe120ff/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f696e766971612f6d6167656e746f2d73796d666f6e792d636f6e7461696e65722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/inviqa/magento-symfony-container/?branch=master)[![Build Status](https://camo.githubusercontent.com/9cf7c1ad76804b28a103f02ba1fda6558fad9d18f3837128fad56b3a30abd2c5/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f696e766971612f6d6167656e746f2d73796d666f6e792d636f6e7461696e65722f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/inviqa/magento-symfony-container/build-status/master)

magento-symfony-container
=========================

[](#magento-symfony-container)

Provides Magento with an instance of a Symfony DI Container

Documentation for the Symfony DI Component can be found [here](http://symfony.com/doc/current/components/dependency_injection/index.html).

Upon requesting the container for the first time, the configuration directories are scanned and the container is compiled. The container will be cached in public/var/cache/container.cache.php and subsequently read from there. You can use the admin cache control panel to enable/disable caching for the container, when disabled all service config files will be re-read when they are changed, otherwise they are ignored. To force the cache to refresh you can use n98-magerun or the admin cache-control panel.

Services Configuration
----------------------

[](#services-configuration)

All services configuration files are expected to be found in either the system-wide etc/ directory or within each modules etc/ directory. The expected format is XML, therefore the configuration files are expected to be called "services.xml"

The following is an example of defining a service named "acme.checkout", which, in turn, depends on a Magento catalog model and a mail service. Via the configuration, we can provide "acme.product.catalog" - which is constructed by calling Mage::getModel('inviqa\_acme/catalog') - as a dependency to "acme.checkout". Thus our "acme.checkout" service/class is now decoupled from Magento and its logic and business rules can be tested independently.

```

            inviqa_acme/catalog

```

Your implementation of Inviqa\\Acme\\Checkout might look something like this:

```
namespace Inviqa\Acme;

use Inviqa\Acme\Catalog;
use Inviqa\Mailer;

class Checkout
{
    private $catalog;

    private $mailer;

    public function __construct(Catalog $catalog, Mailer $mailer)
    {
        $this->catalog = $catalog;
        $this->mailer = $mailer;
    }

    public function process()
    {
        // checkout processing rules
    }
}
```

Along with a Catalog interface

```
namespace Inviqa\Acme

interface Catalog
{
    public function process(Products $products = null);
    public function start();
}
```

And have your Inviqa\_Acme\_Model\_Catalog implment the Catalog interface.

Usage
-----

[](#usage)

The idea behind using a DI container is to be able to easily decouple your code, therefore direct access to the container is bad practice and should be limited to where absolutely necessary for example where a service cannot be provided automatically (e.g. a Magento controller or observer).

### Usage via trait

[](#usage-via-trait)

```
class Inviqa_Acme_IndexController
{
    use Inviqa_SymfonyContainer_Helper_ServiceProvider;

    public function indexAction()
    {
        $this->getService('acme.checkout')->process();

        $this->loadLayout();
        $this->renderLayout();
    }
}
```

### Usage directly via helper

[](#usage-directly-via-helper)

```
$container = Mage::helper('inviqa_symfonyContainer/containerProvider')->getContainer();
```

### Test Environment

[](#test-environment)

The configuration builder reads the Magento configuration node "global/environment" and uses this to switch the container generator to "test" environment. The string expected in the "global/environment" node is "test". In this mode, the container generator will read additional services\_test.xml files, which will override services defined in services.xml if their id's match. In this way, you can use "mock" services for integration testing purposes. (see additional documentation in )

### Providing Magento Store Configuration Values to Service Constructors

[](#providing-magento-store-configuration-values-to-service-constructors)

If your service requires a value from the store configuration, something which would normally require calling Mage::getStoreConfig('web/secure/base\_url') for example, you can use the special tag mage.config in place of an node in your service definition. The "key" attribute is a regular Magento store configuration key. This will simply add the value of requested store configuration to the list of service constructor arguments:

```

```

This will result in the constructor of Acme\_Service being called with two extra arguments:

```
class Acme_Service
{
    public function __construct(SomeSerivce $someService, $amazonPaymentsTitle, $secureBaseUrl)
    {
        $this->_secureBaseUrl = $secureBaseUrl; // will have value of e.g: https://my-magento.dev/
    }
}
```

If the specified key does not exist, or is empty, the argument will be null or empty.

### Explicitly Providing Dependencies via \_\_dependencies (since version 0.5.0)

[](#explicitly-providing-dependencies-via-__dependencies-since-version-050)

Certain Magento classes, such as controllers, observers and blocks are instantiated by the system and therefore cannot be instantiated by the DI Container, nevertheless an additional service tag can make it easier to explicitly provide dependencies to these classes. Adding the mage.injectable tag to a service will allow you to provide these service dependencies *after* the service has been instantiated. The services arguments will be provided to the \_\_dependencies method, provided you call ServiceInjector::setupDependencies($class) after service instantiation, and your service has a \_\_dependencies method that contains typehints that match the arguments types in order.

For convenience, setupDependencies is called on controllers by hooking into the pre-dispatch event, for other classes such as observers and blocks you will have to call it yourself by overriding the class constructor.

For controllers, a service definition might look like this

```

            catalog/product

            sales/order

```

And the class itself will implement \_\_dependencies() thus:

```
    /**
     * @var Mage_Catalog_Model_Product
     */
    private $catalog;

    /**
     * @var Mage_Sales_Model_Order
     */
    private $order;

    /**
     * @param Mage_Catalog_Model_Product $catalog
     * @param Mage_Sales_Model_Order $order
     */
    public function __dependencies(
        Mage_Catalog_Model_Product $catalog,
        Mage_Sales_Model_Order $order
    ) {
        $this->catalog = $catalog;
        $this->order = $order;
    }
```

Unfortunately your controller will still be coupled to Mage due to extending Mage\_Core\_Controller\_Front\_Action, and thus - untestable as a unit, but it will at least be clear what its' dependencies are and they will be type-hinted.

To provide dependencies to other classes after they are instantiated, in addition to using the mage.injectable tag and implementing \_\_dependencies, you will have to override your class' constructor, for example:

```
    function __construct()
    {
        Mage::getSingleton('inviqa_symfonyContainer/serviceInjector')->setupDepdendencies($this);
        parent::__construct();
    }
```

### Registering your own compiler pass

[](#registering-your-own-compiler-pass)

Create a [custom compiler pass](https://github.com/inviqa/magento-symfony-container/blob/master/app/code/community/Inviqa/SymfonyContainer/Model/InjectableCompilerPass.php) class in your project.

Create a Magento observer and configure it to listen to the `symfony_container_before_container_generator` Magento event. Update this observer to inject the custom compiler pass into the generator config, as shown below:

```
class Inviqa_DependencyInjection_Model_Observer
{
    /** @var CustomCompilerPass */
    private $customCompilerPass;

    public function __construct()
    {
        $this->customCompilerPass = new CustomCompilerPass();
    }

    public function onBeforeContainerGenerator(Varien_Event_Observer $observer)
    {
        /** @var Configuration $generatorConfig */
        $generatorConfig = $observer->getData('generator_config');

        $generatorConfig->addCompilerPass($this->customCompilerPass);
    }
}
```

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity33

Limited adoption so far

Community21

Small or concentrated contributor base

Maturity71

Established project with proven stability

 Bus Factor3

3 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~79 days

Recently: every ~205 days

Total

15

Last Release

2820d ago

Major Versions

0.6.1 → 1.0.02016-04-08

0.6.2 → 1.1.12016-08-18

### Community

Maintainers

![](https://www.gravatar.com/avatar/6b33b247b870cf3add3d95961e04f7b87c63d0817af5c373837c28ae3c1aeaf0?d=identicon)[inviqa-session](/maintainers/inviqa-session)

![](https://www.gravatar.com/avatar/eae883afb6f3957e356498002d9503438dc23cc38cdf32aa5d20e463452756f6?d=identicon)[jon-acker](/maintainers/jon-acker)

---

Top Contributors

[![bennoislost](https://avatars.githubusercontent.com/u/1015154?v=4)](https://github.com/bennoislost "bennoislost (1 commits)")[![bicpi](https://avatars.githubusercontent.com/u/301163?v=4)](https://github.com/bicpi "bicpi (1 commits)")[![kojiromike](https://avatars.githubusercontent.com/u/1566303?v=4)](https://github.com/kojiromike "kojiromike (1 commits)")[![rgpjones](https://avatars.githubusercontent.com/u/472797?v=4)](https://github.com/rgpjones "rgpjones (1 commits)")[![ubick](https://avatars.githubusercontent.com/u/904477?v=4)](https://github.com/ubick "ubick (1 commits)")[![walterdolce](https://avatars.githubusercontent.com/u/6195629?v=4)](https://github.com/walterdolce "walterdolce (1 commits)")

### Embed Badge

![Health badge](/badges/inviqa-magento-symfony-container/health.svg)

```
[![Health](https://phpackages.com/badges/inviqa-magento-symfony-container/health.svg)](https://phpackages.com/packages/inviqa-magento-symfony-container)
```

###  Alternatives

[tim-reynolds/magento-qconfig

Magento config quick search

513.0k](/packages/tim-reynolds-magento-qconfig)[fastly/cdn

Fastly CDN module for Magento 1.x

275.5k](/packages/fastly-cdn)[clerk/magento

Clerk.io Turns More Browsers Into Buyers

1029.4k](/packages/clerk-magento)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
