abstract class AvatarBase in Avatar Kit 8
Abstract class for Avatar APIs.
Hierarchy
- class \Drupal\avatars\AvatarBase implements AvatarBaseInterface
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\avatarsView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AvatarBase:: |
protected | property | Maximum height of the avatar. | |
AvatarBase:: |
protected | property | Minimum height of the avatar. | |
AvatarBase:: |
protected | property | Maximum width of the avatar. | |
AvatarBase:: |
protected | property | Minimum width of the avatar. | |
AvatarBase:: |
protected | property | Height. | |
AvatarBase:: |
protected | property | Host name. | |
AvatarBase:: |
protected | property | Identifier. | |
AvatarBase:: |
protected | property | Prehashed. | |
AvatarBase:: |
protected | property | Is Secure. | |
AvatarBase:: |
protected | property | Type. | |
AvatarBase:: |
protected | property | Width. | |
AvatarBase:: |
public | function |
Gets the request host name. Overrides AvatarBaseInterface:: |
3 |
AvatarBase:: |
public | function |
Gets the identifier. Overrides AvatarBaseInterface:: |
|
AvatarBase:: |
public | function |
Gets the avatar type. Overrides AvatarBaseInterface:: |
|
AvatarBase:: |
public static | function |
Prepare an identifier for transmission to a third party. Overrides AvatarBaseInterface:: |
1 |
AvatarBase:: |
public | function |
Determines if the set identifier was prehashed. Overrides AvatarBaseInterface:: |
|
AvatarBase:: |
public | function |
Whether the URL will be secure. Overrides AvatarBaseInterface:: |
|
AvatarBase:: |
protected | function | Sets constraints for avatar dimensions. | |
AvatarBase:: |
public | function |
Sets dimensions to get form the endpoint. Overrides AvatarBaseInterface:: |
|
AvatarBase:: |
public | function |
Sets the request host name. Overrides AvatarBaseInterface:: |
|
AvatarBase:: |
public | function |
Sets a unique identifier to be passed to the API. Overrides AvatarBaseInterface:: |
1 |
AvatarBase:: |
public | function |
Sets the request to secure. Overrides AvatarBaseInterface:: |
1 |
AvatarBase:: |
public | function |
Sets the avatar type. Overrides AvatarBaseInterface:: |
|
AvatarBaseInterface:: |
public static | function | Gets list of avatar types provided by this API. | 3 |
AvatarBaseInterface:: |
public | function | Gets the URL for the avatar. | 3 |