buildConfigurations($configDir); $this->storageManager = new StorageManager($configs); $this->initializeStorages($configDir, $configs); } public function buildConfigurations($configDir) { $this->config = new ConfigBuilder($configDir); $this->config->add(new TaskwarriorConfig()); return $this->config->loadYaml(); } /** * Configure available storages in storage manager * */ public function initializeStorages($configDir, $configs) { $taskwarrior = new Taskwarrior(new Console(['rc.verbose=nothing', 'rc.hooks=off']), $configDir, $configs); $this->storageManager->addStorage(Taskwarrior::NAME, $taskwarrior); } /** * Sets up the plugin * * @param Server $server * @return void */ function initialize(Server $server) { $this->server = $server; $server->on('beforeMethod:*', [$this, 'beforeMethod'], 15); } /** * Returns a plugin name. * * Using this name other plugins will be able to access other plugins * using DAV\Server::getPlugin * * @return string */ function getPluginName() { return 'taskwarrior'; } /** * This method is called before any HTTP method handler. * * This method intercepts any GET, DELETE, PUT and PROPFIND calls to * filenames that are known to match the 'temporary file' regex. * * @param RequestInterface $request * @param ResponseInterface $response * * @return bool */ public function beforeMethod(RequestInterface $request, ResponseInterface $response) { switch ($request->getMethod()) { case 'PUT': $this->httpPut($request, $response); } return; } /** * This method handles the PUT method. * * @param RequestInterface $request * * @return bool */ function httpPut(RequestInterface $request){ $body = $request->getBodyAsString(); $vCal = \Sabre\VObject\Reader::read($body); try { $this->storageManager->import($vCal); } catch(BadRequest $e){ throw new BadRequest($e->getMessage(), null, $e); } catch(\Exception $e){ throw new \Exception($e->getMessage(), null, $e); } $request->setBody($body); } /** * Returns a bunch of meta-data about the plugin. * * Providing this information is optional, and is mainly displayed by the * Browser plugin. * * The description key in the returned array may contain html and will not * be sanitized. * * @return array */ function getPluginInfo() { return [ 'name' => $this->getPluginName(), 'description' => 'The plugin provides synchronization between taskwarrior tasks and iCAL events', 'link' => null, ]; } }