View source
<?php
namespace Drupal\avatars;
use Drupal\avatars\Exception\AvatarException;
abstract class AvatarBase implements AvatarBaseInterface {
protected $hostname;
protected $type;
protected $identifier;
protected $secure;
protected $prehashed;
protected $width;
protected $height;
protected $dimension_width_maximum;
protected $dimension_width_minimum;
protected $dimension_height_maximum;
protected $dimension_height_minimum;
public function getHostName() {
return $this->hostname;
}
public function setHostName($hostname = NULL) {
$this->hostname = $hostname;
}
public function getType() {
return $this->type;
}
public function setType($type) {
if (!array_key_exists($type, $this
->getTypes())) {
throw new AvatarException('Invalid type');
}
$this->type = $type;
return $this;
}
public function getIdentifier() {
return $this->identifier;
}
public function identifierIsPreHashed() {
return $this->prehashed;
}
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;
}
public function isSecure() {
return $this->secure;
}
public function setIsSecure($secure_request = TRUE) {
$this->secure = $secure_request;
return $this;
}
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;
}
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;
}
public static function hashIdentifier($identifier) {
return md5($identifier);
}
}