theofidry/sfcontext-bundle

This package is abandoned and no longer maintained. No replacement package was suggested.

A context to access statically to the symfony container.

Installs: 2 147

Dependents: 0

Suggesters: 0

Security: 0

Stars: 4

Watchers: 1

Forks: 3

Open Issues: 1

Type:symfony-bundle

v1.2.0 2019-12-12 15:45 UTC

This package is auto-updated.

Last update: 2020-09-12 18:16:08 UTC


README

Package version Build Status License

A dead simple bundle to be able to access the Symfony Container statically.

Install

You can use Composer to install the bundle in your project:

composer require theofidry/sfcontext-bundle

Then, enable the bundle by updating your app/AppKernel.php file to enable the bundle:

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Fidry\SfContextBundle\SfContextBundle(),
    );

    return $bundles;
}

Usage

There are two cases where you might use this bundle:

  1. If you don't like dependency injection
  2. For quick & dirty debugging where you can't afford to do a dump
class DummyService
{
    public function foo()
    {
        // Do something

        SfContext::get('logger')->debug('it worked');

        // Do something else
    }
}

Credits

I got the original idea from Laravel facades although the idea is actually not new and you can find it in the Symfony world as sfContext and which has been ported to Symfony 2.x with sfContextBundle.