luispabon / favicon-finder
PHP Library used to discover favicon from given URL
1.1.0
2021-11-17 18:18 UTC
Requires
- php: >=7.3.0
- ext-dom: *
- guzzlehttp/guzzle: ^6.4
- psr/simple-cache: ^1.0.1
Requires (Dev)
- guzzlehttp/psr7: ^1.6
- infection/infection: ^0.18
- phpstan/phpstan: ^1.0
- phpunit/phpunit: 9.3.*
- symfony/var-dumper: ^4.3
This package is auto-updated.
Last update: 2024-11-18 00:46:59 UTC
README
Favicon Finder
Simple PHP library to work out the favicon for a site, given an URL.
It currently supports finding the default favicon, if it exists on the host (eg /favicon.ico
) as well as some basic
HTML parsing of the homepage to hunt for standard favicon tags. Does not support apple
type icons or manifests,
although it can be extended to do so if necessary (PRs welcome).
This library is based on Arthur Hoaro's work.
Here are the changes you can see in this version:
- Only return favicon paths, when found
- PSR-16: Simple Cache support
- More extensive HTML scraping tests
- PHP 7.3+ support
Requirements
- PHP 7.3
- php-xml extension: parse HTML content
- php-curl
- Guzzle
- GNU Make (or compatible): This is optional, if you want to contribute and use the Makefile targets available for running tests
Installation
composer req luispabon/favicon-finder
Basic usage
require_once('vendor/autoload.php'); $guzzle = new \GuzzleHttp\Client(); // You can use any PSR-16 implementation here - if you have none and don't care // about caching, simply use the provided dummy cache implementation below $cache = new \FaviconFinder\DummyCache(); // Cache lifetime in seconds (default is 86400 or 1 day) $ttl = 60; $favicon = new \FaviconFinder\Favicon($guzzle, $cache, $ttl); echo $favicon->get('https://github.com/luispabon/favicon-finder'); // Displays: https://github.com/favicon.ico var_dump($favicon->get('http://nofavicon.tld')); // Returns null
Contributing
Fork this repo, do your stuff, send a PR. Tests are mandatory:
- PHP unit coverage must be 100%
- Infection MSI must be 100%
- PHPStan must show no errors
The provided Makefile has all the basic test targets and is what's in use in CI.