I’m trying to create a wrapper for S3. I have a few buckets and the local fs that perform the same operations. I want to achieve something like S3Wrapper::bucket1->upload()
to simplify development and also reduce duplicating the same methods for each bucket. Does it make sense to create a Singleton class for the wrapper? I’m new to design patterns so let me know if it doesn’t make sense.
class S3Wrapper{
private static $instance;
protected $disk = '';
private function __construct(){}
public static function bucket1(){
if(!isset(self::$instance)){
self::$instance = new S3Wrapper();
} else {
$self::$instance->$disk = 'bucket1';
return $self::$instance;
}
}
public static function bucket2(){
if(!isset(self::$instance)){
self::$instance = new S3Wrapper();
} else {
$self::$instance->$disk = 'bucket2';
return $self::$instance;
}
}
public static function printDisk(){
echo $this->$disk;
}
}
S3Wrapper::bucket1()->printDisk();
S3Wrapper::bucket2()->printDisk();