Use native typing in more places and clean up 'FeedEnclosure' a bit.
This commit is contained in:
@@ -14,8 +14,7 @@ class API extends Handler {
|
|||||||
const E_OPERATION_FAILED = "E_OPERATION_FAILED";
|
const E_OPERATION_FAILED = "E_OPERATION_FAILED";
|
||||||
const E_NOT_FOUND = "E_NOT_FOUND";
|
const E_NOT_FOUND = "E_NOT_FOUND";
|
||||||
|
|
||||||
/** @var int|null */
|
private ?int $seq = null;
|
||||||
private $seq;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array<int|string, mixed> $reply
|
* @param array<int|string, mixed> $reply
|
||||||
|
|||||||
@@ -252,17 +252,15 @@ class Config {
|
|||||||
Config::HTTP_429_THROTTLE_INTERVAL => [ 3600, Config::T_INT ]
|
Config::HTTP_429_THROTTLE_INTERVAL => [ 3600, Config::T_INT ]
|
||||||
];
|
];
|
||||||
|
|
||||||
/** @var Config|null */
|
private static ?Config $instance = null;
|
||||||
private static $instance;
|
|
||||||
|
|
||||||
/** @var array<string, array<bool|int|string>> */
|
/** @var array<string, array<bool|int|string>> */
|
||||||
private $params = [];
|
private array $params = [];
|
||||||
|
|
||||||
/** @var array<string, mixed> */
|
/** @var array<string, mixed> */
|
||||||
private $version = [];
|
private array $version = [];
|
||||||
|
|
||||||
/** @var Db_Migrations|null $migrations */
|
private Db_Migrations $migrations;
|
||||||
private $migrations;
|
|
||||||
|
|
||||||
public static function get_instance() : Config {
|
public static function get_instance() : Config {
|
||||||
if (self::$instance == null)
|
if (self::$instance == null)
|
||||||
|
|||||||
@@ -1,11 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
class Db
|
class Db {
|
||||||
{
|
private static ?Db $instance = null;
|
||||||
/** @var Db $instance */
|
|
||||||
private static $instance;
|
|
||||||
|
|
||||||
/** @var PDO|null $pdo */
|
private ?PDO $pdo = null;
|
||||||
private $pdo;
|
|
||||||
|
|
||||||
function __construct() {
|
function __construct() {
|
||||||
ORM::configure(self::get_dsn());
|
ORM::configure(self::get_dsn());
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
class DiskCache implements Cache_Adapter {
|
class DiskCache implements Cache_Adapter {
|
||||||
/** @var Cache_Adapter $adapter */
|
private Cache_Adapter $adapter;
|
||||||
private $adapter;
|
|
||||||
|
|
||||||
/** @var array<string, DiskCache> $instances */
|
/** @var array<string, DiskCache> $instances */
|
||||||
private static $instances = [];
|
private static array $instances = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* https://stackoverflow.com/a/53662733
|
* https://stackoverflow.com/a/53662733
|
||||||
|
|||||||
@@ -1,21 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
class FeedEnclosure {
|
class FeedEnclosure {
|
||||||
/** @var string */
|
function __construct(
|
||||||
public $link;
|
public string $link = '',
|
||||||
|
public string $type = '',
|
||||||
/** @var string */
|
public string $length = '',
|
||||||
public $type;
|
public string $title = '',
|
||||||
|
public string $height = '',
|
||||||
/** @var string */
|
public string $width = '',
|
||||||
public $length;
|
) {}
|
||||||
|
|
||||||
/** @var string */
|
|
||||||
public $title;
|
|
||||||
|
|
||||||
/** @var string */
|
|
||||||
public $height;
|
|
||||||
|
|
||||||
/** @var string */
|
|
||||||
public $width;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -184,11 +184,11 @@ class FeedItem_Atom extends FeedItem_Common {
|
|||||||
$base = $this->xpath->evaluate("string(ancestor-or-self::*[@xml:base][1]/@xml:base)", $link);
|
$base = $this->xpath->evaluate("string(ancestor-or-self::*[@xml:base][1]/@xml:base)", $link);
|
||||||
|
|
||||||
if ($link->getAttribute("rel") == "enclosure") {
|
if ($link->getAttribute("rel") == "enclosure") {
|
||||||
$enc = new FeedEnclosure();
|
$enc = new FeedEnclosure(
|
||||||
|
type: clean($link->getAttribute('type')),
|
||||||
$enc->type = clean($link->getAttribute("type"));
|
length: clean($link->getAttribute('length')),
|
||||||
$enc->length = clean($link->getAttribute("length"));
|
link: clean($link->getAttribute('href')),
|
||||||
$enc->link = clean($link->getAttribute("href"));
|
);
|
||||||
|
|
||||||
if (!empty($base)) {
|
if (!empty($base)) {
|
||||||
$enc->link = UrlHelper::rewrite_relative($base, $enc->link);
|
$enc->link = UrlHelper::rewrite_relative($base, $enc->link);
|
||||||
|
|||||||
@@ -1,19 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
abstract class FeedItem_Common extends FeedItem {
|
abstract class FeedItem_Common extends FeedItem {
|
||||||
/** @var DOMElement */
|
function __construct(
|
||||||
protected $elem;
|
protected readonly DOMElement $elem,
|
||||||
|
protected readonly DOMDocument $doc,
|
||||||
/** @var DOMDocument */
|
protected readonly DOMXPath $xpath,
|
||||||
protected $doc;
|
) {
|
||||||
|
|
||||||
/** @var DOMXPath */
|
|
||||||
protected $xpath;
|
|
||||||
|
|
||||||
function __construct(DOMElement $elem, DOMDocument $doc, DOMXPath $xpath) {
|
|
||||||
$this->elem = $elem;
|
|
||||||
$this->xpath = $xpath;
|
|
||||||
$this->doc = $doc;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$source = $elem->getElementsByTagName("source")->item(0);
|
$source = $elem->getElementsByTagName("source")->item(0);
|
||||||
|
|
||||||
@@ -97,13 +88,13 @@ abstract class FeedItem_Common extends FeedItem {
|
|||||||
$enclosures = $this->xpath->query("media:content", $this->elem);
|
$enclosures = $this->xpath->query("media:content", $this->elem);
|
||||||
|
|
||||||
foreach ($enclosures as $enclosure) {
|
foreach ($enclosures as $enclosure) {
|
||||||
$enc = new FeedEnclosure();
|
$enc = new FeedEnclosure(
|
||||||
|
type: clean($enclosure->getAttribute('type')),
|
||||||
$enc->type = clean($enclosure->getAttribute("type"));
|
link: clean($enclosure->getAttribute('url')),
|
||||||
$enc->link = clean($enclosure->getAttribute("url"));
|
length: clean($enclosure->getAttribute('length')),
|
||||||
$enc->length = clean($enclosure->getAttribute("length"));
|
height: clean($enclosure->getAttribute('height')),
|
||||||
$enc->height = clean($enclosure->getAttribute("height"));
|
width: clean($enclosure->getAttribute('width')),
|
||||||
$enc->width = clean($enclosure->getAttribute("width"));
|
);
|
||||||
|
|
||||||
$medium = clean($enclosure->getAttribute("medium"));
|
$medium = clean($enclosure->getAttribute("medium"));
|
||||||
if (!$enc->type && $medium) {
|
if (!$enc->type && $medium) {
|
||||||
@@ -119,17 +110,17 @@ abstract class FeedItem_Common extends FeedItem {
|
|||||||
$enclosures = $this->xpath->query("media:group", $this->elem);
|
$enclosures = $this->xpath->query("media:group", $this->elem);
|
||||||
|
|
||||||
foreach ($enclosures as $enclosure) {
|
foreach ($enclosures as $enclosure) {
|
||||||
$enc = new FeedEnclosure();
|
|
||||||
|
|
||||||
/** @var DOMElement|null */
|
/** @var DOMElement|null */
|
||||||
$content = $this->xpath->query("media:content", $enclosure)->item(0);
|
$content = $this->xpath->query("media:content", $enclosure)->item(0);
|
||||||
|
|
||||||
if ($content) {
|
if ($content) {
|
||||||
$enc->type = clean($content->getAttribute("type"));
|
$enc = new FeedEnclosure(
|
||||||
$enc->link = clean($content->getAttribute("url"));
|
type: clean($content->getAttribute('type')),
|
||||||
$enc->length = clean($content->getAttribute("length"));
|
link: clean($content->getAttribute('url')),
|
||||||
$enc->height = clean($content->getAttribute("height"));
|
length: clean($content->getAttribute('length')),
|
||||||
$enc->width = clean($content->getAttribute("width"));
|
height: clean($content->getAttribute('height')),
|
||||||
|
width: clean($content->getAttribute('width')),
|
||||||
|
);
|
||||||
|
|
||||||
$medium = clean($content->getAttribute("medium"));
|
$medium = clean($content->getAttribute("medium"));
|
||||||
if (!$enc->type && $medium) {
|
if (!$enc->type && $medium) {
|
||||||
@@ -151,14 +142,12 @@ abstract class FeedItem_Common extends FeedItem {
|
|||||||
$enclosures = $this->xpath->query("media:thumbnail", $this->elem);
|
$enclosures = $this->xpath->query("media:thumbnail", $this->elem);
|
||||||
|
|
||||||
foreach ($enclosures as $enclosure) {
|
foreach ($enclosures as $enclosure) {
|
||||||
$enc = new FeedEnclosure();
|
$encs[] = new FeedEnclosure(
|
||||||
|
type: 'image/generic',
|
||||||
$enc->type = "image/generic";
|
link: clean($enclosure->getAttribute('url')),
|
||||||
$enc->link = clean($enclosure->getAttribute("url"));
|
height: clean($enclosure->getAttribute('height')),
|
||||||
$enc->height = clean($enclosure->getAttribute("height"));
|
width: clean($enclosure->getAttribute('width')),
|
||||||
$enc->width = clean($enclosure->getAttribute("width"));
|
);
|
||||||
|
|
||||||
array_push($encs, $enc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $encs;
|
return $encs;
|
||||||
|
|||||||
@@ -141,15 +141,13 @@ class FeedItem_RSS extends FeedItem_Common {
|
|||||||
$encs = array();
|
$encs = array();
|
||||||
|
|
||||||
foreach ($enclosures as $enclosure) {
|
foreach ($enclosures as $enclosure) {
|
||||||
$enc = new FeedEnclosure();
|
$encs[] = new FeedEnclosure(
|
||||||
|
type: clean($enclosure->getAttribute('type')),
|
||||||
$enc->type = clean($enclosure->getAttribute("type"));
|
link: clean($enclosure->getAttribute('url')),
|
||||||
$enc->link = clean($enclosure->getAttribute("url"));
|
length: clean($enclosure->getAttribute('length')),
|
||||||
$enc->length = clean($enclosure->getAttribute("length"));
|
height: clean($enclosure->getAttribute('height')),
|
||||||
$enc->height = clean($enclosure->getAttribute("height"));
|
width: clean($enclosure->getAttribute('width')),
|
||||||
$enc->width = clean($enclosure->getAttribute("width"));
|
);
|
||||||
|
|
||||||
array_push($encs, $enc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
array_push($encs, ...parent::get_enclosures());
|
array_push($encs, ...parent::get_enclosures());
|
||||||
|
|||||||
@@ -1,29 +1,23 @@
|
|||||||
<?php
|
<?php
|
||||||
class FeedParser {
|
class FeedParser {
|
||||||
|
private DOMDocument $doc;
|
||||||
|
|
||||||
/** @var DOMDocument */
|
private ?string $error = null;
|
||||||
private $doc;
|
|
||||||
|
|
||||||
/** @var string|null */
|
|
||||||
private $error = null;
|
|
||||||
|
|
||||||
/** @var array<string> */
|
/** @var array<string> */
|
||||||
private $libxml_errors = [];
|
private array $libxml_errors = [];
|
||||||
|
|
||||||
/** @var array<FeedItem> */
|
/** @var array<FeedItem> */
|
||||||
private $items = [];
|
private array $items = [];
|
||||||
|
|
||||||
/** @var string|null */
|
private ?string $link = null;
|
||||||
private $link;
|
|
||||||
|
|
||||||
/** @var string|null */
|
private ?string $title = null;
|
||||||
private $title;
|
|
||||||
|
|
||||||
/** @var FeedParser::FEED_*|null */
|
/** @var FeedParser::FEED_*|null */
|
||||||
private $type;
|
private ?int $type = null;
|
||||||
|
|
||||||
/** @var DOMXPath|null */
|
private ?DOMXPath $xpath = null;
|
||||||
private $xpath;
|
|
||||||
|
|
||||||
const FEED_UNKNOWN = -1;
|
const FEED_UNKNOWN = -1;
|
||||||
const FEED_RDF = 0;
|
const FEED_RDF = 0;
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
class Logger {
|
class Logger {
|
||||||
/** @var Logger|null */
|
private static ?Logger $instance = null;
|
||||||
private static $instance;
|
|
||||||
|
|
||||||
/** @var Logger_Adapter|null */
|
private ?Logger_Adapter $adapter = null;
|
||||||
private $adapter;
|
|
||||||
|
|
||||||
const LOG_DEST_SQL = "sql";
|
const LOG_DEST_SQL = "sql";
|
||||||
const LOG_DEST_STDOUT = "stdout";
|
const LOG_DEST_STDOUT = "stdout";
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ class Pref_Filters extends Handler_Protected {
|
|||||||
const MAX_ACTIONS_TO_DISPLAY = 3;
|
const MAX_ACTIONS_TO_DISPLAY = 3;
|
||||||
|
|
||||||
/** @var array<int,array<mixed>> $action_descriptions */
|
/** @var array<int,array<mixed>> $action_descriptions */
|
||||||
private $action_descriptions = [];
|
private array $action_descriptions = [];
|
||||||
|
|
||||||
function before(string $method) : bool {
|
function before(string $method) : bool {
|
||||||
|
|
||||||
|
|||||||
@@ -144,14 +144,12 @@ class Prefs {
|
|||||||
Prefs::_PREFS_MIGRATED
|
Prefs::_PREFS_MIGRATED
|
||||||
];
|
];
|
||||||
|
|
||||||
/** @var Prefs|null */
|
private static ?Prefs $instance = null;
|
||||||
private static $instance;
|
|
||||||
|
|
||||||
/** @var array<string, bool|int|string> */
|
/** @var array<string, bool|int|string> */
|
||||||
private $cache = [];
|
private array $cache = [];
|
||||||
|
|
||||||
/** @var PDO */
|
private ?PDO $pdo = null;
|
||||||
private $pdo;
|
|
||||||
|
|
||||||
public static function get_instance() : Prefs {
|
public static function get_instance() : Prefs {
|
||||||
if (self::$instance == null)
|
if (self::$instance == null)
|
||||||
|
|||||||
@@ -3,12 +3,8 @@ use PHPUnit\Framework\TestCase;
|
|||||||
|
|
||||||
/** @group integration */
|
/** @group integration */
|
||||||
final class ApiTest extends TestCase {
|
final class ApiTest extends TestCase {
|
||||||
|
private string $api_url;
|
||||||
/** @var string */
|
private string $sid;
|
||||||
private $api_url;
|
|
||||||
|
|
||||||
/** @var string */
|
|
||||||
private $sid;
|
|
||||||
|
|
||||||
function __construct() {
|
function __construct() {
|
||||||
$this->api_url = getenv('API_URL');
|
$this->api_url = getenv('API_URL');
|
||||||
|
|||||||
Reference in New Issue
Block a user