gwsn/sharepoint-sdk
Composer 安装命令:
composer require gwsn/sharepoint-sdk
包简介
Connect to sharepoint drive with PHP
关键字:
README 文档
README
Sharepoint SDK to use Sharepoint as filestorage.
For the Flysystem adapter (Symfony and Laravel) see the flysystem package: gwsn/flysystem-sharepoint-adapter
Installation
You can install the package via composer:
composer require gwsn/sharepoint-sdk
First configuration to start usage
You need to request a new clientId and clientSecret for a new application on Azure.
-
Go to
Azure portalhttps://portal.azure.com -
Go to
Azure Active Directory -
Go to
App registrations -
Click on
new Registrationand follow the wizard.
(give it a name like mine is 'gwsn-sharepoint-connector' and make a decision on the supported accounts, single tenant should be enough but this depends on your organisation) -
When created the application is created write down the following details
-
'Application (client) id', this will be your
$clientId -
'Directory (tenant) id', this will be your
$tenantId -
Then we go in the menu to the
API permissionsto set the permissions that are required -
The click on
Add a permissionand add the following permissions:
Microsoft Graph:- Files.ReadWrite.All
- Sites.ReadWrite.All
- User.Read
-
Click on the
Grant admin consent for ...Company... -
Go in the menu to
Certificates & secrets -
Click on
new client secret -
Give it a description and expiry date and the value will be your
$clientSecret -
The last parameter will be the sharepoint 'slug', this is part of the url of the sharepoint site what you want to use and creation of sharepoint site is out of scope of this readme.
When you sharepoint url is likehttps://{tenant}.sharepoint.com/sites/{site-slug}/Shared%20Documents/Forms/AllItems.aspx
You need to set the$sharepointSiteas{site-slug}Example:
- Sharepoint site url:
https://GWSN.sharepoint.com/sites/gwsn-documents-store/Shared%20Documents/Forms/AllItems.aspx - Sharepoint site variable:
$sharepointSite = 'gwsn-documents-store'
- Sharepoint site url:
Basic usage with the flysystem adapter (preferred way!)
use GWSN\FlysystemSharepoint\FlysystemSharepointAdapter; use GWSN\FlysystemSharepoint\SharepointConnector; use League\Flysystem\Filesystem; $tenantId = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'; $clientId = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'; $clientSecret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; $sharepointSite = 'your-path-to-your-site'; $connector = new SharepointConnector($tenantId, $clientId, $clientSecret, $sharepointSite); $prefix = '/test'; // optional $adapter = new FlysystemSharepointAdapter($connector, $prefix); $flysystem = new Filesystem($adapter);
Basic needs to be able to use the folder|drive|file service
use GWSN\Microsoft\Authentication\AuthenticationService; use GWSN\Microsoft\Drive\DriveService; use GWSN\Microsoft\Drive\FileService; use GWSN\Microsoft\Drive\FolderService; use GWSN\Microsoft\Sharepoint\SharepointService; // Not needed if you use a framework with dependency injection ! require dirname(dirname(__DIR__)) . '/vendor/autoload.php'; $tenantId = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'; $clientId = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'; $clientSecret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; $sharepointSite = 'your-path-to-your-site'; // Login into MS oauth and fetch new access token // In real application please save the access token and use it until it expires $authService = new AuthenticationService(); $accessToken = $authService->getAccessToken($tenantId, $clientId, $clientSecret);
Usage for managing for Sharepoint drives
include the basic usage and add the following code
// Initialize the drive $spDrive = new DriveService($accessToken); $driveId = $spDrive->requestDriveId($siteId); $spDrive->setDriveId($driveId); // Check if Resource exists try { $result = $spDrive->checkResourceExists('/test'); var_dump($result); $result = $spDrive->checkResourceExists('/testDoc.docx'); var_dump($result); } catch (\Exception $exception) { var_dump($exception->getMessage()); } // move file /test.txt to folder /test and rename it to testje.txt $result = $spFileService->moveFile('/test.txt', '/test', 'testje.txt'); // check if it still exists $result = $spDrive->checkResourceExists('/test.txt'); var_dump($result); // check if new file exists $result = $spDrive->checkResourceExists('/test/testje.txt'); var_dump($result);
Usage for managing Sharepoint folders
include the basic usage and add the following code
try { // Initialize the drive $spDrive = new DriveService($accessToken); $driveId = $spDrive->requestDriveId($siteId); $spDrive->setDriveId($driveId); // Create the folderService $spFolderService = new FolderService($accessToken, $driveId); // Get files from sharepoint folder $listRootDirResult = $spFolderService->requestFolderItems('/'); // Check if Folder exists $spFolderService->checkFolderExists('/test'); // Get files from sharepoint sub folder $listRootDirResult = $spFolderService->requestFolderItems('/test'); // Get Folder from sharepoint $spFolderService->createFolderRecursive('/dummy/test'); // Delete Folder from sharepoint we just created $spFolderService->deleteFolder('/dummy/test'); $spFolderService->deleteFolder('/dummy'); // Check if Folder exists while its a file try { $result = $spFolderService->checkFolderExists('/testDoc.docx'); var_dump($result); } catch (\Exception $exception) { var_dump($exception->getMessage()); } } catch (\Exception $exception) { var_dump($exception->getMessage()); }
Usage for files in Sharepoint drives
include the basic usage and add the following code
// FileService $spFileService = new FileService($accessToken, $driveId); // write file to directory $result = $spFileService->writeFile('/test.txt', 'testContent'); var_dump(isset($result['id'])); // read file from directory $content = $spFileService->readFile('/test.txt'); var_dump(($content === 'testContent')); // write file to directory $result = $spFileService->writeFile('/test/docje.txt', 'testContent'); var_dump(isset($result['id'])); // read file from directory $content = $spFileService->readFile('/test/docje.txt'); var_dump(($content === 'testContent')); // move file $result = $spFileService->moveFile('/test.txt', '/test', 'testje.txt'); $result = $spDrive->checkResourceExists('/test.txt'); var_dump($result); $result = $spDrive->checkResourceExists('/test/testje.txt'); var_dump($result); // copy file $result = $spFileService->copyFile('/test/testje.txt', '/', 'toBeDeleted.txt'); var_dump($result); // copy dir $result = $spFileService->copyFile('/test', '/test2'); var_dump($result); // delete file from directory $content = $spFileService->deleteFile('/test/testje.txt'); var_dump($content); $content = $spFileService->deleteFile('/test/docje.txt'); var_dump($content); $content = $spFileService->deleteFile('/toBeDeleted.txt'); var_dump($content); $content = $spFileService->deleteFile('/test.txt'); var_dump($content);
Testing
$ composer run-script test
Security
If you discover any security related issues, please email info@gwsn.nl instead of using the issue tracker.
License
The MIT License (MIT). Please see License File for more information.
gwsn/sharepoint-sdk 适用场景与选型建议
gwsn/sharepoint-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 104.21k 次下载、GitHub Stars 达 7, 最近一次更新时间为 2022 年 02 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「sharepoint」 「Flysystem」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 gwsn/sharepoint-sdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 gwsn/sharepoint-sdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 gwsn/sharepoint-sdk 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Backblaze B2 Cloud Storage for Laravel 5. Original by Paul Olthof (@hpolthof) continued by @bringyourownideas
Virtual Filesystem Storage Adapter for Laravel
Flysystem Adapter for the Sharepoint 2013 REST API
Simple library for file uploading to Microsoft Sharepoint site
SharePoint OAuth App Client
Adds Silverstripe Flysystem support for using the Azure Blob adapter
统计信息
- 总下载量: 104.21k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 23
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-02-08