11<?php
22namespace phpbu \App \Backup \Sync ;
33
4- use Kunnu \Dropbox \DropboxApp as DropboxConfig ;
5- use Kunnu \Dropbox \Dropbox as DropboxApi ;
6- use Kunnu \Dropbox \DropboxFile ;
4+ use Kunnu \Dropbox as DropboxApi ;
5+ use Kunnu \Dropbox \Exceptions \DropboxClientException ;
76use phpbu \App \Backup \Collector ;
87use phpbu \App \Backup \Path ;
98use phpbu \App \Result ;
@@ -61,6 +60,16 @@ class Dropbox implements Simulator
6160 */
6261 protected $ time ;
6362
63+ /**
64+ * @var string
65+ */
66+ private mixed $ appKey ;
67+
68+ /**
69+ * @var string
70+ */
71+ private mixed $ appSecret ;
72+
6473 /**
6574 * (non-PHPDoc)
6675 *
@@ -76,10 +85,12 @@ public function setup(array $config)
7685 }
7786
7887 // check for mandatory options
79- $ this ->validateConfig ($ config , ['token ' , 'path ' ]);
88+ $ this ->validateConfig ($ config , ['token ' , 'path ' , ' appKey ' , ' appSecret ' ]);
8089
81- $ this ->time = time ();
82- $ this ->token = $ config ['token ' ];
90+ $ this ->time = time ();
91+ $ this ->token = $ config ['token ' ];
92+ $ this ->appKey = $ config ['appKey ' ];
93+ $ this ->appSecret = $ config ['appSecret ' ];
8394 // make sure the path contains a leading slash
8495 $ this ->path = new Path (Util \Path::withLeadingSlash ($ config ['path ' ]), $ this ->time );
8596
@@ -117,7 +128,7 @@ public function sync(Target $target, Result $result)
117128 $ client = $ this ->createClient ();
118129
119130 try {
120- $ file = new DropboxFile ($ sourcePath );
131+ $ file = new DropboxApi \ DropboxFile ($ sourcePath );
121132 $ meta = $ client ->upload ($ file , $ dropboxPath , ['autorename ' => true ]);
122133 $ result ->debug ('upload: done ( ' . $ meta ->getSize () . ') ' );
123134
@@ -163,12 +174,13 @@ protected function createCollector(Target $target) : Collector
163174 * Create a dropbox api client.
164175 *
165176 * @return \Kunnu\Dropbox\Dropbox
177+ * @throws DropboxClientException
166178 */
167- protected function createClient () : DropboxApi
179+ protected function createClient () : DropboxApi \ Dropbox
168180 {
169181 if (!$ this ->client ) {
170- $ config = new DropboxConfig ( " id " , " secret " , $ this ->token );
171- $ this ->client = new DropboxApi ( $ config );
182+ $ app = new DropboxApi \ DropboxApp ( $ this -> appKey , $ this -> appSecret , $ this ->token );
183+ $ this ->client = new DropboxApi \ Dropbox ( $ app );
172184 }
173185 return $ this ->client ;
174186 }
0 commit comments