/** * @param array $params user */ public function __construct($params) { $params = $params['dropbox_sdk']; $this->access_token = $params['access_token']; $this->remotePath = $params['remote_path']; Dropbox\RootCertificates::useExternalPaths(); }
/** * (non-PHPDoc) * * @see \phpbu\App\Backup\Sync::sync() * @param \phpbu\App\Backup\Target $target * @param \phpbu\App\Result $result * @throws \phpbu\App\Backup\Sync\Exception */ public function sync(Target $target, Result $result) { $sourcePath = $target->getPathname(); $dropboxPath = $this->path . $target->getFilename(); $client = new DropboxApi\Client($this->token, "phpbu/1.1.0"); $pathError = DropboxApi\Path::findErrorNonRoot($dropboxPath); if (substr(__FILE__, 0, 7) == 'phar://') { DropboxApi\RootCertificates::useExternalPaths(); } if ($pathError !== null) { throw new Exception(sprintf('Invalid \'dropbox-path\': %s', $pathError)); } $size = null; if (stream_is_local($sourcePath)) { $size = filesize($sourcePath); } try { $fp = fopen($sourcePath, 'rb'); $res = $client->uploadFile($dropboxPath, DropboxApi\WriteMode::add(), $fp, $size); fclose($fp); } catch (\Exception $e) { throw new Exception($e->getMessage(), null, $e); } $result->debug('upload: done (' . $res['size'] . ')'); }
/** * Normally, the Dropbox SDK tells cURL to look in the "certs" folder for root certificate * information. But this won't work if the SDK is running from within a PHAR because * cURL won't read files that are packaged in a PHAR. * * @return void */ public function useExternalPaths() { \Dropbox\RootCertificates::useExternalPaths(); }