symfonette/class-named-services

1.0.0 2016-07-08 21:04 UTC

This package is auto-updated.

Last update: 2024-12-05 03:54:24 UTC


README

Packagist Build Status StyleCI Scrutinizer Code Quality SensioLabsInsight

All services can be accessed by FQCN.

Installation

This project can be installed via Composer:

composer require symfonette/class-named-services

Standalone

use Symfonette\ClassNamedServices\ContainerBuilderConfigurator;
use Symfony\Component\DependencyInjection\ContainerBuilder;

$builder = new ContainerBuilder();
$configurator = new ContainerBuilderConfigurator();

$configurator->configure($builder);

Symfony Bundle

use Symfonette\ClassNamedServices\Bundle\ClassNamedServiceBundle;
use Symfony\Component\HttpKernel\Kernel;

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        return [
            // ...
            new ClassNamedServiceBundle,
            // ...
        ];
    }
}

Usage

In dependency injection definition:

# app/config/services.yml
services:
    controller_main:
        class: AppBundle\Controller\MainController
        arguments:
            - '@Symfony\Bridge\Doctrine\RegistryInterface'
            - '@Twig_Environment'

In routing definition:

# app/config/routing.yml
homepage:
    path: /
    defaults:
      _controller: AppBundle\Controller\MainController:homepage

In controller:

namespace AppBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class ContactController extends Controller
{
    public function formAction()
    {
        $validator = $this->get(Validator::class);
        // ...
    }
}