|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of AppName. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Monofony |
|
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 App\Fixture\Factory; |
|
13
|
|
|
|
|
14
|
|
|
use FOS\OAuthServerBundle\Model\ClientInterface; |
|
15
|
|
|
use FOS\OAuthServerBundle\Model\ClientManagerInterface; |
|
16
|
|
|
use Symfony\Component\OptionsResolver\Options; |
|
17
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
|
18
|
|
|
|
|
19
|
|
|
class ApiClientExampleFactory extends AbstractExampleFactory |
|
20
|
|
|
{ |
|
21
|
|
|
/** @var ClientManagerInterface */ |
|
22
|
|
|
private $clientManager; |
|
23
|
|
|
|
|
24
|
|
|
/** @var \Faker\Generator */ |
|
25
|
|
|
private $faker; |
|
26
|
|
|
|
|
27
|
|
|
/** @var OptionsResolver */ |
|
28
|
|
|
private $optionsResolver; |
|
29
|
|
|
|
|
30
|
|
|
public function __construct(ClientManagerInterface $clientManager) |
|
31
|
|
|
{ |
|
32
|
|
|
$this->clientManager = $clientManager; |
|
33
|
|
|
|
|
34
|
|
|
$this->faker = \Faker\Factory::create(); |
|
35
|
|
|
$this->optionsResolver = new OptionsResolver(); |
|
36
|
|
|
|
|
37
|
|
|
$this->configureOptions($this->optionsResolver); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* {@inheritdoc} |
|
42
|
|
|
*/ |
|
43
|
|
|
public function create(array $options = []): ClientInterface |
|
44
|
|
|
{ |
|
45
|
|
|
$options = $this->optionsResolver->resolve($options); |
|
46
|
|
|
|
|
47
|
|
|
/** @var ClientInterface $client */ |
|
48
|
|
|
$client = $this->clientManager->createClient(); |
|
49
|
|
|
|
|
50
|
|
|
$client->setRandomId($options['random_id']); |
|
51
|
|
|
$client->setSecret($options['secret']); |
|
52
|
|
|
|
|
53
|
|
|
$client->setAllowedGrantTypes($options['allowed_grant_types']); |
|
54
|
|
|
|
|
55
|
|
|
return $client; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* {@inheritdoc} |
|
60
|
|
|
*/ |
|
61
|
|
|
protected function configureOptions(OptionsResolver $resolver): void |
|
62
|
|
|
{ |
|
63
|
|
|
$resolver |
|
64
|
|
|
->setDefault('random_id', function (Options $options): int { |
|
|
|
|
|
|
65
|
|
|
return $this->faker->unique()->randomNumber(8); |
|
66
|
|
|
}) |
|
67
|
|
|
->setDefault('secret', function (Options $options): string { |
|
|
|
|
|
|
68
|
|
|
return $this->faker->uuid; |
|
69
|
|
|
}) |
|
70
|
|
|
->setDefault('allowed_grant_types', []) |
|
71
|
|
|
->setAllowedTypes('allowed_grant_types', ['array']) |
|
72
|
|
|
; |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.