2017 © Pedro PelĆ”ez
 

symfony-bundle avatar-bundle

Symfony2 bundle for getting and displaying user's avatar

image

maba/avatar-bundle

Symfony2 bundle for getting and displaying user's avatar

  • Monday, July 27, 2015
  • by mariusbalcytis
  • Repository
  • 1 Watchers
  • 0 Stars
  • 532 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Avatar bundle

What's that?

Symfony2 bundle to get avatar image for given email., (*1)

It lets to register additional avatar providers so that most appropriate avatar can be selected., (*2)

It includes one default avatar provider - GravatarProvider., (*3)

Installing

composer require maba/avatar-bundle

Inside AppKernel::registerBundles:, (*4)

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

  1. Make class which implements Maba\Bundle\AvatarBundle\Service\AvatarProviderInterface.
  2. Register it as a service.
  3. Add tag maba_avatar.avatar_provider to that service.
  4. Optionally provide priority attribute to that tag. Smallest number means provider will be called first. GravatarProvider has priority 9000, but always returns URI, so your priorities should be smaller than that. If not provided, defaults to 0.

Example:, (*5)

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

Travis status Coverage Status, (*6)

composer install
vendor/bin/phpunit

The Versions

27/07 2015

dev-master

9999999-dev

Symfony2 bundle for getting and displaying user's avatar

  Sources   Download

MIT

The Requires

 

The Development Requires

by Marius Balčytis

symfony2 avatar gravatar avatar bundle

26/07 2015

0.1.0

0.1.0.0

Symfony2 bundle for getting and displaying user's avatar

  Sources   Download

MIT

The Requires

 

The Development Requires

by Marius Balčytis

symfony2 avatar gravatar avatar bundle