You are here

class Adorable in Avatar Kit 8

Same name in this branch
  1. 8 avatars_adorable/src/Adorable.php \Drupal\avatars_adorable\Adorable
  2. 8 avatars_adorable/src/Plugin/AvatarGenerator/Adorable.php \Drupal\avatars_adorable\Plugin\AvatarGenerator\Adorable

Implements the Adorable.io API.

Hierarchy

Expanded class hierarchy of Adorable

1 file declares its use of Adorable
Adorable.php in avatars_adorable/src/Plugin/AvatarGenerator/Adorable.php
1 string reference to 'Adorable'
avatars_adorable.info.yml in avatars_adorable/avatars_adorable.info.yml
avatars_adorable/avatars_adorable.info.yml

File

avatars_adorable/src/Adorable.php, line 11

Namespace

Drupal\avatars_adorable
View source
class Adorable extends AvatarBase implements AdorableInterface {

  /**
   * Constructs a new Adorable object.
   */
  public function __construct() {
    $this
      ->setDimensionConstraints(Adorable::DIMENSION_MINIMUM_WIDTH, Adorable::DIMENSION_MAXIMUM_WIDTH);
  }

  /**
   * {@inheritdoc}
   */
  public function getHostName() {
    $hostname = parent::getHostName();
    return isset($hostname) ? $hostname : $this::ADORABLE_HOSTNAME;
  }

  /**
   * {@inheritdoc}
   */
  public static function getTypes() {
    return [
      'adorable' => 'Adorables',
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function setIsSecure($secure_request = TRUE) {
    if ($secure_request) {
      throw new AvatarException('Adorable does not support secure requests.');
    }
    return parent::setIsSecure($secure_request);
  }

  /**
   * {@inheritdoc}
   */
  public function getUrl() {
    $url = ($this
      ->isSecure() ? 'https://' : 'http://') . $this
      ->getHostName() . '/avatars/';

    // Width can be omitted.
    if (is_numeric($this->width)) {
      $url .= $this->width . '/';
    }
    $identifier = $this
      ->getIdentifier();
    if (!strlen($identifier)) {
      throw new AvatarException('Missing avatar identifier/hash');
    }
    $url .= $this
      ->identifierIsPreHashed() ? $identifier : $this
      ->hashIdentifier($identifier);
    return $url;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Adorable::getHostName public function Gets the request host name. Overrides AvatarBase::getHostName
Adorable::getTypes public static function Gets list of avatar types provided by this API. Overrides AvatarBaseInterface::getTypes
Adorable::getUrl public function Gets the URL for the avatar. Overrides AvatarBaseInterface::getUrl
Adorable::setIsSecure public function Sets the request to secure. Overrides AvatarBase::setIsSecure
Adorable::__construct public function Constructs a new Adorable object.
AdorableInterface::ADORABLE_HOSTNAME constant
AdorableInterface::DIMENSION_MAXIMUM_WIDTH constant
AdorableInterface::DIMENSION_MINIMUM_WIDTH constant
AvatarBase::$dimension_height_maximum protected property Maximum height of the avatar.
AvatarBase::$dimension_height_minimum protected property Minimum height of the avatar.
AvatarBase::$dimension_width_maximum protected property Maximum width of the avatar.
AvatarBase::$dimension_width_minimum protected property Minimum width of the avatar.
AvatarBase::$height protected property Height.
AvatarBase::$hostname protected property Host name.
AvatarBase::$identifier protected property Identifier.
AvatarBase::$prehashed protected property Prehashed.
AvatarBase::$secure protected property Is Secure.
AvatarBase::$type protected property Type.
AvatarBase::$width protected property Width.
AvatarBase::getIdentifier public function Gets the identifier. Overrides AvatarBaseInterface::getIdentifier
AvatarBase::getType public function Gets the avatar type. Overrides AvatarBaseInterface::getType
AvatarBase::hashIdentifier public static function Prepare an identifier for transmission to a third party. Overrides AvatarBaseInterface::hashIdentifier 1
AvatarBase::identifierIsPreHashed public function Determines if the set identifier was prehashed. Overrides AvatarBaseInterface::identifierIsPreHashed
AvatarBase::isSecure public function Whether the URL will be secure. Overrides AvatarBaseInterface::isSecure
AvatarBase::setDimensionConstraints protected function Sets constraints for avatar dimensions.
AvatarBase::setDimensions public function Sets dimensions to get form the endpoint. Overrides AvatarBaseInterface::setDimensions
AvatarBase::setHostName public function Sets the request host name. Overrides AvatarBaseInterface::setHostName
AvatarBase::setIdentifier public function Sets a unique identifier to be passed to the API. Overrides AvatarBaseInterface::setIdentifier 1
AvatarBase::setType public function Sets the avatar type. Overrides AvatarBaseInterface::setType