1
0
Fork 0
mirror of https://github.com/RSS-Bridge/rss-bridge.git synced 2024-12-22 04:16:41 +03:00
rss-bridge/actions/DetectAction.php

42 lines
1.1 KiB
PHP
Raw Normal View History

2019-02-06 20:34:51 +03:00
<?php
2022-06-22 19:30:37 +03:00
class DetectAction implements ActionInterface
{
public function execute(Request $request)
{
$targetURL = $request->get('url');
$format = $request->get('format');
2019-02-06 20:34:51 +03:00
if (!$targetURL) {
throw new \Exception('You must specify a url!');
}
if (!$format) {
throw new \Exception('You must specify a format!');
}
$bridgeFactory = new BridgeFactory();
2019-02-06 20:34:51 +03:00
foreach ($bridgeFactory->getBridgeClassNames() as $bridgeClassName) {
if (!$bridgeFactory->isEnabled($bridgeClassName)) {
continue;
}
2019-02-06 20:34:51 +03:00
$bridge = $bridgeFactory->create($bridgeClassName);
2019-02-06 20:34:51 +03:00
$bridgeParams = $bridge->detectParameters($targetURL);
2019-02-06 20:34:51 +03:00
if (is_null($bridgeParams)) {
continue;
}
2019-02-06 20:34:51 +03:00
$bridgeParams['bridge'] = $bridgeClassName;
$bridgeParams['format'] = $format;
2019-02-06 20:34:51 +03:00
$url = '?action=display&' . http_build_query($bridgeParams);
return new Response('', 301, ['location' => $url]);
}
2019-02-06 20:34:51 +03:00
throw new \Exception('No bridge found for given URL: ' . $targetURL);
}
2019-02-06 20:34:51 +03:00
}