PHP code example of kaishiyoku / hera-rss-crawler

1. Go to this page and download the library: Download kaishiyoku/hera-rss-crawler library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kaishiyoku / hera-rss-crawler example snippets


setRetryCount(int $retryCount): void

setLogger(LoggerInterface $logger): void

setUrlReplacementMap(array $urlReplacementMap): void

setFeedDiscoverers(Collection $feedDiscoverers): void



namespace Kaishiyoku\HeraRssCrawler\FeedDiscoverers;

use GuzzleHttp\Client;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use Kaishiyoku\HeraRssCrawler\Models\ResponseContainer;

/**
 * Discover feed URL by parsing a direct RSS feed url.
 */
class FeedDiscovererByContentType implements FeedDiscoverer
{
    public function discover(Client $httpClient, ResponseContainer $responseContainer): Collection
    {
        $contentTypeMixedValue = Arr::get($responseContainer->getResponse()->getHeaders(), 'Content-Type');

        $contentType = is_array($contentTypeMixedValue) ? Arr::first($contentTypeMixedValue) : $contentTypeMixedValue;

        // the given url is no valid RSS feed
        if (!$contentType || !Str::startsWith($contentType, ['application/rss+xml', 'application/atom+xml'])) {
            return new Collection();
        }

        return new Collection([$responseContainer->getRequestUrl()]);
    }
}

new Collection([
    new FeedDiscovererByContentType(),
    new FeedDiscovererByHtmlHeadElements(),
    new FeedDiscovererByHtmlAnchorElements(),
    new FeedDiscovererByFeedly(),
])

parseFeed(string $url): ?Feed

discoverAndParseFeeds(string $url): Collection

discoverFeedUrls(string $url): Collection

discoverFavicon(string $url): ?string

checkIfConsumableFeed(string $url): bool