1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* (c) Christian Gripp <[email protected]> |
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 Core23\FacebookBundle\Action; |
13
|
|
|
|
14
|
|
|
use Core23\FacebookBundle\Connection\FacebookConnection; |
15
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
16
|
|
|
use Symfony\Component\HttpFoundation\Response; |
17
|
|
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; |
18
|
|
|
use Symfony\Component\Routing\RouterInterface; |
19
|
|
|
|
20
|
|
|
final class StartAuthAction |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var RouterInterface |
24
|
|
|
*/ |
25
|
|
|
private $router; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var FacebookConnection |
29
|
|
|
*/ |
30
|
|
|
private $facebookConnection; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var string[] |
34
|
|
|
*/ |
35
|
|
|
private $permissions; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* StartAuthAction constructor. |
39
|
|
|
* |
40
|
|
|
* @param RouterInterface $router |
41
|
|
|
* @param FacebookConnection $facebookConnection |
42
|
|
|
* @param string[] $permissions |
43
|
|
|
*/ |
44
|
|
|
public function __construct(RouterInterface $router, FacebookConnection $facebookConnection, array $permissions) |
45
|
|
|
{ |
46
|
|
|
$this->router = $router; |
47
|
|
|
$this->facebookConnection = $facebookConnection; |
48
|
|
|
$this->permissions = $permissions; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @return Response |
53
|
|
|
*/ |
54
|
|
|
public function __invoke(): Response |
55
|
|
|
{ |
56
|
|
|
$fb = $this->facebookConnection; |
57
|
|
|
$helper = $fb->getRedirectLoginHelper(); |
58
|
|
|
|
59
|
|
|
return new RedirectResponse($helper->getLoginUrl( |
60
|
|
|
$this->generateUrl('core23_facebook_check', [], UrlGeneratorInterface::ABSOLUTE_URL), |
61
|
|
|
$this->permissions |
62
|
|
|
)); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Generates a URL from the given parameters. |
67
|
|
|
* |
68
|
|
|
* @param string $route The name of the route |
69
|
|
|
* @param array $parameters An array of parameters |
70
|
|
|
* @param int $referenceType The type of reference (one of the constants in UrlGeneratorInterface) |
71
|
|
|
* |
72
|
|
|
* @return string The generated URL |
73
|
|
|
*/ |
74
|
|
|
private function generateUrl($route, array $parameters = [], $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH): string |
75
|
|
|
{ |
76
|
|
|
return $this->router->generate($route, $parameters, $referenceType); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|