@@ 8-47 (lines=40) @@ | ||
5 | use Doctrine\ODM\PHPCR\DocumentManagerInterface; |
|
6 | use Sylius\Component\Resource\Factory\FactoryInterface; |
|
7 | ||
8 | final class DocumentFactory implements FactoryInterface |
|
9 | { |
|
10 | /** |
|
11 | * @var FactoryInterface |
|
12 | */ |
|
13 | private $decoratedFactory; |
|
14 | ||
15 | /** |
|
16 | * @var DocumentManagerInterface |
|
17 | */ |
|
18 | private $documentManager; |
|
19 | ||
20 | /** |
|
21 | * @var string |
|
22 | */ |
|
23 | private $parentPath; |
|
24 | ||
25 | /** |
|
26 | * @param FactoryInterface $decoratedFactory |
|
27 | * @param DocumentManagerInterface $documentManager |
|
28 | * @param string $parentPath |
|
29 | */ |
|
30 | public function __construct(FactoryInterface $decoratedFactory, DocumentManagerInterface $documentManager, $parentPath) |
|
31 | { |
|
32 | $this->decoratedFactory = $decoratedFactory; |
|
33 | $this->documentManager = $documentManager; |
|
34 | $this->parentPath = $parentPath; |
|
35 | } |
|
36 | ||
37 | /** |
|
38 | * {@inheritdoc} |
|
39 | */ |
|
40 | public function createNew() |
|
41 | { |
|
42 | $document = $this->decoratedFactory->createNew(); |
|
43 | $document->setParentDocument($this->documentManager->find(null, $this->parentPath)); |
|
44 | ||
45 | return $document; |
|
46 | } |
|
47 | } |
|
48 |
@@ 10-52 (lines=43) @@ | ||
7 | use Sylius\Component\Resource\Factory\FactoryInterface; |
|
8 | use Webmozart\Assert\Assert; |
|
9 | ||
10 | final class RouteFactory implements FactoryInterface |
|
11 | { |
|
12 | /** |
|
13 | * @var FactoryInterface |
|
14 | */ |
|
15 | private $decoratedFactory; |
|
16 | ||
17 | /** |
|
18 | * @var DocumentManagerInterface |
|
19 | */ |
|
20 | private $documentManager; |
|
21 | ||
22 | /** |
|
23 | * @var string |
|
24 | */ |
|
25 | private $routeParentPath; |
|
26 | ||
27 | /** |
|
28 | * @param FactoryInterface $decoratedFactory |
|
29 | * @param DocumentManagerInterface $documentManager |
|
30 | * @param array $routeParentsPaths |
|
31 | */ |
|
32 | public function __construct(FactoryInterface $decoratedFactory, DocumentManagerInterface $documentManager, array $routeParentsPaths) |
|
33 | { |
|
34 | $this->decoratedFactory = $decoratedFactory; |
|
35 | $this->documentManager = $documentManager; |
|
36 | ||
37 | Assert::notEmpty($routeParentsPaths); |
|
38 | $this->routeParentPath = current($routeParentsPaths); |
|
39 | } |
|
40 | ||
41 | /** |
|
42 | * {@inheritdoc} |
|
43 | */ |
|
44 | public function createNew() |
|
45 | { |
|
46 | /** @var Route $route */ |
|
47 | $route = $this->decoratedFactory->createNew(); |
|
48 | $route->setParentDocument($this->documentManager->find(null, $this->routeParentPath)); |
|
49 | ||
50 | return $route; |
|
51 | } |
|
52 | } |
|
53 |