2021-10-18 21:22:02 +09:00
|
|
|
<?php
|
|
|
|
|
2021-10-27 12:15:07 +09:00
|
|
|
declare(strict_types = 1);
|
|
|
|
|
2021-10-18 21:22:02 +09:00
|
|
|
namespace Component\FreeNetwork\Util;
|
|
|
|
|
|
|
|
use App\Core\Event;
|
|
|
|
use App\Core\HTTPClient;
|
2021-10-27 12:15:07 +09:00
|
|
|
use Exception;
|
|
|
|
use Symfony\Contracts\HttpClient\ResponseInterface;
|
2021-10-18 21:22:02 +09:00
|
|
|
use XML_XRD;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Abstract class for LRDD discovery methods
|
|
|
|
*
|
|
|
|
* Objects that extend this class can retrieve an array of
|
|
|
|
* resource descriptor links for the URI. The array consists
|
|
|
|
* of XML_XRD_Element_Link elements.
|
|
|
|
*
|
|
|
|
* @category Discovery
|
|
|
|
* @package StatusNet
|
|
|
|
*
|
|
|
|
* @author James Walker <james@status.net>
|
|
|
|
* @copyright 2010 StatusNet, Inc.
|
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
|
|
|
|
*
|
|
|
|
* @see http://status.net/
|
|
|
|
*/
|
|
|
|
abstract class LrddMethod
|
|
|
|
{
|
|
|
|
protected $xrd;
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->xrd = new XML_XRD();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Discover interesting info about the URI
|
|
|
|
*
|
|
|
|
* @param string $uri URI to inquire about
|
|
|
|
*
|
|
|
|
* @return array of XML_XRD_Element_Link elements to discovered resource descriptors
|
|
|
|
*/
|
|
|
|
abstract public function discover($uri);
|
|
|
|
|
2021-10-27 12:15:07 +09:00
|
|
|
protected function fetchUrl($url, $method = 'get'): ResponseInterface
|
2021-10-18 21:22:02 +09:00
|
|
|
{
|
|
|
|
// If we have a blacklist enabled, let's check against it
|
|
|
|
Event::handle('UrlBlacklistTest', [$url]);
|
|
|
|
|
2021-10-27 12:15:07 +09:00
|
|
|
$response = HTTPClient::$method($url);
|
2021-10-18 21:22:02 +09:00
|
|
|
|
2021-10-27 12:15:07 +09:00
|
|
|
if ($response->getStatusCode() !== 200) {
|
2021-10-18 21:22:02 +09:00
|
|
|
throw new Exception('Unexpected HTTP status code.');
|
|
|
|
}
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
}
|