The SPUser
class is an object representation of a SharePoint user.
Get a SPUser
instance of the current logged user.
<?php
require 'vendor/autoload.php';
use Http\Adapter\Guzzle6\Client as HttpClient;
use Http\Message\MessageFactory\GuzzleMessageFactory as MessageFactory;
use Impensavel\Spoil\Exception\SPRuntimeException;
use Impensavel\Spoil\SPSite;
use Impensavel\Spoil\SPUser;
try {
// SharePoint Site configuration
$config = [
// ...
];
// Instantiate SharePoint Site
$site = new SPSite('https://example.sharepoint.com/sites/mySite/', $config, new HttpClient, new MessageFactory);
$user = SPUser::getCurrent($site);
} catch (SPRuntimeException $e) {
// Handle exceptions
}
Get a SPUser
instance from a specific user account.
<?php
require 'vendor/autoload.php';
use Http\Adapter\Guzzle6\Client as HttpClient;
use Http\Message\MessageFactory\GuzzleMessageFactory as MessageFactory;
use Impensavel\Spoil\Exception\SPRuntimeException;
use Impensavel\Spoil\SPSite;
use Impensavel\Spoil\SPUser;
try {
// SharePoint Site configuration
$config = [
// ...
];
// Instantiate SharePoint Site
$site = new SPSite('https://example.sharepoint.com/sites/mySite/', $config, new HttpClient, new MessageFactory);
$user = SPUser::getByAccount($site, 'i:0#.f|membership|username@example.onmicrosoft.com');
} catch (SPRuntimeException $e) {
// Handle exceptions
}
Retrieve an array
representation of the SPUser
object.
Example:
var_dump($user->toArray());
App-only Policy output:
array(9) {
["account"]=>
string(58) "i:0i.t|00000000-0000-ffff-0000-000000000000|app@sharepoint"
["email"]=>
NULL
["full_name"]=>
string(14) "app@sharepoint"
["first_name"]=>
string(0) ""
["last_name"]=>
string(0) ""
["title"]=>
NULL
["picture"]=>
NULL
["url"]=>
string(132) "https://example.sharepoint.com/Person.aspx?accountname=i%3A0i%2Et%7C00000000%2D0000%2Dffff%2D0000%2D000000000000%7Capp%40sharepoint"
["extra"]=>
array(0) {
}
}
User-only Policy output:
array(9) {
["account"]=>
string(58) "i:0i.t|membership|username@example.onmicrosoft.com"
["email"]=>
string(33) "username@example.onmicrosoft.com"
["full_name"]=>
string(12) "Name Surname"
["first_name"]=>
string(4) "Name"
["last_name"]=>
string(7) "Surname"
["title"]=>
NULL
["picture"]=>
NULL
["url"]=>
string(74) "https://example.sharepoint.com/personal/username_example_onmicrosoft_com/"
["extra"]=>
array(0) {
}
}
Get the SPUser
account.
Example:
echo $user->getAccount();
Output:
i:0i.t|membership|username@example.onmicrosoft.com
Get the SPUser
email.
Example:
echo $user->getEmail();
Output:
username@example.onmicrosoft.com
Get the SPUser
full name.
Example:
echo $user->getFullName();
Output:
Name Surname
Get the SPUser
first name.
Example:
echo $user->getFirstName();
Output:
Name
Get the SPUser
last name.
Example:
echo $user->getLastName();
Output:
Surname
Get the SPUser
title.
Example:
echo $user->getTitle();
Output:
// null
Get the SPUser
picture URL.
Example:
echo $user->getPicture();
Output:
// null
Get the SPUser
URL.
Example:
echo $user->getUrl();
Output:
https://example.sharepoint.com/personal/username_example_onmicrosoft_com/