Skip to content

Commit

Permalink
Added generator instances
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeryther committed Sep 12, 2021
1 parent 6d121b4 commit 6d15e7f
Showing 1 changed file with 29 additions and 12 deletions.
41 changes: 29 additions & 12 deletions src/MinecraftAvatar.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@
namespace Gigadrive\MinecraftAvatar;

use Gigadrive\MinecraftAvatar\Service\AbstractMinecraftAvatarGenerator;
use Gigadrive\MinecraftAvatar\Service\CrafatarGenerator;
use Gigadrive\MinecraftAvatar\Service\CraftheadGenerator;
use Gigadrive\MinecraftAvatar\Service\CravatarGenerator;
use Gigadrive\MinecraftAvatar\Service\MCHeadsGenerator;
use Gigadrive\MinecraftAvatar\Service\MinotarGenerator;
use function is_null;

class MinecraftAvatar extends AbstractMinecraftAvatarGenerator {
class MinecraftAvatar {
/**
* @var string SERVICE_MINOTAR
*/
Expand Down Expand Up @@ -33,19 +39,21 @@ class MinecraftAvatar extends AbstractMinecraftAvatarGenerator {
/**
* @var array SERVICES
*/
public const SERVICES = [
self::SERVICE_MINOTAR,
self::SERVICE_CRAFATAR,
self::SERVICE_CRAFTHEAD,
self::SERVICE_MCHEADS,
self::SERVICE_CRAVATAR
];
protected static $services = null;

/**
* @var string $defaultService
*/
protected static $defaultService = self::SERVICE_MINOTAR;

/**
* Gets the default service for generating avatar URLs.
* @return AbstractMinecraftAvatarGenerator
*/
public static function getDefaultService(): AbstractMinecraftAvatarGenerator {
return self::getServices()[self::$defaultService];
}

/**
* Changes the default service to use for generating avatar URLs.
* @param string $service
Expand All @@ -56,10 +64,19 @@ public static function setDefaultService(string $service) {
}

/**
* Gets the default service for generating avatar URLs.
* @return string
* @return AbstractMinecraftAvatarGenerator[]
*/
public static function getDefaultService(): string {
return self::$defaultService;
public static function getServices(): array {
if (is_null(self::$services)) {
self::$services = [
self::SERVICE_MINOTAR => new MinotarGenerator,
self::SERVICE_CRAFATAR => new CrafatarGenerator,
self::SERVICE_CRAFTHEAD => new CraftheadGenerator,
self::SERVICE_MCHEADS => new MCHeadsGenerator,
self::SERVICE_CRAVATAR => new CravatarGenerator
];
}

return self::$services;
}
}

0 comments on commit 6d15e7f

Please sign in to comment.