PHP code example of ashallendesign / favicon-fetcher
1. Go to this page and download the library: Download ashallendesign/favicon-fetcher 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/ */
ashallendesign / favicon-fetcher example snippets
use AshAllenDesign\FaviconFetcher\Facades\Favicon;
$favicon = Favicon::fetch('https://ashallendesign.co.uk');
use AshAllenDesign\FaviconFetcher\Facades\Favicon;
$favicon = Favicon::fetchOr('https://ashallendesign.co.uk', 'https://example.com/favicon.ico');
use AshAllenDesign\FaviconFetcher\Facades\Favicon;
$favicon = Favicon::fetchOr('https://ashallendesign.co.uk', function ($url) {
// Run extra logic here...
return 'https://example.com/favicon.ico';
});
use AshAllenDesign\FaviconFetcher\Facades\Favicon;
$favicons = Favicon::fetchAll('https://ashallendesign.co.uk');
use AshAllenDesign\FaviconFetcher\Facades\Favicon;
$largestFavicon = Favicon::fetchAll('https://ashallendesign.co.uk')->largest();
use AshAllenDesign\FaviconFetcher\Facades\Favicon;
$largestFavicon = Favicon::fetchAll('https://ashallendesign.co.uk')->largestByFileSize();
use AshAllenDesign\FaviconFetcher\Facades\Favicon;
$favicon = Favicon::fetchAllOr('https://ashallendesign.co.uk', 'https://example.com/favicon.ico');
use AshAllenDesign\FaviconFetcher\Facades\Favicon;
$favicon = Favicon::fetchAllOr('https://ashallendesign.co.uk', function ($url) {
// Run extra logic here...
return 'https://example.com/favicon.ico';
});
use AshAllenDesign\FaviconFetcher\Facades\Favicon;
$favicon = Favicon::throw()->fetch('https://ashallendesign.co.uk');
use AshAllenDesign\FaviconFetcher\Facades\Favicon;
$favicon = Favicon::driver('google-shared-stuff')->fetch('https://ashallendesign.co.uk');
use AshAllenDesign\FaviconFetcher\Facades\Favicon;
$favicon = Favicon::withFallback('google-shared-stuff')->fetch('https://ashallendesign.co.uk');
use AshAllenDesign\FaviconFetcher\Contracts\Fetcher;
use AshAllenDesign\FaviconFetcher\Favicon;
class MyCustomDriver implements Fetcher
{
public function fetch(string $url): ?Favicon
{
// Add logic here that attempts to fetch a favicon...
}
public function fetchOr(string $url, mixed $default): mixed
{
// Add logic here that attempts to fetch a favicon or return a default...
}
}
use AshAllenDesign\FaviconFetcher\Facades\Favicon;
Favicon::extend('my-custom-driver', new MyCustomDriver());
use AshAllenDesign\FaviconFetcher\Facades\Favicon;
$favicon = Favicon::driver('my-custom-driver')->fetch('https://ashallendesign.co.uk');
use AshAllenDesign\FaviconFetcher\Facades\Favicon;
$faviconPath = Favicon::fetch('https://ashallendesign.co.uk')->store('favicons');
// $faviconPath is now equal to: "/favicons/abc-123.ico"
use AshAllenDesign\FaviconFetcher\Facades\Favicon;
$faviconPath = Favicon::fetch('https://ashallendesign.co.uk')->store('favicons', 's3');
// $faviconPath is now equal to: "/favicons/abc-123.ico"
use AshAllenDesign\FaviconFetcher\Facades\Favicon;
$faviconPath = Favicon::fetch('https://ashallendesign.co.uk')->storeAs('favicons', 'ashallendesign');
// $faviconPath is now equal to: "/favicons/ashallendesign.ico"
use AshAllenDesign\FaviconFetcher\Facades\Favicon;
$faviconPath = Favicon::fetch('https://ashallendesign.co.uk')->storeAs('favicons', 'ashallendesign', 's3');
// $faviconPath is now equal to: "/favicons/ashallendesign.ico"
use AshAllenDesign\FaviconFetcher\Facades\Favicon;
$favicon = Favicon::fetch('https://ashallendesign.co.uk')->cache(now()->addDay());
use AshAllenDesign\FaviconFetcher\Facades\Favicon;
$favicon = Favicon::useCache(false)->fetch('https://ashallendesign.co.uk');