Commit ac324a0f by Lech Sawon

service locator

parent f7481020
......@@ -20,6 +20,7 @@ services:
- '../src/Entity/'
- '../src/Kernel.php'
- '../src/Tests/'
- '../src/Service/'
# controllers are imported separately to make sure services can be injected
# as action arguments even if you don't extend any base controller class
......@@ -27,5 +28,12 @@ services:
resource: '../src/Controller/'
tags: ['controller.service_arguments']
#nadpisałem wcześniej automatycznie zarejestrowany serwis
App\Service\Reservation\AddReservation:
- '%env(RABBIT_URL)%'
- '@doctrine.orm.entity_manager'
# add more service definitions when explicit configuration is needed
# please note that last definitions always *replace* previous ones
......@@ -7,6 +7,7 @@ use App\Form\ReservationType;
use App\Repository\ReservationRepository;
use App\Service\Reservation\AddReservation;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
......
......@@ -5,25 +5,29 @@ declare(strict_types=1);
namespace App\Service\Reservation;
use App\Entity\Reservation;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Doctrine\ORM\EntityManagerInterface;
final class AddReservation
{
private ContainerInterface $serviceLocator;
private EntityManagerInterface $manager;
public function __construct(ContainerInterface $serviceLocator)
private string $rabbitUrl;
public function __construct(string $rabbitUrl, EntityManagerInterface $manager)
{
$this->serviceLocator = $serviceLocator;
$this->rabbitUrl = $rabbitUrl;
$this->manager = $manager;
}
public function add(Reservation $reservation): void
{
//dodatkow logika biznesowa do wykonania w czasie dodania rezerwacji
// np czy salka jest dostępna
// np inicjacja wysłania powiadomianie
$manager = $this->serviceLocator->get('doctrine')->getManager();
// np inicjacja wysłania powiadomień
$manager->persist($reservation);
$manager->flush();
//chcemy się połączy z system kolejkowym (rabbit, redis)
// potrzebujemy więc credentiali, skąd je wziąć?
$this->manager->persist($reservation);
$this->manager->flush();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment