mrgoodbytes8667/avatar-bundle

A Symfony bundle for avatar caching

Installs: 1 807

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 1

Type:symfony-bundle

v0.10.2 2023-04-24 16:10 UTC

README

Packagist Version PHP from Packagist Symfony Versions Supported Symfony Versions Tested Symfony LTS Version Symfony Stable Version Symfony Dev Version Packagist License
GitHub Workflow Status GitHub Workflow Status GitHub Workflow Status codecov
A Symfony bundle for avatar caching

Installation

Make sure Composer is installed globally, as explained in the installation chapter of the Composer documentation.

All applications

Add the Multiavatar repo to your composer.json file.

"repositories": [
     {
       "type": "vcs",
       "url":  "https://github.com/bakame-php/multiavatar-php.git"
   }
]

Applications that use Symfony Flex

Open a command console, enter your project directory and execute:

$ composer require mrgoodbytes8667/avatar-bundle

Applications that don't use Symfony Flex

Step 1: Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

$ composer require mrgoodbytes8667/avatar-bundle

Step 2: Enable the Bundle

Then, enable the bundle by adding it to the list of registered bundles in the config/bundles.php file of your project:

// config/bundles.php

return [
    // ...
    Bytes\AvatarBundle\BytesAvatarBundle::class => ['all' => true],
];

All applications

Create a routing file named config\routes\bytes_avatar.yaml with the content below, changing the prefix value to whatever you want the routes changed to.

_bytes_avatar:
  resource: '@BytesAvatarBundle/Resources/config/routing.php'
  prefix: /avatar

Create a config file named config\packages\bytes_avatar.yaml with the content below.

bytes_avatar:
  multiavatar: ~

Sample implementation for a User entity that already has a required email field:

<?php

use Doctrine\ORM\Mapping as ORM;
use Bytes\AvatarBundle\Avatar\Gravatar;

/**
 * @var string|null
 * @ORM\Column(type="string", length=3000, nullable=true)
 */
private $avatar;

/**
 * @return string|null
 */
public function getAvatar(): ?string
{
    return $this->avatar;
}

/**
 * @param string|null $avatar
 * @return $this
 */
public function setAvatar(?string $avatar): self
{
    $this->avatar = $avatar;

    return $this;
}

/**
 * @param int $size
 * @return string
 */
public function getGravatar(int $size = 80)
{
    return Gravatar::url($this->email, $size);
}

License

License
avatar-bundle by MrGoodBytes is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.
Based on a work at https://github.com/mrgoodbytes8667/avatar-bundle.