2019-02-06 18:34:51 +01:00
|
|
|
<?php
|
2022-07-01 15:10:30 +02:00
|
|
|
|
2022-06-22 18:30:37 +02:00
|
|
|
class DetectAction implements ActionInterface
|
|
|
|
{
|
2024-01-25 16:06:24 +01:00
|
|
|
public function execute(Request $request)
|
2022-07-01 15:10:30 +02:00
|
|
|
{
|
2024-01-29 21:51:34 +01:00
|
|
|
$url = $request->get('url');
|
2024-01-25 16:06:24 +01:00
|
|
|
$format = $request->get('format');
|
2019-02-06 18:34:51 +01:00
|
|
|
|
2024-01-29 21:51:34 +01:00
|
|
|
if (!$url) {
|
|
|
|
return new Response(render(__DIR__ . '/../templates/error.html.php', ['message' => 'You must specify a url']));
|
2022-08-06 22:46:28 +02:00
|
|
|
}
|
|
|
|
if (!$format) {
|
2024-01-29 21:51:34 +01:00
|
|
|
return new Response(render(__DIR__ . '/../templates/error.html.php', ['message' => 'You must specify a format']));
|
2022-08-06 22:46:28 +02:00
|
|
|
}
|
2019-06-18 18:55:29 +02:00
|
|
|
|
2022-08-06 22:46:28 +02:00
|
|
|
$bridgeFactory = new BridgeFactory();
|
2019-02-06 18:34:51 +01:00
|
|
|
|
2022-07-08 12:54:23 +02:00
|
|
|
foreach ($bridgeFactory->getBridgeClassNames() as $bridgeClassName) {
|
2023-06-11 03:16:03 +02:00
|
|
|
if (!$bridgeFactory->isEnabled($bridgeClassName)) {
|
2022-07-01 15:10:30 +02:00
|
|
|
continue;
|
|
|
|
}
|
2019-02-06 18:34:51 +01:00
|
|
|
|
2022-07-08 12:54:23 +02:00
|
|
|
$bridge = $bridgeFactory->create($bridgeClassName);
|
2019-02-06 18:34:51 +01:00
|
|
|
|
2024-01-29 21:51:34 +01:00
|
|
|
$bridgeParams = $bridge->detectParameters($url);
|
2019-02-06 18:34:51 +01:00
|
|
|
|
2024-01-29 21:51:34 +01:00
|
|
|
if (!$bridgeParams) {
|
2022-07-01 15:10:30 +02:00
|
|
|
continue;
|
|
|
|
}
|
2019-02-06 18:34:51 +01:00
|
|
|
|
2024-01-29 21:51:34 +01:00
|
|
|
$query = [
|
|
|
|
'action' => 'display',
|
|
|
|
'bridge' => $bridgeClassName,
|
|
|
|
'format' => $format,
|
|
|
|
];
|
|
|
|
$query = array_merge($query, $bridgeParams);
|
|
|
|
return new Response('', 301, ['location' => '?' . http_build_query($query)]);
|
2022-07-01 15:10:30 +02:00
|
|
|
}
|
2019-02-06 18:34:51 +01:00
|
|
|
|
2024-01-29 21:51:34 +01:00
|
|
|
return new Response(render(__DIR__ . '/../templates/error.html.php', [
|
|
|
|
'message' => 'No bridge found for given URL: ' . $url,
|
|
|
|
]));
|
2022-07-01 15:10:30 +02:00
|
|
|
}
|
2019-02-06 18:34:51 +01:00
|
|
|
}
|