Skip to content

Commit 17b36ff

Browse files
committed
#103 : fix for properly encode whitespaces once list & view is referenced by title
1 parent 3318c78 commit 17b36ff

24 files changed

+262
-114
lines changed

examples/GraphConsole/ClientApp.php

Lines changed: 0 additions & 35 deletions
This file was deleted.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
4+
use Office365\PHP\Client\GraphClient\GraphServiceClient;
5+
use Office365\PHP\Client\Runtime\Auth\AuthenticationContext;
6+
use Office365\PHP\Client\Runtime\Auth\OAuthTokenProvider;
7+
use Office365\PHP\Client\Runtime\Utilities\UserCredentials;
8+
9+
require_once '../bootstrap.php';
10+
11+
try
12+
{
13+
$client = getAuthenticatedClient();
14+
//downloadPhoto($client,"./myprofile.jpg");
15+
getDriveInfo($client);
16+
17+
}
18+
catch (Exception $e) {
19+
echo 'Error: ', $e->getMessage(), "\n";
20+
}
21+
22+
23+
function getDriveInfo(GraphServiceClient $client){
24+
$drive = $client->getMe()->getDrive();
25+
$client->load($drive);
26+
$client->executeQuery();
27+
print $drive->getProperty("webUrl");
28+
}
29+
30+
31+
function downloadPhoto(GraphServiceClient $client,$targetFilePath){
32+
$fp = fopen($targetFilePath, 'w+');
33+
//$url = $client->getServiceRootUrl() . "me/photo\$value";
34+
$url = $client->getServiceRootUrl() . "me/photo";
35+
$options = new \Office365\PHP\Client\Runtime\Utilities\RequestOptions($url);
36+
//$options->StreamHandle = $fp;
37+
$content = $client->executeQueryDirect($options);
38+
fclose($fp);
39+
}
40+
41+
42+
function getAuthenticatedClient(){
43+
global $AppSettings;
44+
global $Settings;
45+
$resource = "https://graph.microsoft.com";
46+
$authorityUrl = OAuthTokenProvider::$AuthorityUrl . $AppSettings['TenantName'];
47+
$authCtx = new AuthenticationContext($authorityUrl);
48+
$authCtx->acquireTokenForUserCredential($resource,$AppSettings['ClientId'],new UserCredentials($Settings['UserName'],$Settings['Password']));
49+
$client = new GraphServiceClient($authCtx);
50+
return $client;
51+
}
52+
53+
54+

examples/GraphExplorer/ProcessQuery.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
use Office365\PHP\Client\GraphClient\ActiveDirectoryClient;
2+
use Office365\PHP\Client\GraphClient\GraphServiceClient;
33
use Office365\PHP\Client\Runtime\Utilities\RequestOptions;
44

55
require_once '../bootstrap.php';
@@ -14,11 +14,14 @@
1414
if (isset($_GET['text'])) {
1515
$requestUrl = $_GET['text'];
1616
$authorityUrl = "https://graph.windows.net/";
17-
$client = new ActiveDirectoryClient($authorityUrl,$_SESSION['auth_ctx']);
17+
$client = new GraphServiceClient($_SESSION['auth_ctx']);
1818
$request = new RequestOptions($requestUrl);
1919
//$request->Url .= "?api-version=1.0";
2020
$request->Url .= "?api-version=beta";
21-
$response = $client->executeQueryDirect($request);
21+
try {
22+
$response = $client->executeQueryDirect($request);
23+
} catch (Exception $e) {
24+
}
2225
echo $response;
2326
}
2427
else

examples/Settings.php

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

33
$Settings = array(
4-
'Url' => "https://mediadev20.sharepoint.com/sites/contoso",
5-
'OneDriveUrl' => "https://mediadev20-my.SharePoint.com",
4+
'Url' => "https://mediadev23.sharepoint.com",
5+
'OneDriveUrl' => "https://mediadev23-my.SharePoint.com",
66
'Password' => "P@ssw0rd",
7-
'UserName' => "mattim@mediadev20.onmicrosoft.com"
7+
'UserName' => "mattim@mediadev23.onmicrosoft.com"
88
);
99

1010
$AppSettings = array(
11-
'TenantName' => "mediadev20.onmicrosoft.com",
12-
'ClientId' => "13d4cd98-1761-4416-b01c-a641c08d0737",
13-
'ClientSecret' => "oYM9GUiE4uejyaQ0GuuHj7U",
11+
'TenantName' => "mediadev23.onmicrosoft.com",
12+
'ClientId' => "d426369e-c84b-47db-b6b1-b9c824ac2ea2",
13+
'ClientSecret' => "wrizJBW41]|=@govNEDR059",
1414
'Title' => "Office365 Graph explorer",
1515
'RedirectUrl' => "http://localhost:8078/GraphExplorer/SignIn.php"
1616
);

examples/SharePoint/file_examples.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,14 @@
1717
$targetLibraryTitle = "Documents";
1818
$targetFolderUrl = "/sites/contoso/Documents/Archive/2017/08";
1919

20-
$list = ListExtensions::ensureList($ctx->getWeb(),$targetLibraryTitle, \Office365\PHP\Client\SharePoint\ListTemplateType::DocumentLibrary);
20+
//$list = ListExtensions::ensureList($ctx->getWeb(),$targetLibraryTitle, \Office365\PHP\Client\SharePoint\ListTemplateType::DocumentLibrary);
21+
22+
23+
$fileUrl = "/sites/contoso/Shared Documents/Guide #123.docx";
24+
$file = $ctx->getWeb()->getFileByServerRelativeUrl($fileUrl);
25+
$ctx->load($file);
26+
$ctx->executeQuery();
27+
2128

2229
$folderUrl = "Shared Documents";
2330
$fileUrl = "Guide #123.docx";
@@ -58,6 +65,7 @@ function createSubFolder(ClientContext $ctx,$parentFolderUrl,$folderName){
5865
$ctx->load($files);
5966
$ctx->executeQuery();
6067
//print files info
68+
/* @var $file \Office365\PHP\Client\SharePoint\File */
6169
foreach ($files->getData() as $file) {
6270
print "File name: '{$file->getProperty("ServerRelativeUrl")}'\r\n";
6371
}

examples/SharePoint/list_examples.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@
1515
$ctx = new ClientContext($Settings['Url'],$authCtx);
1616

1717

18+
$listTitle = 'Archive 2017';
19+
//$listTitle = 'Archive%202017';
20+
$list = $ctx->getWeb()->getLists()->getByTitle($listTitle);
21+
$ctx->load($list);
22+
$ctx->executeQuery();
23+
24+
echo $list->getProperty('Title');
25+
1826
$listTitle = "Orders_" . rand(1,1000);
1927
//$listTitle = "Tasks" ;
2028

examples/SharePoint/web_examples.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
global $Settings;
1111

1212
try {
13+
1314
$authCtx = new AuthenticationContext($Settings['Url']);
1415
$authCtx->acquireTokenForUser($Settings['UserName'],$Settings['Password']);
1516

src/GraphClient/ActiveDirectoryClient.php

Lines changed: 0 additions & 58 deletions
This file was deleted.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace Office365\PHP\Client\GraphClient;
4+
5+
use Office365\PHP\Client\OneDrive\CurrentUserRequestContext;
6+
use Office365\PHP\Client\Runtime\Auth\IAuthenticationContext;
7+
use Office365\PHP\Client\Runtime\ClientAction;
8+
use Office365\PHP\Client\Runtime\ClientRuntimeContext;
9+
use Office365\PHP\Client\Runtime\OData\JsonFormat;
10+
use Office365\PHP\Client\Runtime\OData\ODataMetadataLevel;
11+
use Office365\PHP\Client\Runtime\Office365Version;
12+
use Office365\PHP\Client\Runtime\ResourcePathEntity;
13+
use Office365\PHP\Client\Runtime\Utilities\RequestOptions;
14+
15+
class GraphServiceClient extends ClientRuntimeContext
16+
{
17+
public function __construct(IAuthenticationContext $authContext)
18+
{
19+
$serviceRootUrl = "https://graph.microsoft.com/" . Office365Version::V1 . "/";
20+
parent::__construct($serviceRootUrl, $authContext,new JsonFormat(ODataMetadataLevel::Verbose));
21+
}
22+
23+
24+
public function executeQuery()
25+
{
26+
$this->getPendingRequest()->beforeExecuteQuery(function (RequestOptions $request,ClientAction $query){
27+
});
28+
parent::executeQuery();
29+
}
30+
31+
/**
32+
* @return CurrentUserRequestContext
33+
*/
34+
public function getMe(){
35+
if(!isset($this->me))
36+
$this->me = new CurrentUserRequestContext($this,new ResourcePathEntity($this,null,"me"));
37+
return $this->me;
38+
}
39+
40+
41+
42+
43+
44+
}

src/OneDrive/Drive.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function getOwner(){
2222
* @param string $value
2323
*/
2424
public function setOwner($value){
25-
return $this->setProperty("owner",$value);
25+
$this->setProperty("owner",$value);
2626
}
2727

2828

@@ -49,7 +49,7 @@ public function getFiles(){
4949
* @param string $value
5050
*/
5151
public function setFiles($value){
52-
return $this->setProperty("files",$value);
52+
$this->setProperty("files",$value);
5353
}
5454

5555
}

0 commit comments

Comments
 (0)