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\ApiBundle\Fixture\Factory; |
13
|
|
|
|
14
|
|
|
use FOS\OAuthServerBundle\Model\ClientManagerInterface; |
15
|
|
|
use Sylius\Bundle\ApiBundle\Model\ClientInterface; |
16
|
|
|
use Sylius\Bundle\CoreBundle\Fixture\Factory\AbstractExampleFactory; |
17
|
|
|
use Symfony\Component\OptionsResolver\Options; |
18
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @author Łukasz Chruściel <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
class ApiClientExampleFactory extends AbstractExampleFactory |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var ClientManagerInterface |
27
|
|
|
*/ |
28
|
|
|
private $clientManager; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var \Faker\Generator |
32
|
|
|
*/ |
33
|
|
|
private $faker; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var OptionsResolver |
37
|
|
|
*/ |
38
|
|
|
private $optionsResolver; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param ClientManagerInterface $clientManager |
42
|
|
|
*/ |
43
|
|
|
public function __construct(ClientManagerInterface $clientManager) |
44
|
|
|
{ |
45
|
|
|
$this->clientManager = $clientManager; |
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 ClientInterface $client */ |
61
|
|
|
$client = $this->clientManager->createClient(); |
62
|
|
|
|
63
|
|
|
$client->setRandomId($options['random_id']); |
64
|
|
|
$client->setSecret($options['secret']); |
65
|
|
|
|
66
|
|
|
$client->setAllowedGrantTypes($options['allowed_grant_types']); |
67
|
|
|
|
68
|
|
|
return $client; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* {@inheritdoc} |
73
|
|
|
*/ |
74
|
|
|
protected function configureOptions(OptionsResolver $resolver) |
75
|
|
|
{ |
76
|
|
|
$resolver |
77
|
|
|
->setDefault('random_id', function (Options $options) { |
|
|
|
|
78
|
|
|
return $this->faker->unique()->randomNumber(8); |
79
|
|
|
}) |
80
|
|
|
->setDefault('secret', function (Options $options) { |
|
|
|
|
81
|
|
|
return $this->faker->uuid; |
82
|
|
|
}) |
83
|
|
|
->setDefault('allowed_grant_types', []) |
84
|
|
|
->setAllowedTypes('allowed_grant_types', ['array']) |
85
|
|
|
; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.