Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[DI][FrameworkBundle] (Idea) PHP-DSL base class for simple shortcuts for DI #27073

Copy link
Copy link
Closed
@aurimasniekis

Description

@aurimasniekis
Issue body actions
Q A
Bug report? no
Feature request? yes
BC Break report? no
RFC? no
Symfony version 4.1

Hi,

Thanks for merging my PR #27065 my whole point of that change was to ability use inline classes with __invoke method and some shortcuts like addCommand, addService, addControllers, addRepository.

So I thought about something a bit wider scope for e.g. Make a base class inside FrameworkBundle which would have all shortcuts for main features and would allow extending default properties of it and etc.

Something like this:

<?php

use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

abstract class ContainerConfig
{
    /**
     * @var ContainerConfigurator
     */
    private $containerConfig;

    public function addController(string $class, bool $autoWire = true)
    {
        // ...
    }

    public function addDoctrineRepository(string $entityClass)
    {
        // ...
    }

    public function addService(string $class, bool $autoWire = true, bool $public = false)
    {
        // ...
    }
    
    public function addEventListener(string $class, string $eventName)
    {
        // ...
    }

    public function __invoke(ContainerConfigurator $containerConfigurator)
    {
        $this->containerConfig = $containerConfigurator;
        
        $this->configure($containerConfigurator);
    }

    abstract public function configure(ContainerConfigurator $container);
}

return new class extends ContainerConfig {
    public function configure(ContainerConfigurator $container)
    {
        $this->addController(UserController::class);
        $this->addDoctrineRepository(User::class);
        $this->addService(UserCreationService::class);

        $this->addEventListener(UserCreationListener::class, 'user.new');
    }
};

Either way, I am going to make it either an external library or try to integrate inside FrameworkBundle. But I just don't know all shortcuts I should add and if someone could suggest more these kind of shortcuts I would not mind spending time implementing this util class.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.