Урок про “ Сервис Configurator — Symfony” и погорим о следующем: Конфигуратор для сервиса для пополнения данными.

config/services.yaml — autowire загрузит конфигуратор

    App\Services\ServiceManager:
        configurator: 'App\Services\ServiceManagerConfigurator:configure'

src/Services/ServiceManagerConfigurator.php

<?php


namespace App\Services;


use Doctrine\ORM\EntityManagerInterface;

class ServiceManagerConfigurator {

  private $em;

  public function __construct(EntityManagerInterface $entityManager) {
    $this->em = $entityManager;
  }

  public function configure( ServiceManager $serviceManager ){

    $serviceManager->setEntityManager($this->em);
  }
}

src/Services/ServiceManager.php

<?php

namespace App\Services;

use Doctrine\ORM\EntityManagerInterface;

class ServiceManager {

  private $em;

  public function exec(){
    ///
    //var_dump($this->em);
  }

  public function setEntityManager( EntityManagerInterface $entityManager){
    $this->em = $entityManager;
  }

}

Добавить комментарий

Ваш e-mail не будет опубликован. Обязательные поля помечены *

Любишь мемасики?

Подпишись на мой телеграм-канал!

Открыть
Закрыть