1
1
<?php
2
2
namespace phpbu \App \Backup \Sync ;
3
3
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 ;
7
6
use phpbu \App \Backup \Collector ;
8
7
use phpbu \App \Backup \Path ;
9
8
use phpbu \App \Result ;
@@ -61,6 +60,16 @@ class Dropbox implements Simulator
61
60
*/
62
61
protected $ time ;
63
62
63
+ /**
64
+ * @var string
65
+ */
66
+ private mixed $ appKey ;
67
+
68
+ /**
69
+ * @var string
70
+ */
71
+ private mixed $ appSecret ;
72
+
64
73
/**
65
74
* (non-PHPDoc)
66
75
*
@@ -76,10 +85,12 @@ public function setup(array $config)
76
85
}
77
86
78
87
// check for mandatory options
79
- $ this ->validateConfig ($ config , ['token ' , 'path ' ]);
88
+ $ this ->validateConfig ($ config , ['token ' , 'path ' , ' appKey ' , ' appSecret ' ]);
80
89
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 ' ];
83
94
// make sure the path contains a leading slash
84
95
$ this ->path = new Path (Util \Path::withLeadingSlash ($ config ['path ' ]), $ this ->time );
85
96
@@ -117,7 +128,7 @@ public function sync(Target $target, Result $result)
117
128
$ client = $ this ->createClient ();
118
129
119
130
try {
120
- $ file = new DropboxFile ($ sourcePath );
131
+ $ file = new DropboxApi \ DropboxFile ($ sourcePath );
121
132
$ meta = $ client ->upload ($ file , $ dropboxPath , ['autorename ' => true ]);
122
133
$ result ->debug ('upload: done ( ' . $ meta ->getSize () . ') ' );
123
134
@@ -163,12 +174,13 @@ protected function createCollector(Target $target) : Collector
163
174
* Create a dropbox api client.
164
175
*
165
176
* @return \Kunnu\Dropbox\Dropbox
177
+ * @throws DropboxClientException
166
178
*/
167
- protected function createClient () : DropboxApi
179
+ protected function createClient () : DropboxApi \ Dropbox
168
180
{
169
181
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 );
172
184
}
173
185
return $ this ->client ;
174
186
}
0 commit comments