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 = [];
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2020-05-12 23:56:22 -05:00
|
|
|
* @var array()
|
2020-05-03 16:41:59 -05:00
|
|
|
*/
|
|
|
|
private $configs;
|
|
|
|
|
2020-05-12 23:56:22 -05:00
|
|
|
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) {
|
|
|
|
if (!isset($this->configs)) {
|
|
|
|
throw new \Exception('StorageManger was not initialize or configs are not defined');
|
|
|
|
}
|
|
|
|
foreach ($this->configs as $key => $value) {
|
|
|
|
$storage = $this->storages[$key];
|
|
|
|
if (!isset($storage)){
|
|
|
|
throw new \Exception();
|
|
|
|
}
|
|
|
|
$storage->save($calendar);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|