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\LastFmBundle\Action; |
13
|
|
|
|
14
|
|
|
use Core23\LastFm\Service\AuthService; |
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 AuthService |
24
|
|
|
*/ |
25
|
|
|
private $authService; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var RouterInterface |
29
|
|
|
*/ |
30
|
|
|
private $router; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* StartAuthAction constructor. |
34
|
|
|
* |
35
|
|
|
* @param AuthService $authService |
36
|
|
|
* @param RouterInterface $router |
37
|
|
|
*/ |
38
|
|
|
public function __construct(AuthService $authService, RouterInterface $router) |
39
|
|
|
{ |
40
|
|
|
$this->authService = $authService; |
41
|
|
|
$this->router = $router; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @return Response |
46
|
|
|
*/ |
47
|
|
|
public function __invoke(): Response |
48
|
|
|
{ |
49
|
|
|
$callbackUrl = $this->generateUrl('core23_lastfm_check', [], UrlGeneratorInterface::ABSOLUTE_URL); |
50
|
|
|
|
51
|
|
|
return new RedirectResponse($this->authService->getAuthUrl($callbackUrl)); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Generates a URL from the given parameters. |
56
|
|
|
* |
57
|
|
|
* @param string $route The name of the route |
58
|
|
|
* @param array $parameters An array of parameters |
59
|
|
|
* @param int $referenceType The type of reference (one of the constants in UrlGeneratorInterface) |
60
|
|
|
* |
61
|
|
|
* @return string The generated URL |
62
|
|
|
*/ |
63
|
|
|
private function generateUrl($route, array $parameters = [], $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH): string |
64
|
|
|
{ |
65
|
|
|
return $this->router->generate($route, $parameters, $referenceType); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|