1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Lakion\CmsPlugin\Fixture\Factory; |
4
|
|
|
|
5
|
|
|
use Lakion\CmsPlugin\Document\Route; |
6
|
|
|
use Lakion\CmsPlugin\Document\StaticContent; |
7
|
|
|
use Sylius\Bundle\CoreBundle\Fixture\Factory\ExampleFactoryInterface; |
8
|
|
|
use Sylius\Bundle\CoreBundle\Fixture\OptionsResolver\LazyOption; |
9
|
|
|
use Sylius\Component\Core\Formatter\StringInflector; |
10
|
|
|
use Sylius\Component\Resource\Factory\FactoryInterface; |
11
|
|
|
use Sylius\Component\Resource\Repository\RepositoryInterface; |
12
|
|
|
use Symfony\Component\OptionsResolver\Options; |
13
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
14
|
|
|
|
15
|
|
|
final class RouteExampleFactory implements ExampleFactoryInterface |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var FactoryInterface |
19
|
|
|
*/ |
20
|
|
|
private $routeFactory; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var \Faker\Generator |
24
|
|
|
*/ |
25
|
|
|
private $faker; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var OptionsResolver |
29
|
|
|
*/ |
30
|
|
|
private $optionsResolver; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param FactoryInterface $routeFactory |
34
|
|
|
* @param RepositoryInterface $staticContentRepository |
35
|
|
|
*/ |
36
|
|
|
public function __construct(FactoryInterface $routeFactory, RepositoryInterface $staticContentRepository) |
37
|
|
|
{ |
38
|
|
|
$this->routeFactory = $routeFactory; |
39
|
|
|
|
40
|
|
|
$this->faker = \Faker\Factory::create(); |
41
|
|
|
$this->optionsResolver = |
42
|
|
|
(new OptionsResolver()) |
43
|
|
|
->setDefault('name', function (Options $options) { |
|
|
|
|
44
|
|
|
return StringInflector::nameToCode($this->faker->words(3, true)); |
|
|
|
|
45
|
|
|
}) |
46
|
|
|
->setAllowedTypes('name', 'string') |
47
|
|
|
|
48
|
|
|
->setDefault('content', LazyOption::randomOne($staticContentRepository)) |
49
|
|
|
->setAllowedTypes('content', ['string', StaticContent::class]) |
50
|
|
|
->setNormalizer('content', LazyOption::findOneBy($staticContentRepository, 'name')) |
51
|
|
|
; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* {@inheritdoc} |
56
|
|
|
*/ |
57
|
|
View Code Duplication |
public function create(array $options = []) |
|
|
|
|
58
|
|
|
{ |
59
|
|
|
$options = $this->optionsResolver->resolve($options); |
60
|
|
|
|
61
|
|
|
/** @var Route $route */ |
62
|
|
|
$route = $this->routeFactory->createNew(); |
63
|
|
|
$route->setName($options['name']); |
64
|
|
|
$route->setContent($options['content']); |
65
|
|
|
|
66
|
|
|
return $route; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.