blue-twilight/app/AlbumSources/AlbumSourceBase.php

59 lines
1.2 KiB
PHP

<?php
namespace app\AlbumSources;
use App\Album;
use App\Storage;
abstract class AlbumSourceBase
{
/**
* @var Album
*/
protected $album;
/**
* @var Storage
*/
protected $configuration;
/**
* @var mixed
*/
private static $albumSourceCache = [];
/**
* Makes an album source class for the given source name (relative class name.)
* @param string $sourceName Name of the source.
* @return IAlbumSource
*/
public static function make($sourceName)
{
$fullClassName = sprintf('App\AlbumSources\%s', $sourceName);
if (!array_key_exists($fullClassName, self::$albumSourceCache))
{
/** @var IAlbumSource $source */
$source = app($fullClassName);
self::$albumSourceCache[$fullClassName] = $source;
}
return self::$albumSourceCache[$fullClassName];
}
public function getConfiguration()
{
return $this->configuration;
}
public function setAlbum(Album $album)
{
$this->album = $album;
}
public function setConfiguration(Storage $configuration)
{
$this->configuration = $configuration;
}
}