Skip to content

Commit 10ddce4

Browse files
committed
Unit tests minor fixes, minor changes for Chunked transfer encoding support
1 parent a7a6b28 commit 10ddce4

File tree

9 files changed

+34
-24
lines changed

9 files changed

+34
-24
lines changed

src/Runtime/ClientRequest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,14 @@ public function addQueryAndResultObject(ClientObject $clientObject, ODataQueryOp
128128
/**
129129
* @param RequestOptions $request
130130
* @param array $responseInfo
131-
* @param bool $transferEncodingChunkedAllowed
132131
* @return string
133132
* @throws \Exception
134133
*/
135-
public function executeQueryDirect(RequestOptions $request, &$responseInfo = array(), bool $transferEncodingChunkedAllowed = false)
134+
public function executeQueryDirect(RequestOptions $request, &$responseInfo = array())
136135
{
137136
$this->context->authenticateRequest($request); //Auth mandatory headers
138137
$this->setRequestHeaders($request); //set request headers
139-
return Requests::execute($request,$responseInfo, $transferEncodingChunkedAllowed);
138+
return Requests::execute($request,$responseInfo);
140139
}
141140

142141
/**

src/Runtime/ClientRuntimeContext.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,14 @@ public function executeQuery()
145145

146146
/**
147147
* @param RequestOptions $options
148-
* @param bool $transferEncodingChunkedAllowed
149148
* @return string
150149
* @throws \Exception
151150
*/
152-
public function executeQueryDirect(RequestOptions $options, bool $transferEncodingChunkedAllowed = false)
151+
public function executeQueryDirect(RequestOptions $options)
153152
{
154153
// $_ is not used, just to avoid the "Only variables can be passed by reference" error
155154
$_ = [];
156-
return $this->getPendingRequest()->executeQueryDirect($options, $_, $transferEncodingChunkedAllowed);
155+
return $this->getPendingRequest()->executeQueryDirect($options, $_);
157156
}
158157

159158
/**

src/Runtime/Utilities/RequestOptions.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
class RequestOptions
99
{
1010

11-
1211
/**
1312
* RequestOptions constructor.
1413
* @param $url string
@@ -30,6 +29,7 @@ public function __construct($url, $headers = array(), $data = null, $methodType
3029
$this->StreamHandle = null;
3130
$this->Data = $data;
3231
$this->ConnectTimeout = null;
32+
$this->TransferEncodingChunkedAllowed = false;
3333
}
3434

3535
public function toArray()
@@ -137,4 +137,10 @@ function ($k, $v) {
137137
* @var ?int
138138
*/
139139
public $ConnectTimeout;
140+
141+
142+
/**
143+
* @var bool
144+
*/
145+
public $TransferEncodingChunkedAllowed;
140146
}

src/Runtime/Utilities/Requests.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ public static function getHistory()
1919

2020
protected static $history = [];
2121

22-
public static function execute(RequestOptions $options, &$responseInfo = array(), $transferEncodingChunkedAllowed = false)
22+
public static function execute(RequestOptions $options, &$responseInfo = array())
2323
{
2424
$call = [];
2525
$call['request'] = $options->toArray();
2626

27-
$ch = Requests::init($options, $transferEncodingChunkedAllowed);
27+
$ch = Requests::init($options);
2828
$response = curl_exec($ch);
2929
$responseInfo["HttpCode"] = curl_getinfo($ch, CURLINFO_HTTP_CODE);
3030
$responseInfo["ContentType"] = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
@@ -89,10 +89,9 @@ public static function parseCookies($response)
8989
/**
9090
* Init Curl with the default parameters
9191
* @param RequestOptions $options
92-
* @param bool $transferEncodingChunkedAllowed if true, add the "Transfer-Encoding: chunked" HTTP header if the "Content-Length" header is absent.
9392
* @return resource [type] [description]
9493
*/
95-
private static function init(RequestOptions $options, bool $transferEncodingChunkedAllowed)
94+
private static function init(RequestOptions $options)
9695
{
9796
$ch = curl_init();
9897
curl_setopt($ch, CURLOPT_URL, $options->Url);
@@ -104,7 +103,8 @@ private static function init(RequestOptions $options, bool $transferEncodingChun
104103
//Set method
105104
if($options->Method === HttpMethod::Post) {
106105
curl_setopt($ch, CURLOPT_POST, 1);
107-
if ($transferEncodingChunkedAllowed && !array_key_exists('Content-Length', $options->Headers)) {
106+
//if true, add the "Transfer-Encoding: chunked" HTTP header if the "Content-Length" header is absent.
107+
if ($options->TransferEncodingChunkedAllowed && !array_key_exists('Content-Length', $options->Headers)) {
108108
$options->addCustomHeader("Transfer-Encoding", "chunked");
109109
}
110110
} else if($options->Method == HttpMethod::Patch) {

src/SharePoint/ClientContext.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function requestFormDigest()
6464
{
6565
$request = new RequestOptions($this->getServiceRootUrl() . "contextinfo");
6666
$request->Method = HttpMethod::Post;
67-
$response = $this->executeQueryDirect($request, true);
67+
$response = $this->executeQueryDirect($request);
6868
if(!isset($this->contextWebInformation))
6969
$this->contextWebInformation = new ContextWebInformation();
7070
$result = new ClientResult($this->contextWebInformation);

src/SharePoint/File.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class File extends SecurableObject
2626
public function deleteObject(){
2727
$qry = new DeleteEntityQuery($this);
2828
$this->getContext()->addQuery($qry);
29-
//$this->removeFromParentCollection();
29+
$this->removeFromParentCollection();
3030
}
3131

3232
/**
@@ -164,7 +164,8 @@ public static function openBinary(ClientRuntimeContext $ctx, $serverRelativeUrl)
164164
$serverRelativeUrl = rawurlencode($serverRelativeUrl);
165165
$url = $ctx->getServiceRootUrl() . "web/getfilebyserverrelativeurl('$serverRelativeUrl')/\$value";
166166
$options = new RequestOptions($url);
167-
$data = $ctx->executeQueryDirect($options, true);
167+
$options->TransferEncodingChunkedAllowed = true;
168+
$data = $ctx->executeQueryDirect($options);
168169
return $data;
169170
}
170171

@@ -187,7 +188,8 @@ public static function saveBinary(ClientRuntimeContext $ctx, $serverRelativeUrl,
187188
if ($ctx instanceof ClientContext) {
188189
$ctx->ensureFormDigest($request);
189190
}
190-
$ctx->executeQueryDirect($request, true);
191+
$request->TransferEncodingChunkedAllowed = true;
192+
$ctx->executeQueryDirect($request);
191193
}
192194

193195

@@ -216,7 +218,8 @@ public function getLimitedWebPartManager($scope)
216218
public function getInformationRightsManagementSettings()
217219
{
218220
if (!$this->isPropertyAvailable('InformationRightsManagementSettings')) {
219-
$this->setProperty("InformationRightsManagementSettings", new InformationRightsManagementSettings($this->getContext(), $this->getResourcePath(), "InformationRightsManagementSettings"));
221+
$this->setProperty("InformationRightsManagementSettings",
222+
new InformationRightsManagementSettings());
220223
}
221224
return $this->getProperty("InformationRightsManagementSettings");
222225
}
@@ -229,7 +232,9 @@ public function getInformationRightsManagementSettings()
229232
public function getVersions()
230233
{
231234
if (!$this->isPropertyAvailable('Versions')) {
232-
$this->setProperty("Versions", new FileVersionCollection($this->getContext(), $this->getResourcePath(), "Versions"));
235+
$this->setProperty("Versions",
236+
new FileVersionCollection($this->getContext(),
237+
new ResourcePathEntity($this->getContext(), $this->getResourcePath(), "Versions")));
233238
}
234239
return $this->getProperty("Versions");
235240
}

src/SharePoint/ListItem.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function getTypeName(){
3636
//determine whether ListItemEntityTypeFullName property has been requested
3737
if(!$list->isPropertyAvailable("ListItemEntityTypeFullName")){
3838
$request = new RequestOptions($list->getResourceUrl() . "?\$select=ListItemEntityTypeFullName");
39-
$response = $this->getContext()->executeQueryDirect($request, true);
39+
$response = $this->getContext()->executeQueryDirect($request);
4040
$payload = json_decode($response);
4141
$this->getContext()->getSerializerContext()->map($payload,$list);
4242
}
@@ -92,4 +92,4 @@ public function getFile(){
9292
return $this->getProperty("File");
9393
}
9494

95-
}
95+
}

src/SharePoint/Publishing/VideoItem.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ public function saveBinaryStream($content){
3737
$request->Data = $content;
3838
if($ctx instanceof ClientContext)
3939
$ctx->ensureFormDigest($request);
40-
$ctx->executeQueryDirect($request, true);
40+
$request->TransferEncodingChunkedAllowed = true;
41+
$ctx->executeQueryDirect($request);
4142
}
4243

4344

@@ -59,4 +60,4 @@ public function getTypeName()
5960

6061

6162

62-
}
63+
}

tests/MetadataReaderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ public function testParseMetadata($edmxContent){
2929
'rootNamespace' => $rootNamespace,
3030
'ignoredTypes' => array()
3131
);
32-
$reader = new ODataV3Reader();
33-
$model = $reader->generateModel($edmxContent,$generatorOptions);
32+
$reader = new ODataV3Reader($edmxContent,$generatorOptions);
33+
$model = $reader->generateModel();
3434
$this->assertNotNull($model);
3535
$this->assertNotEquals(0,count($model->getTypes()));
3636
}

0 commit comments

Comments
 (0)