maba / avatar-bundle
Symfony2 bundle for getting and displaying user's avatar
Installs: 543
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 1
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=5.3.2
- maba/dependency-injection-extra: ^0.1
- symfony/framework-bundle: ^2.3
Requires (Dev)
- phpunit/phpunit: ~4.0
- symfony/browser-kit: 2.3
- symfony/filesystem: 2.3
- symfony/twig-bundle: ^2.3
Suggests
- symfony/twig-bundle: ^2.3
This package is auto-updated.
Last update: 2024-11-10 20:47:36 UTC
README
What's that?
Symfony2 bundle to get avatar image for given email.
It lets to register additional avatar providers so that most appropriate avatar can be selected.
It includes one default avatar provider - GravatarProvider
.
Installing
composer require maba/avatar-bundle
Inside AppKernel::registerBundles
:
new Maba\Bundle\AvatarBundle\MabaAvatarBundle(),
Configuring
maba_avatar: default_uri: /assets/unknown.png # defaults to ~ default_size: 50 gravatar: enabled: true secure: false force_default: false default: mm # one of mm, 404, identicon, monsterid, wavatar, retro, blank # ignored if default_uri is set rating: ~ # one of g, pg, r, x
Adding avatar provider
- Make class which implements
Maba\Bundle\AvatarBundle\Service\AvatarProviderInterface
. - Register it as a service.
- Add tag
maba_avatar.avatar_provider
to that service. - Optionally provide
priority
attribute to that tag. Smallest number means provider will be called first.GravatarProvider
haspriority
9000
, but always returns URI, so your priorities should be smaller than that. If not provided, defaults to0
.
Example:
namespace Acme; use Maba\Bundle\AvatarBundle\Service\AvatarProviderInterface; class MyAvatarProvider implements AvatarProviderInterface { // ... public function getAvatar($email, $size) { $user = $this->repository->findOneByEmail($email); if ($user === null) { // we don't have avatar - other providers will by called by priority return null; } return $this->avatarPath . $user->getAvatar(); } // ... }
<service id="acme.my_avatar_provider" class="Acme\MyAvatarProvider"> <tag name="maba_avatar.avatar_provider" priority="0"/> <!-- any other configuration --> </service>
Running tests
composer install vendor/bin/phpunit