File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -15,12 +15,14 @@ class StockFacade
1515 * @param \Shopsys\FrameworkBundle\Model\Stock\StockRepository $stockRepository
1616 * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $eventDispatcher
1717 * @param \Shopsys\FrameworkBundle\Model\Stock\ProductStockFacade $productStockFacade
18+ * @param \Shopsys\FrameworkBundle\Model\Stock\StockFactory $stockFactory
1819 */
1920 public function __construct (
2021 protected readonly EntityManagerInterface $ em ,
2122 protected readonly StockRepository $ stockRepository ,
2223 protected readonly EventDispatcherInterface $ eventDispatcher ,
2324 protected readonly ProductStockFacade $ productStockFacade ,
25+ protected readonly StockFactory $ stockFactory ,
2426 ) {
2527 }
2628
@@ -30,7 +32,7 @@ public function __construct(
3032 */
3133 public function create (StockData $ stockData ): Stock
3234 {
33- $ stock = new Stock ($ stockData );
35+ $ stock = $ this -> stockFactory -> create ($ stockData );
3436 $ this ->em ->persist ($ stock );
3537 $ this ->em ->flush ();
3638
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Shopsys \FrameworkBundle \Model \Stock ;
6+
7+ use Shopsys \FrameworkBundle \Component \EntityExtension \EntityNameResolver ;
8+
9+ class StockFactory
10+ {
11+ /**
12+ * @param \Shopsys\FrameworkBundle\Component\EntityExtension\EntityNameResolver $entityNameResolver
13+ */
14+ public function __construct (
15+ protected readonly EntityNameResolver $ entityNameResolver ,
16+ ) {
17+ }
18+
19+ /**
20+ * @param \Shopsys\FrameworkBundle\Model\Stock\StockData $stockData
21+ * @return \Shopsys\FrameworkBundle\Model\Stock\Stock
22+ */
23+ public function create (StockData $ stockData ): Stock
24+ {
25+ $ classData = $ this ->entityNameResolver ->resolve (Stock::class);
26+
27+ return new $ classData ($ stockData );
28+ }
29+ }
You can’t perform that action at this time.
0 commit comments