Skip to content

Commit

Permalink
remove deps: laminas/laminas-http
Browse files Browse the repository at this point in the history
  • Loading branch information
fetus-hina committed Nov 16, 2024
1 parent 08d91f1 commit 0715c88
Show file tree
Hide file tree
Showing 4 changed files with 710 additions and 781 deletions.
16 changes: 16 additions & 0 deletions commands/BlogFeedController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
namespace app\commands;

use Exception;
use GuzzleHttp\Client as GuzzleHttpClient;
use Laminas\Feed\Reader\Http\ClientInterface as FeedReaderHttpClientInterface;
use Laminas\Feed\Reader\Http\Psr7ResponseDecorator;
use Laminas\Feed\Reader\Reader as FeedReader;
use TypeError;
use Yii;
Expand All @@ -20,6 +23,7 @@
use jp3cki\uuid\Uuid;
use yii\console\Controller;

use function count;
use function preg_match;
use function printf;
use function usort;
Expand All @@ -39,6 +43,16 @@ public function actionCrawl()
private function fetchFeed()
{
echo "Fetching feed...\n";
FeedReader::setHttpClient(
new class () implements FeedReaderHttpClientInterface {
public function get($uri)
{
return new Psr7ResponseDecorator(
(new GuzzleHttpClient())->request('GET', $uri),
);
}
},
);
$feed = FeedReader::import('https://blog.fetus.jp/category/website/stat-ink/feed');
echo "done.\n";
$ret = [];
Expand All @@ -49,6 +63,8 @@ private function fetchFeed()
$ret[] = $entry;
}
usort($ret, fn ($a, $b) => $a->getDateCreated()->getTimestamp() <=> $b->getDateCreated()->getTimestamp());
printf("%d entries\n", count($ret));

return $ret;
}

Expand Down
4 changes: 2 additions & 2 deletions components/helpers/TypeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ public static function floatOrNull(mixed $value): ?float
public static function url(mixed $value): string
{
$value = filter_var(
self::string($value);
self::string($value),
FILTER_VALIDATE_URL,
FILTER_FLAG_SCHEME_REQUIRED | FILTER_FLAG_HOST_REQUIRED | FILTER_FLAG_PATH_REQUIRED,
FILTER_FLAG_PATH_REQUIRED,
);
return match (true) {
is_string($value) => $value,
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"ext-zlib": "*",
"cweagans/composer-patches": "^1.7.3",
"geoip2/geoip2": "^3.1.0",
"guzzlehttp/guzzle": "^7.9.2",
"jaybizzle/crawler-detect": "^1.2.121",
"jp3cki/mb_str_replace": "^4.0.2",
"jp3cki/uuid": "^4.0.1",
Expand All @@ -30,7 +31,6 @@
"jp3cki/yii2-twitter-widget": "^1.0",
"jp3cki/yii2-zxcvbn": "^1.0",
"laminas/laminas-feed": "^2.23.0",
"laminas/laminas-http": "^2.20",
"lipis/flag-icons": "^7.2.3",
"lusitanian/oauth": "^0.8.11",
"markrogoyski/math-php": "^2.10.0",
Expand Down
Loading

0 comments on commit 0715c88

Please sign in to comment.