PluginProbe
ManageWP Worker / 4.0.1
ManageWP Worker v4.0.1
4.9.38 4.9.37 4.9.36 4.9.35 4.9.34 3.8.7 3.8.8 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.18 3.9.19 3.9.2 3.9.20 3.9.21 3.9.22 3.9.23 3.9.24 All 73 releases
worker / src / Dropbox / WriteMode.php

WriteMode.php in ManageWP Worker 4.0.1, at src/Dropbox/WriteMode.php

127 lines 3.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Describes how a file should be saved when it is written to Dropbox.
5 */
6 final class Dropbox_WriteMode
7 {
8 /**
9 * The URL parameters to pass to the file uploading endpoint to achieve the
10 * desired write mode.
11 *
12 * @var array
13 */
14 private $extraParams;
15
16 /**
17 * @internal
18 */
19 private function __construct($extraParams)
20 {
21 $this->extraParams = $extraParams;
22 }
23
24 /**
25 * @internal
26 */
27 public function getExtraParams()
28 {
29 return $this->extraParams;
30 }
31
32 /**
33 * Returns a {@link WriteMode} for adding a new file. If a file at the specified path already
34 * exists, the new file will be renamed automatically.
35 *
36 * For example, if you're trying to upload a file to "/Notes/Groceries.txt", but there's
37 * already a file there, your file will be written to "/Notes/Groceries (1).txt".
38 *
39 * You can determine whether your file was renamed by checking the "path" field of the
40 * metadata object returned by the API call.
41 *
42 * @return Dropbox_WriteMode
43 */
44 public static function add()
45 {
46 if (self::$addInstance === null) {
47 self::$addInstance = new Dropbox_WriteMode(array("overwrite" => "false"));
48 }
49
50 return self::$addInstance;
51 }
52
53 private static $addInstance = null;
54
55 /**
56 * Returns a {@link WriteMode} for forcing a file to be at a certain path. If there's already
57 * a file at that path, the existing file will be overwritten. If there's a folder at that
58 * path, however, it will not be overwritten and the API call will fail.
59 *
60 * @return Dropbox_WriteMode
61 */
62 public static function force()
63 {
64 if (self::$forceInstance === null) {
65 self::$forceInstance = new Dropbox_WriteMode(array("overwrite" => "true"));
66 }
67
68 return self::$forceInstance;
69 }
70
71 private static $forceInstance = null;
72
73 /**
74 * Returns a {@link WriteMode} for updating an existing file. This is useful for when you
75 * have downloaded a file, made modifications, and want to save your modifications back to
76 * Dropbox. You need to specify the revision of the copy of the file you downloaded (it's
77 * the "rev" parameter of the file's metadata object).
78 *
79 * If, when you attempt to save, the revision of the file currently on Dropbox matches
80 * $revToReplace, the file on Dropbox will be overwritten with the new contents you provide.
81 *
82 * If the revision of the file currently on Dropbox doesn't match $revToReplace, Dropbox will
83 * create a new file and save your contents to that file. For example, if the original file
84 * path is "/Notes/Groceries.txt", the new file's path might be
85 * "/Notes/Groceries (conflicted copy).txt".
86 *
87 * You can determine whether your file was renamed by checking the "path" field of the
88 * metadata object returned by the API call.
89 *
90 * @param string $revToReplace
91 *
92 * @return Dropbox_WriteMode
93 */
94 public static function update($revToReplace)
95 {
96 return new Dropbox_WriteMode(array("parent_rev" => $revToReplace));
97 }
98
99 /**
100 * Check that a function argument is of type <code>WriteMode</code>.
101 *
102 * @internal
103 */
104 public static function checkArg($argName, $argValue)
105 {
106 if (!($argValue instanceof self)) {
107 Dropbox_Checker::throwError($argName, $argValue, __CLASS__);
108 }
109 }
110
111 /**
112 * Check that a function argument is either <code>null</code> or of type
113 * <code>WriteMode</code>.
114 *
115 * @internal
116 */
117 public static function checkArgOrNull($argName, $argValue)
118 {
119 if ($argValue === null) {
120 return;
121 }
122 if (!($argValue instanceof self)) {
123 Dropbox_Checker::throwError($argName, $argValue, __CLASS__);
124 }
125 }
126 }
127