baikal-storage-plugin/lib/StorageManager.php

50 lines
917 B
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) {
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);
}
}
}