1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sylius package. |
5
|
|
|
* |
6
|
|
|
* (c) Paweł Jędrzejewski |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Sylius\Bundle\CoreBundle\Fixture\Factory; |
13
|
|
|
|
14
|
|
|
use Sylius\Component\Core\Formatter\StringInflector; |
15
|
|
|
use Sylius\Component\Customer\Model\CustomerGroupInterface; |
16
|
|
|
use Sylius\Component\Resource\Factory\FactoryInterface; |
17
|
|
|
use Symfony\Component\OptionsResolver\Options; |
18
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @author Grzegorz Sadowski <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
class CustomerGroupExampleFactory extends AbstractExampleFactory implements ExampleFactoryInterface |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var FactoryInterface |
27
|
|
|
*/ |
28
|
|
|
private $customerGroupFactory; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var \Faker\Generator |
32
|
|
|
*/ |
33
|
|
|
private $faker; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var OptionsResolver |
37
|
|
|
*/ |
38
|
|
|
private $optionsResolver; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param FactoryInterface $customerGroupFactory |
42
|
|
|
*/ |
43
|
|
|
public function __construct(FactoryInterface $customerGroupFactory) |
44
|
|
|
{ |
45
|
|
|
$this->customerGroupFactory = $customerGroupFactory; |
46
|
|
|
|
47
|
|
|
$this->faker = \Faker\Factory::create(); |
48
|
|
|
$this->optionsResolver = new OptionsResolver(); |
49
|
|
|
|
50
|
|
|
$this->configureOptions($this->optionsResolver); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* {@inheritdoc} |
55
|
|
|
*/ |
56
|
|
|
public function create(array $options = []) |
57
|
|
|
{ |
58
|
|
|
$options = $this->optionsResolver->resolve($options); |
59
|
|
|
|
60
|
|
|
/** @var CustomerGroupInterface $customerGroup */ |
61
|
|
|
$customerGroup = $this->customerGroupFactory->createNew(); |
62
|
|
|
$customerGroup->setCode($options['code']); |
63
|
|
|
$customerGroup->setName($options['name']); |
64
|
|
|
|
65
|
|
|
return $customerGroup; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* {@inheritdoc} |
70
|
|
|
*/ |
71
|
|
|
protected function configureOptions(OptionsResolver $resolver) |
72
|
|
|
{ |
73
|
|
|
$resolver |
74
|
|
|
->setDefault('name', function (Options $options) { |
|
|
|
|
75
|
|
|
return $this->faker->words(3, true); |
76
|
|
|
}) |
77
|
|
|
->setDefault('code', function (Options $options) { |
78
|
|
|
return StringInflector::nameToCode($options['name']); |
79
|
|
|
}) |
80
|
|
|
; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.