You are here

abstract class AvatarBase in Avatar Kit 8

Abstract class for Avatar APIs.

Hierarchy

Expanded class hierarchy of AvatarBase

3 files declare their use of AvatarBase
Adorable.php in avatars_adorable/src/Adorable.php
Gravatar.php in avatars_gravatar/src/Gravatar.php
Robohash.php in avatars_robohash/src/Robohash.php

File

src/AvatarBase.php, line 10

Namespace

Drupal\avatars
View source
abstract class AvatarBase implements AvatarBaseInterface {

  /**
   * Host name.
   *
   * @var string
   */
  protected $hostname;

  /**
   * Type.
   *
   * @var string
   */
  protected $type;

  /**
   * Identifier.
   *
   * @var string
   */
  protected $identifier;

  /**
   * Is Secure.
   *
   * @var bool
   */
  protected $secure;

  /**
   * Prehashed.
   *
   * @var bool|null
   */
  protected $prehashed;

  /**
   * Width.
   *
   * @var int
   */
  protected $width;

  /**
   * Height.
   *
   * @var int
   */
  protected $height;

  // @codingStandardsIgnoreStart

  /**
   * Maximum width of the avatar.
   *
   * @var int
   */
  protected $dimension_width_maximum;

  /**
   * Minimum width of the avatar.
   *
   * @var int
   */
  protected $dimension_width_minimum;

  /**
   * Maximum height of the avatar.
   *
   * @var int
   */
  protected $dimension_height_maximum;

  /**
   * Minimum height of the avatar.
   *
   * @var int
   */
  protected $dimension_height_minimum;

  // @codingStandardsIgnoreEnd

  /**
   * {@inheritdoc}
   */
  public function getHostName() {
    return $this->hostname;
  }

  /**
   * {@inheritdoc}
   */
  public function setHostName($hostname = NULL) {
    $this->hostname = $hostname;
  }

  /**
   * {@inheritdoc}
   */
  public function getType() {
    return $this->type;
  }

  /**
   * {@inheritdoc}
   */
  public function setType($type) {
    if (!array_key_exists($type, $this
      ->getTypes())) {
      throw new AvatarException('Invalid type');
    }
    $this->type = $type;
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function getIdentifier() {
    return $this->identifier;
  }

  /**
   * {@inheritdoc}
   */
  public function identifierIsPreHashed() {
    return $this->prehashed;
  }

  /**
   * {@inheritdoc}
   */
  public function setIdentifier($identifier, $pre_hashed = FALSE) {
    if (!is_scalar($identifier)) {
      throw new AvatarException('Invalid identifier');
    }
    $this->identifier = $identifier;
    $this->prehashed = $pre_hashed;
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function isSecure() {
    return $this->secure;
  }

  /**
   * {@inheritdoc}
   */
  public function setIsSecure($secure_request = TRUE) {
    $this->secure = $secure_request;
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function setDimensions($width, $height = NULL) {
    if ($this->dimension_width_maximum && $width > $this->dimension_width_maximum) {
      throw new AvatarException('Avatar width is too large.');
    }
    if ($this->dimension_width_minimum && $width < $this->dimension_width_minimum) {
      throw new AvatarException('Avatar width is too small.');
    }
    if ($this->dimension_height_maximum && $height > $this->dimension_height_maximum) {
      throw new AvatarException('Avatar height is too large.');
    }
    if ($this->dimension_height_minimum && $height < $this->dimension_height_minimum) {
      throw new AvatarException('Avatar height is too small.');
    }
    $this->width = $width;
    $this->height = $height === NULL ? $this->width : $height;
    return $this;
  }

  /**
   * Sets constraints for avatar dimensions.
   *
   * @param int $width_minimum
   *   The minimum width.
   * @param int $width_maximum
   *   The maximum width.
   * @param int|null $height_minimum
   *   The minimum height, or NULL to mirror minimum width.
   * @param int|null $height_maximum
   *   The maximum height, or NULL to mirror maximum width.
   */
  protected function setDimensionConstraints($width_minimum, $width_maximum, $height_minimum = NULL, $height_maximum = NULL) {
    $this->dimension_width_maximum = $width_maximum;
    $this->dimension_width_minimum = $width_minimum;
    $this->dimension_height_minimum = $height_minimum;
    $this->dimension_height_maximum = $height_maximum;
  }

  /**
   * {@inheritdoc}
   */
  public static function hashIdentifier($identifier) {
    return md5($identifier);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
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::getHostName public function Gets the request host name. Overrides AvatarBaseInterface::getHostName 3
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::setIsSecure public function Sets the request to secure. Overrides AvatarBaseInterface::setIsSecure 1
AvatarBase::setType public function Sets the avatar type. Overrides AvatarBaseInterface::setType
AvatarBaseInterface::getTypes public static function Gets list of avatar types provided by this API. 3
AvatarBaseInterface::getUrl public function Gets the URL for the avatar. 3