Skip to content

Commit 86b823e

Browse files
committed
determines whether FormDigest has been expired or not
1 parent 3e1b806 commit 86b823e

12 files changed

+220
-8
lines changed

examples/SharePoint/Sites/CreateModernSite.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
<?php
22

3+
/**
4+
* Creates a communications site
5+
* Refer https://docs.microsoft.com/en-us/sharepoint/dev/apis/site-creation-rest for docs
6+
*/
7+
38
require_once __DIR__ . '/../../vendor/autoload.php';
49
$settings = include(__DIR__ . '/../../../tests/Settings.php');
510

611
use Office365\Runtime\Auth\ClientCredential;
712
use Office365\SharePoint\ClientContext;
8-
use Office365\SharePoint\Portal\SPSiteManager;
913

1014
try {
1115
$credentials = new ClientCredential($settings['ClientId'], $settings['ClientSecret']);
1216
$ctx = (new ClientContext($settings['Url']))->withCredentials($credentials);
1317

14-
$siteManager = new SPSiteManager($ctx);
15-
//create communications site
16-
//refer https://docs.microsoft.com/en-us/sharepoint/dev/apis/site-creation-rest for docs
17-
$result = $siteManager->create("commsite127", $settings['TestAccountName'], "Low Business Impact");
18-
$siteManager->executeQuery();
18+
$result = $ctx
19+
->getSiteManager()
20+
->create("commsite127", $settings['TestAccountName'], "Low Business Impact")
21+
->executeQuery();
1922
print("Site has been created: {$result->getValue()->SiteUrl} \n");
2023
}
2124
catch (Exception $e) {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/**
4+
* Generated 2024-10-28T19:09:39+00:00 16.0.25409.12005
5+
*/
6+
namespace Office365\SharePoint;
7+
8+
use Office365\Runtime\ClientValue;
9+
class AgreementCountryResponse extends ClientValue
10+
{
11+
/**
12+
* @var string
13+
*/
14+
public $CountryKey;
15+
/**
16+
* @var string
17+
*/
18+
public $DisplayName;
19+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
/**
4+
* Generated 2024-10-28T19:09:39+00:00 16.0.25409.12005
5+
*/
6+
namespace Office365\SharePoint;
7+
8+
use Office365\Runtime\ClientValue;
9+
class AgreementLocationData extends ClientValue
10+
{
11+
/**
12+
* @var string
13+
*/
14+
public $LibraryId;
15+
/**
16+
* @var string
17+
*/
18+
public $SiteId;
19+
/**
20+
* @var string
21+
*/
22+
public $WebId;
23+
}

src/SharePoint/ClientContext.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public function withNtlm($credential){
174174
*/
175175
public function ensureFormDigest(RequestOptions $request)
176176
{
177-
if (!isset($this->contextWebInformation)) {
177+
if (!$this->getContextWebInformation()->isValid()) {
178178
$this->requestFormDigest();
179179
}
180180
$request->ensureHeader("X-RequestDigest",$this->getContextWebInformation()->FormDigestValue);
@@ -250,6 +250,8 @@ public function getSite()
250250
*/
251251
public function getContextWebInformation()
252252
{
253+
if(!isset($this->contextWebInformation))
254+
$this->contextWebInformation = new ContextWebInformation();
253255
return $this->contextWebInformation;
254256
}
255257

src/SharePoint/ContextWebInformation.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,34 @@
1010
*/
1111
class ContextWebInformation extends ClientValue
1212
{
13-
13+
14+
15+
16+
public function __construct()
17+
{
18+
parent::__construct();
19+
$this->_valid_from = time();
20+
}
21+
22+
/**
23+
* @var int
24+
*/
25+
private $_valid_from;
26+
27+
/**
28+
* Determines whether FormDigest has been expired or not
29+
* @return bool
30+
*/
31+
function isValid()
32+
{
33+
if ($this->FormDigestTimeoutSeconds === null) {
34+
return false;
35+
}
36+
37+
$expires_in_sec = time() - $this->_valid_from;
38+
return $expires_in_sec < $this->FormDigestTimeoutSeconds;
39+
}
40+
1441
/**
1542
* The form digest value.
1643
* @var string
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
/**
4+
* Generated 2024-10-28T19:35:46+00:00 16.0.25409.12005
5+
*/
6+
namespace Office365\SharePoint;
7+
8+
use Office365\Runtime\ClientObject;
9+
use Office365\Runtime\Actions\DeleteEntityQuery;
10+
use Office365\Runtime\ResourcePath;
11+
use Office365\Runtime\Actions\UpdateEntityQuery;
12+
class CopilotFileCollection extends BaseEntity
13+
{
14+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
/**
4+
* Generated 2024-10-28T19:09:39+00:00 16.0.25409.12005
5+
*/
6+
namespace Office365\SharePoint;
7+
8+
use Office365\Runtime\ClientValue;
9+
class GridInitInfoType extends ClientValue
10+
{
11+
/**
12+
* @var string
13+
*/
14+
public $ControllerId;
15+
/**
16+
* @var string
17+
*/
18+
public $GridSerializer;
19+
/**
20+
* @var string
21+
*/
22+
public $JsInitObj;
23+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/**
4+
* Generated 2024-10-28T19:09:39+00:00 16.0.25409.12005
5+
*/
6+
namespace Office365\SharePoint;
7+
8+
use Office365\Runtime\ClientValue;
9+
class ItemOrderUpdateValue extends ClientValue
10+
{
11+
/**
12+
* @var bool
13+
*/
14+
public $HasException;
15+
/**
16+
* @var integer
17+
*/
18+
public $ItemId;
19+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
/**
4+
* Generated 2024-10-28T19:35:46+00:00 16.0.25409.12005
5+
*/
6+
namespace Office365\SharePoint;
7+
8+
use Office365\Runtime\ClientObject;
9+
use Office365\Runtime\Actions\DeleteEntityQuery;
10+
use Office365\Runtime\ResourcePath;
11+
use Office365\Runtime\Actions\UpdateEntityQuery;
12+
class OutOfBoxFontPackageSettings extends BaseEntity
13+
{
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
/**
4+
* Generated 2024-10-28T19:35:46+00:00 16.0.25409.12005
5+
*/
6+
namespace Office365\SharePoint;
7+
8+
use Office365\Runtime\ClientObject;
9+
use Office365\Runtime\Actions\DeleteEntityQuery;
10+
use Office365\Runtime\ResourcePath;
11+
use Office365\Runtime\Actions\UpdateEntityQuery;
12+
class PeopleCollection extends BaseEntity
13+
{
14+
}

0 commit comments

Comments
 (0)