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
f7481020
Commit
f7481020
authored
Oct 27, 2021
by
Lech Sawon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
service locator
parent
b1416f6e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
4 deletions
+33
-4
ReservationController.php
src/Controller/ReservationController.php
+4
-4
AddReservation.php
src/Service/Reservation/AddReservation.php
+29
-0
No files found.
src/Controller/ReservationController.php
View file @
f7481020
...
...
@@ -5,6 +5,7 @@ namespace App\Controller;
use
App\Entity\Reservation
;
use
App\Form\ReservationType
;
use
App\Repository\ReservationRepository
;
use
App\Service\Reservation\AddReservation
;
use
Symfony\Bundle\FrameworkBundle\Controller\AbstractController
;
use
Symfony\Component\HttpFoundation\Request
;
use
Symfony\Component\HttpFoundation\Response
;
...
...
@@ -30,16 +31,15 @@ class ReservationController extends AbstractController
/**
* @Route("/new", name="reservation_new", methods={"GET","POST"})
*/
public
function
new
(
Request
$request
)
:
Response
public
function
new
(
Request
$request
,
AddReservation
$addReservation
)
:
Response
{
$reservation
=
new
Reservation
();
$form
=
$this
->
createForm
(
ReservationType
::
class
,
$reservation
);
$form
->
handleRequest
(
$request
);
if
(
$form
->
isSubmitted
()
&&
$form
->
isValid
())
{
$entityManager
=
$this
->
getDoctrine
()
->
getManager
();
$entityManager
->
persist
(
$reservation
);
$entityManager
->
flush
();
$addReservation
->
add
(
$reservation
);
return
$this
->
redirectToRoute
(
'reservation_index'
,
[],
Response
::
HTTP_SEE_OTHER
);
}
...
...
src/Service/Reservation/AddReservation.php
0 → 100644
View file @
f7481020
<?php
declare
(
strict_types
=
1
);
namespace
App\Service\Reservation
;
use
App\Entity\Reservation
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
final
class
AddReservation
{
private
ContainerInterface
$serviceLocator
;
public
function
__construct
(
ContainerInterface
$serviceLocator
)
{
$this
->
serviceLocator
=
$serviceLocator
;
}
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
();
$manager
->
persist
(
$reservation
);
$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