Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
symfony_2504
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Lech Sawoń
symfony_2504
Commits
ac324a0f
Commit
ac324a0f
authored
Oct 27, 2021
by
Lech Sawon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
service locator
parent
f7481020
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
8 deletions
+21
-8
services.yaml
config/services.yaml
+8
-0
ReservationController.php
src/Controller/ReservationController.php
+1
-0
AddReservation.php
src/Service/Reservation/AddReservation.php
+12
-8
No files found.
config/services.yaml
View file @
ac324a0f
...
...
@@ -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
src/Controller/ReservationController.php
View file @
ac324a0f
...
...
@@ -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
;
...
...
src/Service/Reservation/AddReservation.php
View file @
ac324a0f
...
...
@@ -5,25 +5,29 @@ declare(strict_types=1);
namespace
App\Service\Reservation
;
use
App\Entity\Reservation
;
use
Symfony\Component\DependencyInjection\Contain
erInterface
;
use
Doctrine\ORM\EntityManag
erInterface
;
final
class
AddReservation
{
private
ContainerInterface
$serviceLocato
r
;
private
EntityManagerInterface
$manage
r
;
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
();
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment