baikal-storage-plugin/lib/StorageManager.php

64 lines
1.3 KiB
PHP
Raw Normal View History

2020-05-03 16:41:59 -05:00
<?php
namespace Aerex\BaikalStorage;
use Sabre\VObject\Component\VCalendar as Calendar;
class StorageManager {
/**
* @var Storage[]
*/
private $storages = [];
/**
* @var array()
2020-05-03 16:41:59 -05:00
*/
private $configs;
public function __construct($configs){
$this->configs = $configs;
2020-05-03 16:41:59 -05:00
}
public function getStorages() {
return $this->storages;
}
public function getConfigs() {
return $this->configs;
}
public function addStorage($name, $storage) {
$this->storages[$name] = $storage;
}
public function import(Calendar $calendar, string $displayname) {
2020-05-03 16:41:59 -05:00
if (!isset($this->configs)) {
throw new \Exception('StorageManger was not initialize or configs are not defined');
}
foreach ($this->configs['storages'] as $key => $value) {
$storage = $this->storages[$key];
if (!isset($storage)){
throw new \Exception();
2020-05-03 16:41:59 -05:00
}
$storage->save($calendar, $displayname);
2020-05-03 16:41:59 -05:00
}
}
public function remove($uid) {
if (!isset($this->configs)) {
throw new \Exception('StorageManger was not initialize or configs are not defined');
}
foreach ($this->configs['storages'] as $key => $value) {
$storage = $this->storages[$key];
if (!isset($storage)){
throw new \Exception();
}
$storage->remove($uid);
}
}
2020-05-03 16:41:59 -05:00
}