7
7
8
8
9
9
10
+ use Office365 \Runtime \DeleteEntityQuery ;
11
+ use Office365 \Runtime \Http \HttpMethod ;
12
+ use Office365 \Runtime \Http \RequestOptions ;
13
+ use Office365 \Runtime \InvokeMethodQuery ;
14
+ use Office365 \Runtime \InvokePostMethodQuery ;
10
15
use Office365 \Runtime \ResourcePath ;
16
+ use Office365 \Runtime \ResourcePathUrl ;
11
17
12
18
/**
13
19
* Item is the main data model in the OneDrive API. Everything is an item.
14
20
*/
15
21
class DriveItem extends BaseItem
16
22
{
17
23
24
+ /**
25
+ * The simple upload API allows you to provide the contents of a new file or update the contents of an
26
+ * existing file in a single API call. This method only supports files up to 4MB in size.
27
+ * @param string $name
28
+ * @param string $content
29
+ * @return DriveItem
30
+ */
31
+ public function upload ($ name , $ content )
32
+ {
33
+ $ driveItem = new DriveItem ($ this ->getContext (), new ResourcePathUrl ($ name ,$ this ->resourcePath ));
34
+ $ qry = new InvokePostMethodQuery ($ driveItem , null ,null ,null ,$ content );
35
+ $ this ->getContext ()->addQueryAndResultObject ($ qry ,$ driveItem );
36
+ $ this ->getContext ()->getPendingRequest ()->beforeExecuteQuery (function (RequestOptions $ request ){
37
+ $ request ->Url .= "content " ;
38
+ $ request ->Method = HttpMethod::Put;
39
+ },true );
40
+ return $ driveItem ;
41
+ }
42
+
43
+
44
+ /**
45
+ * Download the contents of the primary stream (file) of a DriveItem. Only driveItems with the file property
46
+ * can be downloaded.
47
+ * @param resource $handle
48
+ */
49
+ public function download ($ handle ){
50
+ $ qry = new InvokeMethodQuery ($ this );
51
+ $ this ->getContext ()->getPendingRequest ()->beforeExecuteQuery (function (RequestOptions $ request ) use ($ handle ){
52
+ $ request ->Url .= "content " ;
53
+ $ request ->StreamHandle = $ handle ;
54
+ $ request ->FollowLocation = true ;
55
+ },true );
56
+ $ this ->getContext ()->addQuery ($ qry );
57
+ }
58
+
59
+
60
+ /**
61
+ * Converts the contents of an item in a specific format
62
+ * @param resource $handle
63
+ * @param string $format
64
+ */
65
+ public function convert ($ handle , $ format )
66
+ {
67
+ $ qry = new InvokeMethodQuery ($ this );
68
+ $ this ->getContext ()->getPendingRequest ()->beforeExecuteQuery (function (RequestOptions $ request ) use ($ handle ,$ format ){
69
+ $ request ->Url .= "content? \$format= $ format " ;
70
+ $ request ->StreamHandle = $ handle ;
71
+ $ request ->FollowLocation = true ;
72
+ },true );
73
+ $ this ->getContext ()->addQuery ($ qry );
74
+ }
75
+
76
+ /**
77
+ * Delete a DriveItem by using its ID or path. Note that deleting items using this method will move the items to
78
+ * the recycle bin instead of permanently deleting the item.
79
+ */
80
+ public function delete ()
81
+ {
82
+ $ qry = new DeleteEntityQuery ($ this );
83
+ $ this ->getContext ()->addQuery ($ qry );
84
+ }
85
+
18
86
19
87
/**
20
88
* @return string
@@ -406,4 +474,16 @@ public function getPermissions()
406
474
}
407
475
return $ this ->getProperty ("Permissions " );
408
476
}
477
+
478
+ public function setProperty ($ name , $ value , $ persistChanges = true )
479
+ {
480
+ parent ::setProperty ($ name , $ value , $ persistChanges );
481
+ if ($ name == "id " && $ this ->resourcePath ->getParent ()->getSegment () == "Children " ){
482
+ $ this ->resourcePath = new ResourcePath ($ value ,
483
+ new ResourcePath ("items " , $ this ->parentCollection ->getResourcePath ()->getParent ()->getParent ()));
484
+ }
485
+ }
486
+
487
+
488
+
409
489
}
0 commit comments