mheap / silex-gravatar
Gravatar extension for Silex
Installs: 3 922
Dependents: 0
Suggesters: 0
Security: 0
Stars: 6
Watchers: 2
Forks: 2
Open Issues: 0
Requires
- php: >=7.0
- se/gravatar-php: ^2.0
Requires (Dev)
- phpunit/phpunit: ^6
- silex/silex: 2.*
- squizlabs/php_codesniffer: ^3.1
- twig/twig: >=1.2.0
Suggests
- twig/twig: >=1.2.0
This package is auto-updated.
Last update: 2020-11-26 18:08:57 UTC
README
Requirements
This extension only works with PHP 7.1+ and Silex 2. Version 1.1.0 is compatible with Silex 1.
Installation
Install with composer:
composer require mheap/silex-gravatar
Usage
First, you need to register the Gravatar extension. All of the options shown are optional.
$app->register(new SilexExtension\GravatarExtension(), array( 'gravatar.cache_dir' => sys_get_temp_dir() . '/gravatar', 'gravatar.cache_ttl' => 240, // 240 seconds 'gravatar.options' => array( 'size' => 100, 'rating' => Gravatar\Service::RATING_G, 'secure' => true, 'default' => Gravatar\Service::DEFAULT_404, 'force_default' => true ) ));
To fetch a Gravatar URL, use $app['gravatar']
:
$app->get('/', function() use($app) { return $app['gravatar']->get('m@michaelheap.com'); });
If you're using Twig via Silex\Provider\TwigServiceProvider()
, a gravatar
function will
be automatically registered for you. This allows you do do the following:
{% if gravatar_exist('m@michaelheap.com') %} Gravatar found {% endif %} <img src="{{ gravatar('m@michaelheap.com', {'size': 50}) }}" />
Available configuration options
The GravatarExtension provides access to the Gravatar web service
through Sven Eisenschmidts's Gravatar <https://github.com/fate/Gravatar-php>
_
library.
- gravatar.cache_dir (optional): A directory to cache the direct web service calls to gravatar.com
- gravatar.cache_ttl (optional): The time how long a cache entry will live, defaults to 360 seconds
- gravatar.options (optional): An associative array of arguments for the Gravatar\Service class
Running the tests
There are no external dependencies for this library. Just composer install
then run ./vendor/bin/phpunit