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