diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml
index ff408e8..4e521ca 100644
--- a/.github/workflows/php.yml
+++ b/.github/workflows/php.yml
@@ -10,7 +10,7 @@ jobs:
strategy:
max-parallel: 2
matrix:
- php-versions: ['8.2']
+ php-versions: ['8.1', '8.2', '8.3']
name: PHP ${{ matrix.php-versions }}
@@ -29,5 +29,8 @@ jobs:
- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest
+ - name: Run Pint
+ run: ./vendor/bin/pint --test
+
- name: Run test suite
- run: ./vendor/bin/pest
+ run: ./vendor/bin/pest --parallel
diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php
deleted file mode 100644
index d4f72bc..0000000
--- a/.php-cs-fixer.dist.php
+++ /dev/null
@@ -1,168 +0,0 @@
- ['syntax' => 'short'],
-
- 'no_unused_imports' => true,
- 'blank_line_after_namespace' => true,
- 'blank_line_after_opening_tag' => true,
- 'braces' => true,
- 'cast_spaces' => true,
- 'concat_space' => [
- 'spacing' => 'none',
- ],
- 'declare_equal_normalize' => true,
- 'elseif' => true,
- 'encoding' => true,
- 'full_opening_tag' => true,
- 'fully_qualified_strict_types' => true, // added by Shift
- 'function_declaration' => true,
- 'function_typehint_space' => true,
- 'heredoc_to_nowdoc' => true,
- 'include' => true,
- 'increment_style' => ['style' => 'post'],
- 'indentation_type' => true,
- 'linebreak_after_opening_tag' => true,
- 'line_ending' => true,
- 'lowercase_cast' => true,
- 'lowercase_keywords' => true,
- 'lowercase_static_reference' => true, // added from Symfony
- 'magic_method_casing' => true, // added from Symfony
- 'magic_constant_casing' => true,
- 'method_argument_space' => true,
- 'native_function_casing' => true,
- 'no_alias_functions' => true,
- 'no_extra_blank_lines' => [
- 'tokens' => [
- 'extra',
- 'throw',
- 'use',
- ],
- ],
- 'no_blank_lines_after_class_opening' => true,
- 'no_blank_lines_after_phpdoc' => true,
- 'no_closing_tag' => true,
- 'no_empty_phpdoc' => true,
- 'no_empty_statement' => true,
- 'no_leading_import_slash' => true,
- 'no_leading_namespace_whitespace' => true,
- 'no_mixed_echo_print' => [
- 'use' => 'echo',
- ],
- 'no_multiline_whitespace_around_double_arrow' => true,
- 'multiline_whitespace_before_semicolons' => [
- 'strategy' => 'no_multi_line',
- ],
- 'no_short_bool_cast' => true,
- 'no_singleline_whitespace_before_semicolons' => true,
- 'no_spaces_after_function_name' => true,
- 'no_spaces_inside_parenthesis' => true,
- 'no_trailing_comma_in_list_call' => true,
- 'no_trailing_comma_in_singleline_array' => true,
- 'no_trailing_whitespace' => true,
- 'no_trailing_whitespace_in_comment' => true,
- 'no_unreachable_default_argument_value' => true,
- 'no_useless_return' => true,
- 'no_whitespace_before_comma_in_array' => true,
- 'no_whitespace_in_blank_line' => true,
- 'normalize_index_brace' => true,
- 'not_operator_with_successor_space' => true,
- 'object_operator_without_whitespace' => true,
- 'phpdoc_indent' => true,
- 'phpdoc_no_access' => true,
- 'phpdoc_no_package' => true,
- 'phpdoc_no_useless_inheritdoc' => true,
- 'phpdoc_scalar' => true,
- 'phpdoc_single_line_var_spacing' => true,
- 'phpdoc_summary' => true,
- 'phpdoc_to_comment' => true,
- 'phpdoc_trim' => true,
- 'phpdoc_types' => true,
- 'phpdoc_var_without_name' => true,
- 'self_accessor' => true,
- 'short_scalar_cast' => true,
- 'simplified_null_return' => false, // disabled by Shift
- 'single_blank_line_at_eof' => true,
- 'single_blank_line_before_namespace' => true,
- 'single_import_per_statement' => true,
- 'single_line_after_imports' => true,
- 'single_line_comment_style' => [
- 'comment_types' => ['hash'],
- ],
- 'single_quote' => true,
- 'space_after_semicolon' => true,
- 'standardize_not_equals' => true,
- 'switch_case_semicolon_to_colon' => true,
- 'switch_case_space' => true,
- 'ternary_operator_spaces' => true,
- 'trim_array_spaces' => false,
- 'unary_operator_spaces' => true,
- 'whitespace_after_comma_in_array' => true,
-
- // php-cs-fixer 3: Renamed rules
- 'constant_case' => ['case' => 'lower'],
- 'general_phpdoc_tag_rename' => true,
- 'phpdoc_inline_tag_normalizer' => true,
- 'phpdoc_tag_type' => true,
- 'psr_autoloading' => true,
- 'trailing_comma_in_multiline' => ['elements' => ['arrays']],
-
- // php-cs-fixer 3: Changed options
- 'binary_operator_spaces' => [
- 'default' => 'align_single_space',
- 'operators' => [
- '=>' => 'align_single_space',
- '=' => 'align_single_space',
- ],
- ],
- 'blank_line_before_statement' => [
- 'statements' => ['return'],
- ],
- 'class_attributes_separation' => [
- 'elements' => [
- 'const' => 'none',
- 'method' => 'one',
- 'property' => 'none',
- 'trait_import' => 'none',
- ],
- ],
- 'class_definition' => [
- 'multi_line_extends_each_single_line' => true,
- 'single_item_single_line' => true,
- 'single_line' => true,
- ],
- 'ordered_imports' => [
- 'sort_algorithm' => 'alpha',
- ],
-
- // php-cs-fixer 3: Removed rootless options (*)
- 'no_unneeded_control_parentheses' => [
- 'statements' => ['break', 'clone', 'continue', 'echo_print', 'return', 'switch_case', 'yield'],
- ],
- 'no_spaces_around_offset' => [
- 'positions' => ['inside', 'outside'],
- ],
- 'visibility_required' => [
- 'elements' => ['property', 'method', 'const'],
- ],
-
-];
-
-$finder = Finder::create()
- ->in([
- __DIR__.'/src',
- __DIR__.'/config',
- __DIR__.'/tests',
- ])
- ->name('*.php')
- ->ignoreDotFiles(true)
- ->ignoreVCS(true);
-
-return (new Config())
- ->setFinder($finder)
- ->setRules($rules)
- ->setRiskyAllowed(true)
- ->setUsingCache(true);
diff --git a/changelog.md b/changelog.md
index 1b8e911..b4b22d9 100755
--- a/changelog.md
+++ b/changelog.md
@@ -402,4 +402,16 @@ Where $behavior is either rename or replace
### Removed
-- Removed package level migrations, using src migrations instead
\ No newline at end of file
+- Removed package level migrations, using src migrations instead
+
+## Next
+
+## Added
+
+- Added sites resource for MsGraph
+- Added Pint with Laravel preset for formatting
+- Added composer scripts for formatting and testing
+
+## Changed
+- Fixed an issue in MsGraph connect having an infinite loop when an error is returned from Microsoft
+- Dropped support for using csfixer
diff --git a/composer.json b/composer.json
index de99b2a..72a1d4a 100755
--- a/composer.json
+++ b/composer.json
@@ -1,65 +1,71 @@
{
- "name": "dcblogdev/laravel-microsoft-graph",
- "description": "A Laravel Microsoft Graph API (Office365) package",
- "license": "MIT",
- "authors": [
- {
- "name": "David Carr",
- "email": "dave@dcblog.dev",
- "homepage": "https://dcblog.dev"
- }
- ],
- "homepage": "https://github.com/dcblogdev/laravel-microsoft-graph",
- "keywords": [
- "Laravel",
- "MsGraph",
- "Graph",
- "Microsoft Graph",
- "Office365",
- "Microsoft365"
- ],
- "require": {
- "illuminate/support": "5.5.x|5.6.x|5.7.x|5.8.x|6.x|7.x|8.x|9.x|^10.0",
- "league/oauth2-client": "^1.4|^2",
- "guzzlehttp/guzzle": "6.x|7.x",
- "ext-json": "*",
- "ext-fileinfo": "*",
- "ext-curl": "*",
- "shitware-ltd/flysystem-msgraph": "^1.0",
- "microsoft/microsoft-graph": "^1.70"
- },
- "require-dev": {
- "orchestra/testbench": "^7.0|^8.0",
- "pestphp/pest": "^1.21",
- "pestphp/pest-plugin-laravel": "^1.1",
- "friendsofphp/php-cs-fixer": "^3.9",
- "pestphp/pest-plugin-mock": "^1.0"
- },
- "autoload": {
- "psr-4": {
- "Dcblogdev\\MsGraph\\": "src/",
- "Dcblogdev\\MsGraph\\Tests\\": "tests"
- }
- },
- "autoload-dev": {
- "classmap": [
- "tests/TestCase.php"
- ]
- },
- "extra": {
- "laravel": {
- "providers": [
- "Dcblogdev\\MsGraph\\MsGraphServiceProvider"
- ],
- "aliases": {
- "MsGraph": "Dcblogdev\\MsGraph\\Facades\\MsGraph",
- "MsGraphAdmin": "Dcblogdev\\MsGraph\\Facades\\MsGraphAdmin"
- }
- }
- },
- "config": {
- "allow-plugins": {
- "pestphp/pest-plugin": true
- }
+ "name": "dcblogdev/laravel-microsoft-graph",
+ "description": "A Laravel Microsoft Graph API (Office365) package",
+ "license": "MIT",
+ "authors": [
+ {
+ "name": "David Carr",
+ "email": "dave@dcblog.dev",
+ "homepage": "https://dcblog.dev"
}
+ ],
+ "homepage": "https://github.com/dcblogdev/laravel-microsoft-graph",
+ "keywords": [
+ "Laravel",
+ "MsGraph",
+ "Graph",
+ "Microsoft Graph",
+ "Office365",
+ "Microsoft365"
+ ],
+ "require": {
+ "illuminate/support": "5.5.x|5.6.x|5.7.x|5.8.x|6.x|7.x|8.x|9.x|^10.0",
+ "league/oauth2-client": "^1.4|^2",
+ "guzzlehttp/guzzle": "6.x|7.x",
+ "ext-json": "*",
+ "ext-fileinfo": "*",
+ "ext-curl": "*",
+ "shitware-ltd/flysystem-msgraph": "^1.0",
+ "microsoft/microsoft-graph": "^1.70"
+ },
+ "require-dev": {
+ "orchestra/testbench": "^7.0|^8.0",
+ "pestphp/pest": "^1.21",
+ "pestphp/pest-plugin-laravel": "^1.1",
+ "friendsofphp/php-cs-fixer": "^3.9",
+ "pestphp/pest-plugin-mock": "^1.0",
+ "laravel/pint": "^1.13",
+ "pestphp/pest-plugin-parallel": "^1.2"
+ },
+ "autoload": {
+ "psr-4": {
+ "Dcblogdev\\MsGraph\\": "src/",
+ "Dcblogdev\\MsGraph\\Tests\\": "tests"
+ }
+ },
+ "autoload-dev": {
+ "classmap": [
+ "tests/TestCase.php"
+ ]
+ },
+ "extra": {
+ "laravel": {
+ "providers": [
+ "Dcblogdev\\MsGraph\\MsGraphServiceProvider"
+ ],
+ "aliases": {
+ "MsGraph": "Dcblogdev\\MsGraph\\Facades\\MsGraph",
+ "MsGraphAdmin": "Dcblogdev\\MsGraph\\Facades\\MsGraphAdmin"
+ }
+ }
+ },
+ "config": {
+ "allow-plugins": {
+ "pestphp/pest-plugin": true
+ }
+ },
+ "scripts": {
+ "test": "vendor/bin/pest --parallel",
+ "pint": "vendor/bin/pint"
+ }
}
diff --git a/config/msgraph.php b/config/msgraph.php
index 54b5d5a..4a488b2 100755
--- a/config/msgraph.php
+++ b/config/msgraph.php
@@ -28,7 +28,7 @@
* set the url to be redirected to once the token has been saved
*/
- 'msgraphLandingUri' => env('MSGRAPH_LANDING_URL'),
+ 'msgraphLandingUri' => env('MSGRAPH_LANDING_URL'),
/*
set the tenant authorize url
diff --git a/docs/v3/nav.php b/docs/v3/nav.php
index cf07cd7..8ebeb4a 100644
--- a/docs/v3/nav.php
+++ b/docs/v3/nav.php
@@ -2,67 +2,67 @@
return [
[
- 'name' => 'Introduction',
- 'url' => 'introduction',
+ 'name' => 'Introduction',
+ 'url' => 'introduction',
],
[
- 'name' => 'Install',
- 'url' => 'install',
+ 'name' => 'Install',
+ 'url' => 'install',
],
[
- 'name' => 'MsGraph',
- 'url' => 'msgraph',
+ 'name' => 'MsGraph',
+ 'url' => 'msgraph',
'children' => [
[
- 'name' => 'Is Connected',
- 'url' => 'msgraph/is-connected',
+ 'name' => 'Is Connected',
+ 'url' => 'msgraph/is-connected',
],
[
- 'name' => 'Disconnect',
- 'url' => 'msgraph/disconnect',
+ 'name' => 'Disconnect',
+ 'url' => 'msgraph/disconnect',
],
[
- 'name' => 'Middleware',
- 'url' => 'msgraph/middleware',
+ 'name' => 'Middleware',
+ 'url' => 'msgraph/middleware',
],
[
- 'name' => 'Login with MsGraph',
- 'url' => 'msgraph/login-with-msgraph',
+ 'name' => 'Login with MsGraph',
+ 'url' => 'msgraph/login-with-msgraph',
],
[
- 'name' => 'Contacts',
- 'url' => 'msgraph/contacts',
+ 'name' => 'Contacts',
+ 'url' => 'msgraph/contacts',
],
[
- 'name' => 'Emails',
- 'url' => 'msgraph/emails'
+ 'name' => 'Emails',
+ 'url' => 'msgraph/emails',
],
[
- 'name' => 'Files',
- 'url' => 'msgraph/files'
+ 'name' => 'Files',
+ 'url' => 'msgraph/files',
],
[
- 'name' => 'Filesystem',
- 'url' => 'msgraph/filesystem'
+ 'name' => 'Filesystem',
+ 'url' => 'msgraph/filesystem',
],
],
],
[
- 'name' => 'MsGraph Admin',
- 'url' => 'msgraphadmin',
+ 'name' => 'MsGraph Admin',
+ 'url' => 'msgraphadmin',
'children' => [
[
- 'name' => 'Middleware',
- 'url' => 'msgraphadmin/middleware',
+ 'name' => 'Middleware',
+ 'url' => 'msgraphadmin/middleware',
],
[
- 'name' => 'Contacts',
- 'url' => 'msgraphadmin/contacts',
+ 'name' => 'Contacts',
+ 'url' => 'msgraphadmin/contacts',
],
[
- 'name' => 'Emails',
- 'url' => 'msgraphadmin/emails'
+ 'name' => 'Emails',
+ 'url' => 'msgraphadmin/emails',
],
- ]
- ]
-];
\ No newline at end of file
+ ],
+ ],
+];
diff --git a/pint.json b/pint.json
new file mode 100644
index 0000000..661e522
--- /dev/null
+++ b/pint.json
@@ -0,0 +1,3 @@
+{
+ "preset": "laravel"
+}
\ No newline at end of file
diff --git a/src/AdminResources/CalendarEvents.php b/src/AdminResources/CalendarEvents.php
index 9abe46b..01c5a52 100644
--- a/src/AdminResources/CalendarEvents.php
+++ b/src/AdminResources/CalendarEvents.php
@@ -8,7 +8,9 @@
class CalendarEvents extends MsGraphAdmin
{
private $userId;
+
private $top;
+
private $skip;
public function userid($userId)
@@ -38,28 +40,28 @@ public function get($calendarId, $params = [])
throw new Exception('userId is required.');
}
- $top = request('top', $this->top);
+ $top = request('top', $this->top);
$skip = request('skip', $this->skip);
if ($params == []) {
$params = http_build_query([
'$orderby' => 'subject',
- '$top' => $top,
- '$skip' => $skip,
- '$count' => 'true',
+ '$top' => $top,
+ '$skip' => $skip,
+ '$count' => 'true',
]);
} else {
$params = http_build_query($params);
}
$events = MsGraphAdmin::get("users/$this->userId/calendars/$calendarId/events?$params");
- $data = MsGraphAdmin::getPagination($events, $top, $skip);
+ $data = MsGraphAdmin::getPagination($events, $top, $skip);
return [
'events' => $events,
- 'total' => $data['total'],
- 'top' => $data['top'],
- 'skip' => $data['skip'],
+ 'total' => $data['total'],
+ 'top' => $data['top'],
+ 'skip' => $data['skip'],
];
}
diff --git a/src/AdminResources/Calendars.php b/src/AdminResources/Calendars.php
index 59ac159..c402a21 100644
--- a/src/AdminResources/Calendars.php
+++ b/src/AdminResources/Calendars.php
@@ -8,7 +8,9 @@
class Calendars extends MsGraphAdmin
{
private $userId;
+
private $top;
+
private $skip;
public function userid($userId)
@@ -38,15 +40,15 @@ public function get($params = [])
throw new Exception('userId is required.');
}
- $top = request('top', $this->top);
+ $top = request('top', $this->top);
$skip = request('skip', $this->skip);
if ($params == []) {
$params = http_build_query([
'$orderby' => 'name',
- '$top' => $top,
- '$skip' => $skip,
- '$count' => 'true',
+ '$top' => $top,
+ '$skip' => $skip,
+ '$count' => 'true',
]);
} else {
$params = http_build_query($params);
@@ -58,9 +60,9 @@ public function get($params = [])
return [
'calendars' => $calendars,
- 'total' => $data['total'],
- 'top' => $data['top'],
- 'skip' => $data['skip'],
+ 'total' => $data['total'],
+ 'top' => $data['top'],
+ 'skip' => $data['skip'],
];
}
diff --git a/src/AdminResources/Contacts.php b/src/AdminResources/Contacts.php
index 75b934c..204fa03 100644
--- a/src/AdminResources/Contacts.php
+++ b/src/AdminResources/Contacts.php
@@ -8,7 +8,9 @@
class Contacts extends MsGraphAdmin
{
private $userId;
+
private $top;
+
private $skip;
public function userid($userId)
@@ -38,15 +40,15 @@ public function get($params = [])
throw new Exception('userId is required.');
}
- $top = request('top', $this->top);
+ $top = request('top', $this->top);
$skip = request('skip', $this->skip);
if ($params == []) {
$params = http_build_query([
'$orderby' => 'displayName',
- '$top' => $top,
- '$skip' => $skip,
- '$count' => 'true',
+ '$top' => $top,
+ '$skip' => $skip,
+ '$count' => 'true',
]);
} else {
$params = http_build_query($params);
@@ -58,9 +60,9 @@ public function get($params = [])
return [
'contacts' => $contacts,
- 'total' => $data['total'],
- 'top' => $data['top'],
- 'skip' => $data['skip'],
+ 'total' => $data['total'],
+ 'top' => $data['top'],
+ 'skip' => $data['skip'],
];
}
diff --git a/src/AdminResources/Emails.php b/src/AdminResources/Emails.php
index fccbab4..04cd36c 100644
--- a/src/AdminResources/Emails.php
+++ b/src/AdminResources/Emails.php
@@ -8,15 +8,25 @@
class Emails extends MsGraphAdmin
{
private $userId;
+
private $top;
+
private $skip;
+
private $subject;
+
private $body;
+
private $comment;
+
private $id;
+
private $to;
+
private $cc;
+
private $bcc;
+
private $attachments;
public function userid($userId)
@@ -102,14 +112,14 @@ public function get($params = [])
throw new Exception('userId is required.');
}
- $top = request('top', $this->top);
+ $top = request('top', $this->top);
$skip = request('skip', $this->skip);
if ($params == []) {
$params = http_build_query([
- '$top' => $top,
- '$skip' => $skip,
- '$count' => 'true',
+ '$top' => $top,
+ '$skip' => $skip,
+ '$count' => 'true',
'$orderby' => 'sentDateTime desc',
]);
} else {
@@ -123,9 +133,9 @@ public function get($params = [])
return [
'emails' => $emails,
- 'total' => $data['total'],
- 'top' => $data['top'],
- 'skip' => $data['skip'],
+ 'total' => $data['total'],
+ 'top' => $data['top'],
+ 'skip' => $data['skip'],
];
}
@@ -238,12 +248,12 @@ public function delete($id)
protected function prepareEmail()
{
- $subject = $this->subject;
- $body = $this->body;
- $comment = $this->comment;
- $to = $this->to;
- $cc = $this->cc;
- $bcc = $this->bcc;
+ $subject = $this->subject;
+ $body = $this->body;
+ $comment = $this->comment;
+ $to = $this->to;
+ $cc = $this->cc;
+ $bcc = $this->bcc;
$attachments = $this->attachments;
$toArray = [];
@@ -273,9 +283,9 @@ protected function prepareEmail()
$path = pathinfo($file);
$attachmentarray[] = [
- '@odata.type' => '#microsoft.graph.fileAttachment',
- 'name' => $path['basename'],
- 'contentType' => mime_content_type($file),
+ '@odata.type' => '#microsoft.graph.fileAttachment',
+ 'name' => $path['basename'],
+ 'contentType' => mime_content_type($file),
'contentBytes' => base64_encode(file_get_contents($file)),
];
}
@@ -288,7 +298,7 @@ protected function prepareEmail()
if ($body != null) {
$envelope['message']['body'] = [
'contentType' => 'html',
- 'content' => $body,
+ 'content' => $body,
];
}
if ($toArray != null) {
diff --git a/src/AdminResources/Events.php b/src/AdminResources/Events.php
index be43aa0..b601a5c 100644
--- a/src/AdminResources/Events.php
+++ b/src/AdminResources/Events.php
@@ -8,7 +8,9 @@
class Events extends MsGraphAdmin
{
private $userId;
+
private $top;
+
private $skip;
public function userid($userId)
@@ -38,15 +40,15 @@ public function get($params = [])
throw new Exception('userId is required.');
}
- $top = request('top', $this->top);
+ $top = request('top', $this->top);
$skip = request('skip', $this->skip);
if ($params == []) {
$params = http_build_query([
'$orderby' => 'subject',
- '$top' => $top,
- '$skip' => $skip,
- '$count' => 'true',
+ '$top' => $top,
+ '$skip' => $skip,
+ '$count' => 'true',
]);
} else {
$params = http_build_query($params);
@@ -58,9 +60,9 @@ public function get($params = [])
return [
'events' => $events,
- 'total' => $data['total'],
- 'top' => $data['top'],
- 'skip' => $data['skip'],
+ 'total' => $data['total'],
+ 'top' => $data['top'],
+ 'skip' => $data['skip'],
];
}
diff --git a/src/Console/Commands/MsGraphAdminKeepAliveCommand.php b/src/Console/Commands/MsGraphAdminKeepAliveCommand.php
index 3f41d7b..6d07de7 100644
--- a/src/Console/Commands/MsGraphAdminKeepAliveCommand.php
+++ b/src/Console/Commands/MsGraphAdminKeepAliveCommand.php
@@ -7,7 +7,8 @@
class MsGraphAdminKeepAliveCommand extends Command
{
- protected $signature = 'msgraphadmin:keep-alive';
+ protected $signature = 'msgraphadmin:keep-alive';
+
protected $description = 'Run this command to refresh token if its due to expire. schedule this to run daily to avoid token expiring when using CLI commands';
public function handle()
@@ -17,4 +18,4 @@ public function handle()
$this->comment('connected');
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Console/Commands/MsGraphKeepAliveCommand.php b/src/Console/Commands/MsGraphKeepAliveCommand.php
index 9ee0365..5f90b24 100644
--- a/src/Console/Commands/MsGraphKeepAliveCommand.php
+++ b/src/Console/Commands/MsGraphKeepAliveCommand.php
@@ -7,7 +7,8 @@
class MsGraphKeepAliveCommand extends Command
{
- protected $signature = 'msgraph:keep-alive';
+ protected $signature = 'msgraph:keep-alive';
+
protected $description = 'Run this command to refresh token if its due to expire. schedule this to run daily to avoid token expiring when using CLI commands';
public function handle()
@@ -17,4 +18,4 @@ public function handle()
$this->comment('connected');
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Helpers/Paginator.php b/src/Helpers/Paginator.php
index 0597c59..734595b 100644
--- a/src/Helpers/Paginator.php
+++ b/src/Helpers/Paginator.php
@@ -5,14 +5,17 @@
class Paginator
{
protected $perPage;
+
protected $instance;
+
protected $page;
+
protected $totalRows = 0;
public function __construct($perPage, $instance)
{
$this->instance = $instance;
- $this->perPage = $perPage;
+ $this->perPage = $perPage;
$this->setInstance();
}
@@ -23,7 +26,7 @@ public function get_start()
protected function setInstance()
{
- $this->page = (int) (!isset($_GET[$this->instance]) ? 1 : $_GET[$this->instance]);
+ $this->page = (int) (! isset($_GET[$this->instance]) ? 1 : $_GET[$this->instance]);
$this->page = ($this->page == 0 ? 1 : ($this->page < 0 ? 1 : $this->page));
}
@@ -40,13 +43,13 @@ public function page_links()
$path = $path.http_build_query($queryParams->all()).'&';
}
- $adjacents = "2";
- $prev = $this->page - 1;
- $next = $this->page + 1;
- $lastpage = ceil($this->totalRows / $this->perPage);
- $lpm1 = $lastpage - 1;
+ $adjacents = '2';
+ $prev = $this->page - 1;
+ $next = $this->page + 1;
+ $lastpage = ceil($this->totalRows / $this->perPage);
+ $lpm1 = $lastpage - 1;
- $pagination = "";
+ $pagination = '';
if ($lastpage > 1) {
$pagination .= "
\n";
}
-
return $pagination;
}
public function page_links_array($path = '?', $ext = null)
{
$lastpage = ceil($this->totalRows / $this->perPage);
- $pages = [];
+ $pages = [];
for ($counter = 1; $counter <= $lastpage; $counter++) {
$pages[] = $counter;
@@ -126,4 +128,4 @@ public function page_links_array($path = '?', $ext = null)
return $pages;
}
-}
\ No newline at end of file
+}
diff --git a/src/Listeners/NewMicrosoft365SignInListener.php b/src/Listeners/NewMicrosoft365SignInListener.php
index d6194c9..b3941ae 100644
--- a/src/Listeners/NewMicrosoft365SignInListener.php
+++ b/src/Listeners/NewMicrosoft365SignInListener.php
@@ -10,11 +10,11 @@ class NewMicrosoft365SignInListener
{
public function handle($event)
{
- $user = User::firstOrCreate([
+ $user = User::firstOrCreate([
'email' => $event->token['info']['mail'],
], [
- 'name' => $event->token['info']['displayName'],
- 'email' => $event->token['info']['mail'] ?? $event->token['info']['userPrincipalName'],
+ 'name' => $event->token['info']['displayName'],
+ 'email' => $event->token['info']['mail'] ?? $event->token['info']['userPrincipalName'],
'password' => '',
]);
@@ -28,4 +28,4 @@ public function handle($event)
Auth::login($user);
}
-}
\ No newline at end of file
+}
diff --git a/src/MsGraph.php b/src/MsGraph.php
index 83f3f0e..6af0e82 100755
--- a/src/MsGraph.php
+++ b/src/MsGraph.php
@@ -11,6 +11,7 @@
use Dcblogdev\MsGraph\Resources\Contacts;
use Dcblogdev\MsGraph\Resources\Emails;
use Dcblogdev\MsGraph\Resources\Files;
+use Dcblogdev\MsGraph\Resources\Sites;
use Dcblogdev\MsGraph\Resources\Tasks\TaskLists;
use Dcblogdev\MsGraph\Resources\Tasks\Tasks;
use Exception;
@@ -39,6 +40,11 @@ public function files()
return new Files();
}
+ public function sites()
+ {
+ return new Sites();
+ }
+
public function tasklists()
{
return new TaskLists();
@@ -51,12 +57,14 @@ public function tasks()
/**
* Set the base url that all API requests use.
+ *
* @var string
*/
protected static $baseUrl = 'https://graph.microsoft.com/v1.0/';
/**
* Set the User model
+ *
* @var string
*/
protected static $userModel;
@@ -75,9 +83,6 @@ public function setApiVersion($version = '1.0'): static
return $this;
}
- /**
- * @return static
- */
public static function setUserModel($model): static
{
self::$userModel = $model;
@@ -87,6 +92,7 @@ public static function setUserModel($model): static
/**
* Make a connection or return a token where it's valid.
+ *
* @return mixed
*/
public function connect($id = null)
@@ -95,7 +101,7 @@ public function connect($id = null)
$provider = $this->getProvider();
- if (!$this->isConnected($id)) {
+ if (! $this->isConnected($id)) {
$token = $this->getTokenData($id);
if ($token !== null) {
@@ -106,9 +112,17 @@ public function connect($id = null)
}
}
- if (!request()->has('code') && !$this->isConnected($id)) {
+ if (request()->has('error')) {
+
+ return trigger_error('Error: '.request('error').'
Description: '.request('error_description'),
+ E_USER_ERROR);
+
+ } elseif (! request()->has('code') && ! $this->isConnected($id)) {
+
return redirect($provider->getAuthorizationUrl());
+
} elseif (request()->has('code')) {
+
$accessToken = $provider->getAccessToken('authorization_code', ['code' => request('code')]);
$response = Http::withToken($accessToken->getToken())->get(self::$baseUrl.'me');
@@ -123,10 +137,10 @@ public function connect($id = null)
);
} else {
event(new NewMicrosoft365SignInEvent([
- 'info' => $response->json(),
- 'accessToken' => $accessToken->getToken(),
+ 'info' => $response->json(),
+ 'accessToken' => $accessToken->getToken(),
'refreshToken' => $accessToken->getRefreshToken(),
- 'expires' => $accessToken->getExpires(),
+ 'expires' => $accessToken->getExpires(),
]));
}
}
@@ -135,7 +149,6 @@ public function connect($id = null)
}
/**
- * @param $id
* @return bool
*/
public function isConnected($id = null)
@@ -155,6 +168,7 @@ public function isConnected($id = null)
/**
* logout of application and Microsoft 365, redirects back to the provided path.
+ *
* @param string $redirectPath
* @return RedirectResponse
*/
@@ -169,17 +183,18 @@ public function disconnect($redirectPath = '/', $logout = true)
/**
* Return authenticated access token or request new token when expired.
- * @param $id integer - id of the user
- * @param $returnNullNoAccessToken null when set to true return null
+ *
+ * @param $id integer - id of the user
+ * @param $returnNullNoAccessToken null when set to true return null
* @return Application|\Illuminate\Foundation\Application|RedirectResponse|\Illuminate\Routing\Redirector string access token
*/
public function getAccessToken($id = null, $redirectWhenNotConnected = true)
{
$token = $this->getTokenData($id);
- $id = $this->getUserId($id);
+ $id = $this->getUserId($id);
if ($redirectWhenNotConnected) {
- if (!$this->isConnected()) {
+ if (! $this->isConnected()) {
return redirect()->away(config('msgraph.redirectUri'));
}
}
@@ -190,6 +205,7 @@ public function getAccessToken($id = null, $redirectWhenNotConnected = true)
if ($token->expires < time() + 300) {
$user = (self::$userModel ?: config('auth.providers.users.model'))::find($id);
+
return $this->renewExpiringToken($token, $id, $user->email);
}
@@ -197,53 +213,56 @@ public function getAccessToken($id = null, $redirectWhenNotConnected = true)
}
/**
- * @param $id - integar id of user
+ * @param $id - integar id of user
* @return object
*/
public function getTokenData($id = null)
{
$id = $this->getUserId($id);
+
return MsGraphToken::where('user_id', $id)->where('refresh_token', '<>', '')->first();
}
/**
* Store token.
- * @param $access_token string
- * @param $refresh_token string
- * @param $expires string
- * @param $id integer
+ *
+ * @param $access_token string
+ * @param $refresh_token string
+ * @param $expires string
+ * @param $id integer
* @return object
*/
public function storeToken($access_token, $refresh_token, $expires, $id, $email)
{
return MsGraphToken::updateOrCreate(['user_id' => $id], [
- 'user_id' => $id,
- 'email' => $email,
- 'access_token' => $access_token,
- 'expires' => $expires,
+ 'user_id' => $id,
+ 'email' => $email,
+ 'access_token' => $access_token,
+ 'expires' => $expires,
'refresh_token' => $refresh_token,
]);
}
/**
* return array containing previous and next page counts.
- * @param $data array
- * @param $total array
- * @param $limit integer
- * @param $skip integer
+ *
+ * @param $data array
+ * @param $total array
+ * @param $limit integer
+ * @param $skip integer
* @return array
*/
public function getPagination(array $data, int $total, int $limit, int $skip)
{
$previous = 0;
- $next = 0;
+ $next = 0;
if (isset($data['@odata.nextLink'])) {
$parts = explode('skip=', $data['@odata.nextLink']);
if (isset($parts[1])) {
$previous = $parts[1] - $limit;
- $next = $parts[1];
+ $next = $parts[1];
}
if ($previous < 0) {
@@ -265,21 +284,19 @@ public function getPagination(array $data, int $total, int $limit, int $skip)
return [
'previous' => $previous,
- 'next' => $next,
+ 'next' => $next,
];
}
/**
- * @param $token
- * @param $id
- * @param $email
* @return mixed|string
+ *
* @throws IdentityProviderException
*/
protected function renewExpiringToken($token, $id, $email)
{
$oauthClient = $this->getProvider();
- $newToken = $oauthClient->getAccessToken('refresh_token', ['refresh_token' => $token->refresh_token]);
+ $newToken = $oauthClient->getAccessToken('refresh_token', ['refresh_token' => $token->refresh_token]);
$this->storeToken($newToken->getToken(), $newToken->getRefreshToken(), $newToken->getExpires(), $id, $email);
return $newToken->getToken();
@@ -287,18 +304,20 @@ protected function renewExpiringToken($token, $id, $email)
/**
* __call catches all requests when no found method is requested.
- * @param $function - the verb to execute
- * @param $args - array of arguments
+ *
+ * @param $function - the verb to execute
+ * @param $args - array of arguments
* @return json request
+ *
* @throws Exception
*/
public function __call($function, $args)
{
$options = ['get', 'post', 'patch', 'put', 'delete'];
- $path = (isset($args[0])) ? $args[0] : null;
- $data = (isset($args[1])) ? $args[1] : null;
+ $path = (isset($args[0])) ? $args[0] : null;
+ $data = (isset($args[1])) ? $args[1] : null;
$headers = (isset($args[2])) ? $args[2] : null;
- $id = (isset($args[3])) ? $args[3] : auth()->id();
+ $id = (isset($args[3])) ? $args[3] : auth()->id();
if (in_array($function, $options)) {
return self::guzzle($function, $path, $data, $headers, $id);
@@ -310,11 +329,12 @@ public function __call($function, $args)
/**
* run guzzle to process requested url.
- * @param $type string
- * @param $request string
- * @param $data array
+ *
+ * @param $type string
+ * @param $request string
+ * @param $data array
* @param array $headers
- * @param $id integer
+ * @param $id integer
* @return json object
*/
protected function guzzle($type, $request, $data = [], $headers = [], $id = null)
@@ -324,8 +344,8 @@ protected function guzzle($type, $request, $data = [], $headers = [], $id = null
$mainHeaders = [
'Authorization' => 'Bearer '.$this->getAccessToken($id),
- 'content-type' => 'application/json',
- 'Prefer' => config('msgraph.preferTimezone'),
+ 'content-type' => 'application/json',
+ 'Prefer' => config('msgraph.preferTimezone'),
];
if (is_array($headers)) {
@@ -336,7 +356,7 @@ protected function guzzle($type, $request, $data = [], $headers = [], $id = null
$response = $client->$type(self::$baseUrl.$request, [
'headers' => $headers,
- 'body' => json_encode($data),
+ 'body' => json_encode($data),
]);
$responseObject = $response->getBody()->getContents();
@@ -357,7 +377,6 @@ protected function guzzle($type, $request, $data = [], $headers = [], $id = null
}
/**
- * @param $string
* @return bool
*/
protected function isJson($string)
@@ -366,7 +385,6 @@ protected function isJson($string)
}
/**
- * @param $id
* @return int|mixed|string|null
*/
protected function getUserId($id = null)
@@ -385,13 +403,13 @@ protected function getProvider()
{
//set up the provides loaded values from the config
return new GenericProvider([
- 'clientId' => config('msgraph.clientId'),
- 'clientSecret' => config('msgraph.clientSecret'),
- 'redirectUri' => config('msgraph.redirectUri'),
- 'urlAuthorize' => config('msgraph.urlAuthorize'),
- 'urlAccessToken' => config('msgraph.urlAccessToken'),
+ 'clientId' => config('msgraph.clientId'),
+ 'clientSecret' => config('msgraph.clientSecret'),
+ 'redirectUri' => config('msgraph.redirectUri'),
+ 'urlAuthorize' => config('msgraph.urlAuthorize'),
+ 'urlAccessToken' => config('msgraph.urlAccessToken'),
'urlResourceOwnerDetails' => config('msgraph.urlResourceOwnerDetails'),
- 'scopes' => config('msgraph.scopes'),
+ 'scopes' => config('msgraph.scopes'),
]);
}
}
diff --git a/src/MsGraphAdmin.php b/src/MsGraphAdmin.php
index 8699629..4723213 100644
--- a/src/MsGraphAdmin.php
+++ b/src/MsGraphAdmin.php
@@ -51,6 +51,7 @@ public function files()
/**
* Set the base url that all API requests use.
+ *
* @var string
*/
protected static $baseUrl = 'https://graph.microsoft.com/v1.0/';
@@ -74,7 +75,7 @@ public function setApiVersion($version = '1.0'): static
*/
public function isConnected()
{
- $token = $this->getTokenData();
+ $token = $this->getTokenData();
if ($token === null) {
return false;
@@ -89,15 +90,16 @@ public function isConnected()
/**
* Make a connection or return a token where it's valid.
+ *
* @return mixed
*/
public function connect($redirect = true)
{
$params = [
- 'scope' => 'https://graph.microsoft.com/.default',
- 'client_id' => config('msgraph.clientId'),
+ 'scope' => 'https://graph.microsoft.com/.default',
+ 'client_id' => config('msgraph.clientId'),
'client_secret' => config('msgraph.clientSecret'),
- 'grant_type' => 'client_credentials',
+ 'grant_type' => 'client_credentials',
];
$token = $this->dopost(config('msgraph.tenantUrlAccessToken'), $params);
@@ -115,8 +117,9 @@ public function connect($redirect = true)
/**
* Return authenticated access token or request new token when expired.
- * @param $id integer - id of the user
- * @param $returnNullNoAccessToken null when set to true return null
+ *
+ * @param $id integer - id of the user
+ * @param $returnNullNoAccessToken null when set to true return null
* @return return string access token
*/
public function getAccessToken($returnNullNoAccessToken = false, $redirect = false)
@@ -146,7 +149,7 @@ public function getAccessToken($returnNullNoAccessToken = false, $redirect = fal
}
/**
- * @param $id - integar id of user
+ * @param $id - integar id of user
* @return object
*/
public function getTokenData()
@@ -156,34 +159,36 @@ public function getTokenData()
/**
* Store token.
- * @param $access_token string
- * @param $refresh_token string
- * @param $expires string
- * @param $id integer
+ *
+ * @param $access_token string
+ * @param $refresh_token string
+ * @param $expires string
+ * @param $id integer
* @return object
*/
protected function storeToken($access_token, $refresh_token, $expires)
{
//Create or update a new record for admin token
return MsGraphToken::updateOrCreate(['user_id' => null], [
- 'email' => 'application_token', // Placeholder name
- 'access_token' => $access_token,
- 'expires' => (time() + $expires),
+ 'email' => 'application_token', // Placeholder name
+ 'access_token' => $access_token,
+ 'expires' => (time() + $expires),
'refresh_token' => $refresh_token,
]);
}
/**
* __call catches all requests when no founf method is requested.
- * @param $function - the verb to execute
- * @param $args - array of arguments
+ *
+ * @param $function - the verb to execute
+ * @param $args - array of arguments
* @return json request
*/
public function __call($function, $args)
{
$options = ['get', 'post', 'patch', 'put', 'delete'];
- $path = (isset($args[0])) ? $args[0] : null;
- $data = (isset($args[1])) ? $args[1] : null;
+ $path = (isset($args[0])) ? $args[0] : null;
+ $data = (isset($args[1])) ? $args[1] : null;
if (in_array($function, $options)) {
return self::guzzle($function, $path, $data);
@@ -200,10 +205,11 @@ protected function isJson($string)
/**
* run guzzle to process requested url.
- * @param $type string
- * @param $request string
- * @param $data array
- * @param $id integer
+ *
+ * @param $type string
+ * @param $request string
+ * @param $data array
+ * @param $id integer
* @return json object
*/
protected function guzzle($type, $request, $data = [])
@@ -214,8 +220,8 @@ protected function guzzle($type, $request, $data = [])
$response = $client->$type(self::$baseUrl.$request, [
'headers' => [
'Authorization' => 'Bearer '.$this->getAccessToken(),
- 'content-type' => 'application/json',
- 'Prefer' => config('msgraph.preferTimezone'),
+ 'content-type' => 'application/json',
+ 'Prefer' => config('msgraph.preferTimezone'),
],
'body' => json_encode($data),
]);
@@ -239,7 +245,7 @@ protected function guzzle($type, $request, $data = [])
protected static function dopost($url, $params)
{
try {
- $client = new Client;
+ $client = new Client;
$response = $client->post($url, ['form_params' => $params]);
if ($response == null) {
@@ -256,9 +262,10 @@ protected static function dopost($url, $params)
/**
* return tarray containing total, top and skip params.
- * @param $data array
- * @param $top integer
- * @param $skip integer
+ *
+ * @param $data array
+ * @param $top integer
+ * @param $skip integer
* @return array
*/
public function getPagination($data, $top, $skip)
@@ -273,17 +280,17 @@ public function getPagination($data, $top, $skip)
$parts = parse_url($data['@odata.nextLink']);
parse_str($parts['query'], $query);
- $top = isset($query['$top']) ? $query['$top'] : 0;
+ $top = isset($query['$top']) ? $query['$top'] : 0;
$skip = isset($query['$skip']) ? $query['$skip'] : 0;
} else {
- $top = 0;
+ $top = 0;
$skip = 0;
}
return [
'total' => $total,
- 'top' => $top,
- 'skip' => $skip,
+ 'top' => $top,
+ 'skip' => $skip,
];
}
}
diff --git a/src/MsGraphAdminAuthenticated.php b/src/MsGraphAdminAuthenticated.php
index 008d765..07a049c 100644
--- a/src/MsGraphAdminAuthenticated.php
+++ b/src/MsGraphAdminAuthenticated.php
@@ -11,7 +11,6 @@ class MsGraphAdminAuthenticated
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
- * @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
diff --git a/src/MsGraphAuthenticated.php b/src/MsGraphAuthenticated.php
index e84cec6..75c3b2d 100644
--- a/src/MsGraphAuthenticated.php
+++ b/src/MsGraphAuthenticated.php
@@ -11,7 +11,6 @@ class MsGraphAuthenticated
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
- * @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
diff --git a/src/MsGraphServiceProvider.php b/src/MsGraphServiceProvider.php
index 47e5fda..cbabaa8 100755
--- a/src/MsGraphServiceProvider.php
+++ b/src/MsGraphServiceProvider.php
@@ -4,6 +4,7 @@
use Dcblogdev\MsGraph\Console\Commands\MsGraphAdminKeepAliveCommand;
use Dcblogdev\MsGraph\Console\Commands\MsGraphKeepAliveCommand;
+use Dcblogdev\MsGraph\Facades\MsGraph as MsGraphFacade;
use GuzzleHttp\Client;
use Illuminate\Filesystem\FilesystemAdapter;
use Illuminate\Routing\Router;
@@ -12,7 +13,6 @@
use League\Flysystem\Filesystem;
use Microsoft\Graph\Graph;
use ShitwareLtd\FlysystemMsGraph\Adapter;
-use Dcblogdev\MsGraph\Facades\MsGraph as MsGraphFacade;
class MsGraphServiceProvider extends ServiceProvider
{
@@ -37,7 +37,7 @@ public function registerMiddleware($router)
public function registerCommands()
{
- if (!$this->app->runningInConsole()) {
+ if (! $this->app->runningInConsole()) {
return;
}
@@ -49,7 +49,7 @@ public function registerCommands()
public function configurePublishing()
{
- if (!$this->app->runningInConsole()) {
+ if (! $this->app->runningInConsole()) {
return;
}
@@ -76,25 +76,25 @@ public function registerFilesystem()
if (MsGraphFacade::isConnected()) {
$this->graph = $graph->setAccessToken(MsGraphFacade::getAccessToken());
} else {
- $tenantId = config('msgraph.tenantId');
- $clientId = config('msgraph.clientId');
+ $tenantId = config('msgraph.tenantId');
+ $clientId = config('msgraph.clientId');
$clientSecret = config('msgraph.clientSecret');
- $guzzle = new Client();
- $response = $guzzle->post("https://login.microsoftonline.com/$tenantId/oauth2/v2.0/token",
+ $guzzle = new Client();
+ $response = $guzzle->post("https://login.microsoftonline.com/$tenantId/oauth2/v2.0/token",
[
- 'headers' => [
- 'Host' => 'login.microsoftonline.com',
- 'Content-Type' => 'application/x-www-form-urlencoded'
+ 'headers' => [
+ 'Host' => 'login.microsoftonline.com',
+ 'Content-Type' => 'application/x-www-form-urlencoded',
],
'form_params' => [
- 'client_id' => $clientId,
- 'scope' => 'https://graph.microsoft.com/.default',
+ 'client_id' => $clientId,
+ 'scope' => 'https://graph.microsoft.com/.default',
'client_secret' => $clientSecret,
- 'grant_type' => 'client_credentials'
- ]
+ 'grant_type' => 'client_credentials',
+ ],
]);
- $body = json_decode($response->getBody()->getContents());
+ $body = json_decode($response->getBody()->getContents());
$this->graph = $graph->setAccessToken($body->access_token);
}
diff --git a/src/Resources/Contacts.php b/src/Resources/Contacts.php
index a1ffead..3290a35 100644
--- a/src/Resources/Contacts.php
+++ b/src/Resources/Contacts.php
@@ -9,17 +9,17 @@ class Contacts extends MsGraph
{
public function get($params = [], $perPage = 25)
{
- $perPage = $params['$top'] ?? $perPage;
- $params = $this->getParams($params, $perPage);
+ $perPage = $params['$top'] ?? $perPage;
+ $params = $this->getParams($params, $perPage);
$contacts = MsGraph::get('me/contacts?'.$params);
- $total = $contacts['@odata.count'] ?? $perPage;
- $pages = new Paginator($perPage, 'p');
+ $total = $contacts['@odata.count'] ?? $perPage;
+ $pages = new Paginator($perPage, 'p');
$pages->setTotal($total);
return [
- 'contacts' => $contacts,
- 'total' => $total,
- 'links' => $pages->page_links(),
+ 'contacts' => $contacts,
+ 'total' => $total,
+ 'links' => $pages->page_links(),
'links_array' => $pages->page_links_array(),
];
}
@@ -55,22 +55,22 @@ protected function getParams($params, $perPage)
if ($params == []) {
$params = http_build_query([
'$orderby' => 'displayName',
- '$top' => $perPage,
- '$skip' => $page,
- '$count' => "true"
+ '$top' => $perPage,
+ '$skip' => $page,
+ '$count' => 'true',
]);
} else {
//ensure $top, $skip and $count are part of params
- if (!in_array('$top', $params)) {
+ if (! in_array('$top', $params)) {
$params['$top'] = $perPage;
}
- if (!in_array('$skip', $params)) {
+ if (! in_array('$skip', $params)) {
$params['$skip'] = $page;
}
- if (!in_array('$count', $params)) {
- $params['$count'] = "true";
+ if (! in_array('$count', $params)) {
+ $params['$count'] = 'true';
}
$params = http_build_query($params);
diff --git a/src/Resources/Emails.php b/src/Resources/Emails.php
index 80a1633..03e6a41 100644
--- a/src/Resources/Emails.php
+++ b/src/Resources/Emails.php
@@ -8,14 +8,23 @@
class Emails extends MsGraph
{
private $top;
+
private $skip;
+
private $subject;
+
private $body;
+
private $comment;
+
private $id;
+
private $to;
+
private $cc;
+
private $bcc;
+
private $attachments;
public function id($id)
@@ -90,7 +99,7 @@ public function skip($skip)
public function get($folderId = null, $params = [])
{
- $top = request('top', $this->top);
+ $top = request('top', $this->top);
$skip = request('skip', $this->skip);
if ($top === null) {
@@ -103,8 +112,8 @@ public function get($folderId = null, $params = [])
if ($params == []) {
$params = http_build_query([
- '$top' => $top,
- '$skip' => $skip,
+ '$top' => $top,
+ '$skip' => $skip,
'$count' => 'true',
]);
} else {
@@ -216,12 +225,12 @@ public function delete($id)
protected function prepareEmail()
{
- $subject = $this->subject;
- $body = $this->body;
- $comment = $this->comment;
- $to = $this->to;
- $cc = $this->cc;
- $bcc = $this->bcc;
+ $subject = $this->subject;
+ $body = $this->body;
+ $comment = $this->comment;
+ $to = $this->to;
+ $cc = $this->cc;
+ $bcc = $this->bcc;
$attachments = $this->attachments;
$toArray = [];
@@ -251,9 +260,9 @@ protected function prepareEmail()
$path = pathinfo($file);
$attachmentarray[] = [
- '@odata.type' => '#microsoft.graph.fileAttachment',
- 'name' => $path['basename'],
- 'contentType' => mime_content_type($file),
+ '@odata.type' => '#microsoft.graph.fileAttachment',
+ 'name' => $path['basename'],
+ 'contentType' => mime_content_type($file),
'contentBytes' => base64_encode(file_get_contents($file)),
];
}
@@ -266,7 +275,7 @@ protected function prepareEmail()
if ($body != null) {
$envelope['message']['body'] = [
'contentType' => 'html',
- 'content' => $body,
+ 'content' => $body,
];
}
if ($toArray != null) {
diff --git a/src/Resources/Files.php b/src/Resources/Files.php
index f919589..342c8cc 100644
--- a/src/Resources/Files.php
+++ b/src/Resources/Files.php
@@ -46,8 +46,8 @@ public function createFolder($name, $path, $type = 'me', $behavior = 'rename')
$path = $path === null ? $type.'/drive/root/children' : $type.'/drive/root:'.$this->forceStartingSlash($path).':/children';
return MsGraph::post($path, [
- 'name' => $name,
- 'folder' => new \stdClass(),
+ 'name' => $name,
+ 'folder' => new \stdClass(),
'@microsoft.graph.conflictBehavior' => $behavior,
]);
}
@@ -69,23 +69,23 @@ public function rename($name, $id, $type = 'me')
public function upload($name, $uploadPath, $path = null, $type = 'me', $behavior = 'rename')
{
$uploadSession = $this->createUploadSession($name, $path, $type, $behavior);
- $uploadUrl = $uploadSession['uploadUrl'];
+ $uploadUrl = $uploadSession['uploadUrl'];
- $fragSize = 320 * 1024;
- $file = file_get_contents($uploadPath);
- $fileSize = strlen($file);
- $numFragments = ceil($fileSize / $fragSize);
+ $fragSize = 320 * 1024;
+ $file = file_get_contents($uploadPath);
+ $fileSize = strlen($file);
+ $numFragments = ceil($fileSize / $fragSize);
$bytesRemaining = $fileSize;
- $i = 0;
- $ch = curl_init($uploadUrl);
+ $i = 0;
+ $ch = curl_init($uploadUrl);
while ($i < $numFragments) {
$chunkSize = $numBytes = $fragSize;
- $start = $i * $fragSize;
- $end = $i * $fragSize + $chunkSize - 1;
- $offset = $i * $fragSize;
+ $start = $i * $fragSize;
+ $end = $i * $fragSize + $chunkSize - 1;
+ $offset = $i * $fragSize;
if ($bytesRemaining < $chunkSize) {
$chunkSize = $numBytes = $bytesRemaining;
- $end = $fileSize - 1;
+ $end = $fileSize - 1;
}
if ($stream = fopen($uploadPath, 'r')) {
// get contents using offset
@@ -94,15 +94,15 @@ public function upload($name, $uploadPath, $path = null, $type = 'me', $behavior
}
$content_range = ' bytes '.$start.'-'.$end.'/'.$fileSize;
- $headers = [
+ $headers = [
'Content-Length' => $numBytes,
- 'Content-Range' => $content_range,
+ 'Content-Range' => $content_range,
];
- $client = new Client;
+ $client = new Client;
$response = $client->put($uploadUrl, [
'headers' => $headers,
- 'body' => $data,
+ 'body' => $data,
]);
$bytesRemaining = $bytesRemaining - $chunkSize;
@@ -117,7 +117,7 @@ protected function createUploadSession($name, $path = null, $type = 'me', $behav
return MsGraph::post($path, [
'item' => [
'@microsoft.graph.conflictBehavior' => $behavior,
- 'name' => $name,
+ 'name' => $name,
],
]);
}
diff --git a/src/Resources/Sites.php b/src/Resources/Sites.php
new file mode 100644
index 0000000..04b3a3d
--- /dev/null
+++ b/src/Resources/Sites.php
@@ -0,0 +1,13 @@
+ $name
+ return MsGraph::post('me/todo/lists', [
+ 'displayName' => $name,
]);
}
public function update(string $listId, string $name)
{
return MsGraph::patch("me/todo/lists/$listId", [
- 'displayName' => $name
+ 'displayName' => $name,
]);
}
@@ -36,4 +36,4 @@ public function delete(string $listId)
{
return MsGraph::delete("me/todo/lists/$listId");
}
-}
\ No newline at end of file
+}
diff --git a/src/Resources/Tasks/Tasks.php b/src/Resources/Tasks/Tasks.php
index 9cbb556..247e4c2 100644
--- a/src/Resources/Tasks/Tasks.php
+++ b/src/Resources/Tasks/Tasks.php
@@ -15,16 +15,16 @@ public function get($taskListId, $params = [], $perPage = 25, $instance = 'p')
unset($filteredParams['$top']);
unset($filteredParams['$skip']);
- $tasks = MsGraph::get("me/todo/lists/$taskListId/tasks?".http_build_query($params));
+ $tasks = MsGraph::get("me/todo/lists/$taskListId/tasks?".http_build_query($params));
$filteredTasks = MsGraph::get("me/todo/lists/$taskListId/tasks?".http_build_query($filteredParams));
- $total = count($filteredTasks['value']);
- $pages = new Paginator($perPage, $instance);
+ $total = count($filteredTasks['value']);
+ $pages = new Paginator($perPage, $instance);
$pages->setTotal($total);
return [
- 'tasks' => $tasks,
- 'total' => $total,
- 'links' => $pages->page_links(),
+ 'tasks' => $tasks,
+ 'total' => $total,
+ 'links' => $pages->page_links(),
'links_array' => $pages->page_links_array(),
];
}
@@ -60,16 +60,16 @@ protected function getParams($params, $perPage, $instance)
if ($params == []) {
$params = [
'$orderby' => 'createdDateTime',
- '$top' => $perPage,
- '$skip' => $page,
+ '$top' => $perPage,
+ '$skip' => $page,
];
} else {
//ensure $top, $skip and $count are part of params
- if (!in_array('$top', $params)) {
+ if (! in_array('$top', $params)) {
$params['$top'] = $perPage;
}
- if (!in_array('$skip', $params)) {
+ if (! in_array('$skip', $params)) {
$params['$skip'] = $page;
}
}
diff --git a/tests/MsGraphAdminTest.php b/tests/MsGraphAdminTest.php
index cef25ae..da8510a 100644
--- a/tests/MsGraphAdminTest.php
+++ b/tests/MsGraphAdminTest.php
@@ -1,7 +1,7 @@
null,
+ 'user_id' => null,
'access_token' => 'ghgh4h22',
- 'expires' => strtotime('+1 day'),
+ 'expires' => strtotime('+1 day'),
]);
$this->artisan('msgraphadmin:keep-alive')
@@ -32,9 +32,9 @@
test('is connected returns true when data exists in db', function () {
MsGraphToken::create([
- 'user_id' => null,
+ 'user_id' => null,
'access_token' => 'ghgh4h22',
- 'expires' => strtotime('+1 day'),
+ 'expires' => strtotime('+1 day'),
]);
$connect = MsGraphAdminFacade::isConnected();
diff --git a/tests/MsGraphTest.php b/tests/MsGraphTest.php
index bd73df6..6842f16 100644
--- a/tests/MsGraphTest.php
+++ b/tests/MsGraphTest.php
@@ -28,10 +28,10 @@
test('is connected returns true when a valid token exists', function () {
$userId = 1;
MsGraphToken::create([
- 'user_id' => $userId,
+ 'user_id' => $userId,
'access_token' => 'ghgh4h22',
'refresh_token' => 'rhrh4h22',
- 'expires' => strtotime('+1 day'),
+ 'expires' => strtotime('+1 day'),
]);
$connect = MsGraphFacade::isConnected($userId);
@@ -42,9 +42,9 @@
test('is redirected on disconnection', function () {
$userId = 1;
MsGraphToken::create([
- 'user_id' => $userId,
+ 'user_id' => $userId,
'access_token' => 'ghgh4h22',
- 'expires' => strtotime('+1 day'),
+ 'expires' => strtotime('+1 day'),
]);
$connect = MsGraphFacade::disconnect($redirectPath = '/', $logout = true);
@@ -65,9 +65,8 @@
});
test('returns null when token has expired and redirectWhenNotConnected is false', function () {
- $userId = 1;
+ $userId = 1;
$response = MsGraphFacade::getAccessToken($userId, false);
$this->assertSame(null, $response);
});
-
diff --git a/tests/TestCase.php b/tests/TestCase.php
index 91d314b..d039133 100644
--- a/tests/TestCase.php
+++ b/tests/TestCase.php
@@ -18,10 +18,10 @@ protected function getEnvironmentSetUp($app)
{
$app['config']->set('database.default', 'mysql');
$app['config']->set('database.connections.mysql', [
- 'driver' => 'sqlite',
- 'host' => '127.0.0.1',
+ 'driver' => 'sqlite',
+ 'host' => '127.0.0.1',
'database' => ':memory:',
- 'prefix' => '',
+ 'prefix' => '',
]);
}
@@ -32,4 +32,3 @@ protected function defineDatabaseMigrations()
$this->loadMigrationsFrom(dirname(__DIR__).'/src/database/migrations');
}
}
-