Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,14 @@
}
},
"scripts": {
"pest": "vendor/bin/pest --parallel",
"pest-cov": "vendor/bin/pest --coverage",
"pest-type": "vendor/bin/pest --type-coverage",
"pint": "vendor/bin/pint"
"lint": "vendor/bin/pint",
"test": "vendor/bin/pest --parallel",
"type-coverage": "vendor/bin/pest --coverage",
"test-coverage": "vendor/bin/pest --type-coverage",
"check": [
"@lint",
"@test-coverage",
"@type-coverage"
]
}
}
9 changes: 7 additions & 2 deletions src/AdminResources/CalendarEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ class CalendarEvents extends MsGraphAdmin
{
private string $userId = '';

private string $top = '';
private string $top = '100';

private string $skip = '';
private string $skip = '0';

public function userid(string $userId): static
{
Expand Down Expand Up @@ -58,6 +58,11 @@ public function get(string $calendarId, array $params = []): array
}

$events = MsGraphAdmin::get("users/$this->userId/calendars/$calendarId/events?$params");

if (isset($events->error)) {
throw new Exception("Graph API Error, code: {$events->error->code}, Message: {$events->error->message}");
}

$data = MsGraphAdmin::getPagination($events, $top, $skip);

return [
Expand Down
8 changes: 6 additions & 2 deletions src/AdminResources/Calendars.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ class Calendars extends MsGraphAdmin
{
private string $userId = '';

private string $top = '';
private string $top = '100';

private string $skip = '';
private string $skip = '0';

public function userid(string $userId): static
{
Expand Down Expand Up @@ -59,6 +59,10 @@ public function get(array $params = []): array

$calendars = MsGraphAdmin::get("users/$this->userId/calendars?$params");

if (isset($calendars->error)) {
throw new Exception("Graph API Error, code: {$calendars->error->code}, Message: {$calendars->error->message}");
}

$data = MsGraphAdmin::getPagination($calendars, $top, $skip);

return [
Expand Down
8 changes: 6 additions & 2 deletions src/AdminResources/Contacts.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ class Contacts extends MsGraphAdmin
{
private string $userId = '';

private string $top = '';
private string $top = '100';

private string $skip = '';
private string $skip = '0';

public function userid(string $userId): static
{
Expand Down Expand Up @@ -59,6 +59,10 @@ public function get(array $params = []): array

$contacts = MsGraphAdmin::get('users/'.$this->userId.'/contacts?'.$params);

if (isset($contacts->error)) {
throw new Exception("Graph API Error, code: {$contacts->error->code}, Message: {$contacts->error->message}");
}

$data = MsGraphAdmin::getPagination($contacts, $top, $skip);

return [
Expand Down
36 changes: 20 additions & 16 deletions src/AdminResources/Emails.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ class Emails extends MsGraphAdmin
{
private string $userId = '';

private string $top = '';
private string $top = '100';

private string $skip = '';
private string $skip = '0';

private string $subject = '';

Expand Down Expand Up @@ -129,9 +129,13 @@ public function get(array $params = []): array
$params = http_build_query($params);
}

//get messages from folderId
// get messages from folderId
$emails = MsGraphAdmin::get('users/'.$this->userId.'/messages?'.$params);

if (isset($emails->error)) {
throw new Exception("Graph API Error, code: {$emails->error->code}, Message: {$emails->error->message}");
}

$data = MsGraphAdmin::getPagination($emails, $top, $skip);

return [
Expand Down Expand Up @@ -163,21 +167,21 @@ public function findInlineAttachments(array $email): array
{
$attachments = self::findAttachments($email['id']);

//replace every case of <img='cid:' with the base64 image
// replace every case of <img='cid:' with the base64 image
$email['body']['content'] = preg_replace_callback(
'~cid.*?"~',
function (array $m) use ($attachments) {
//remove the last quote
// remove the last quote
$parts = explode('"', $m[0]);

//remove cid:
// remove cid:
$contentId = str_replace('cid:', '', $parts[0]);

//loop over the attachments
// loop over the attachments
foreach ($attachments['value'] as $file) {
//if there is a match
// if there is a match
if ($file['contentId'] == $contentId) {
//return a base64 image with a quote
// return a base64 image with a quote
return 'data:'.$file['contentType'].';base64,'.$file['contentBytes'].'"';
}
}
Expand Down Expand Up @@ -217,7 +221,7 @@ public function send(): void
/**
* @throws Exception
*/
public function reply()
public function reply(): MsGraphAdmin
{
if (strlen($this->userId) === 0) {
throw new Exception('userId is required.');
Expand All @@ -237,7 +241,7 @@ public function reply()
/**
* @throws Exception
*/
public function forward()
public function forward(): MsGraphAdmin
{
if (strlen($this->userId) === 0) {
throw new Exception('userId is required.');
Expand All @@ -257,7 +261,7 @@ public function forward()
/**
* @throws Exception
*/
public function delete(string $id)
public function delete(string $id): MsGraphAdmin
{
if ($this->userId == null) {
throw new Exception('userId is required.');
Expand Down Expand Up @@ -297,12 +301,12 @@ protected function prepareEmail(): array
}
}

$attachmentarray = [];
$attachmentArray = [];
if ($attachments != null) {
foreach ($attachments as $file) {
$path = pathinfo($file);

$attachmentarray[] = [
$attachmentArray[] = [
'@odata.type' => '#microsoft.graph.fileAttachment',
'name' => $path['basename'],
'contentType' => mime_content_type($file),
Expand Down Expand Up @@ -330,8 +334,8 @@ protected function prepareEmail(): array
if ($bccArray != null) {
$envelope['message']['bccRecipients'] = $bccArray;
}
if ($attachmentarray != null) {
$envelope['message']['attachments'] = $attachmentarray;
if ($attachmentArray != null) {
$envelope['message']['attachments'] = $attachmentArray;
}
if ($comment != null) {
$envelope['comment'] = $comment;
Expand Down
8 changes: 6 additions & 2 deletions src/AdminResources/Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ class Events extends MsGraphAdmin
{
private string $userId = '';

private string $top = '';
private string $top = '100';

private string $skip = '';
private string $skip = '0';

public function userid(string $userId): static
{
Expand Down Expand Up @@ -59,6 +59,10 @@ public function get(array $params = []): array

$events = MsGraphAdmin::get("users/$this->userId/events?$params");

if (isset($events->error)) {
throw new Exception("Graph API Error, code: {$events->error->code}, Message: {$events->error->message}");
}

$data = MsGraphAdmin::getPagination($events, $top, $skip);

return [
Expand Down
4 changes: 1 addition & 3 deletions src/Events/NewMicrosoft365SignInEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,5 @@ class NewMicrosoft365SignInEvent
use InteractsWithSockets;
use SerializesModels;

public function __construct(public array $token)
{
}
public function __construct(public array $token) {}
}
2 changes: 1 addition & 1 deletion src/Listeners/NewMicrosoft365SignInListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function handle(object $event): void
'password' => '',
]);

(new MsGraph())->storeToken(
(new MsGraph)->storeToken(
$event->token['accessToken'],
$event->token['refreshToken'],
$event->token['expires'],
Expand Down
10 changes: 6 additions & 4 deletions src/MsGraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
use Illuminate\Support\Facades\Http;
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
use League\OAuth2\Client\Provider\GenericProvider;
use Microsoft\Graph\Model\User;
use TestUser;

class MsGraph
{
Expand Down Expand Up @@ -56,7 +58,7 @@ public function tasks(): Tasks
return new Tasks;
}

protected static $user;
protected static User|TestUser|null $user = null;

protected static string $baseUrl = 'https://graph.microsoft.com/v1.0/';

Expand Down Expand Up @@ -88,12 +90,12 @@ public static function setUserModel(string $model): static
return new static;
}

public static function login($user)
public static function login(User|TestUser|null $user): void
{
self::$user = $user;
}

public static function getUser()
public static function getUser(): User|TestUser|null
{
return self::$user;
}
Expand Down Expand Up @@ -281,7 +283,7 @@ public function __call(string $function, array $args)
if (in_array($function, $options)) {
return self::guzzle($function, $path, $data, $headers, $id);
} else {
//request verb is not in the $options array
// request verb is not in the $options array
throw new Exception($function.' is not a valid HTTP Verb');
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/MsGraphAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,32 @@ class MsGraphAdmin
{
public function calendarEvents(): CalendarEvents
{
return new CalendarEvents();
return new CalendarEvents;
}

public function calendars(): Calendars
{
return new Calendars();
return new Calendars;
}

public function contacts(): Contacts
{
return new Contacts();
return new Contacts;
}

public function emails(): Emails
{
return new Emails();
return new Emails;
}

public function events(): Events
{
return new Events();
return new Events;
}

public function files(): Files
{
return new Files();
return new Files;
}

protected static string $baseUrl = 'https://graph.microsoft.com/v1.0/';
Expand Down Expand Up @@ -136,7 +136,7 @@ public function getTokenData(): ?MsGraphToken

protected function storeToken(string $access_token, string $refresh_token, string $expires): MsGraphToken
{
//Create or update a new record for admin token
// Create or update a new record for admin token
return MsGraphToken::updateOrCreate(['user_id' => null], [
'email' => 'application_token', // Placeholder name
'access_token' => $access_token,
Expand All @@ -157,7 +157,7 @@ public function __call(string $function, array $args): mixed
if (in_array($function, $options)) {
return self::guzzle($function, $path, $data);
} else {
//request verb is not in the $options array
// request verb is not in the $options array
throw new Exception($function.' is not a valid HTTP Verb');
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/MsGraphServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function registerFilesystem(): void
$clientId = config('msgraph.clientId');
$clientSecret = config('msgraph.clientSecret');

$guzzle = new Client();
$guzzle = new Client;
$response = $guzzle->post("https://login.microsoftonline.com/$tenantId/oauth2/v2.0/token",
[
'headers' => [
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/Contacts.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected function getParams(array $params, int $perPage): string
'$count' => 'true',
]);
} else {
//ensure $top, $skip and $count are part of params
// ensure $top, $skip and $count are part of params
if (! in_array('$top', $params)) {
$params['$top'] = $perPage;
}
Expand Down
Loading