Adorable.php in Avatar Kit 8
File
avatars_adorable/src/Adorable.php
View source
<?php
namespace Drupal\avatars_adorable;
use Drupal\avatars\AvatarBase;
use Drupal\avatars\Exception\AvatarException;
class Adorable extends AvatarBase implements AdorableInterface {
public function __construct() {
$this
->setDimensionConstraints(Adorable::DIMENSION_MINIMUM_WIDTH, Adorable::DIMENSION_MAXIMUM_WIDTH);
}
public function getHostName() {
$hostname = parent::getHostName();
return isset($hostname) ? $hostname : $this::ADORABLE_HOSTNAME;
}
public static function getTypes() {
return [
'adorable' => 'Adorables',
];
}
public function setIsSecure($secure_request = TRUE) {
if ($secure_request) {
throw new AvatarException('Adorable does not support secure requests.');
}
return parent::setIsSecure($secure_request);
}
public function getUrl() {
$url = ($this
->isSecure() ? 'https://' : 'http://') . $this
->getHostName() . '/avatars/';
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;
}
}