j-rodrigueza-2018/php-hexadrive
最新稳定版本:v1.0.3
Composer 安装命令:
composer require j-rodrigueza-2018/php-hexadrive
包简介
PHP library for managing files and folders in Google Drive using Hexagonal Architecture.
README 文档
README
PHP-HexaDrive is a modern PHP library for managing files and folders in Google Drive, built with a clean and decoupled Hexagonal Architecture.
✨ Features
- 📁 Upload, download, list, rename and delete files
- 📂 Create, list, rename and delete folders
- 🔌 Hexagonal Architecture: decoupled, testable and clean
- ⚙️ PSR-4 autoloading and interface-based adapters
- 🌐 Ready to extend to other providers (e.g. AWS S3, Dropbox, etc.)
- ✅ Comes with integration tests using real Google Drive accounts
🛠 Installation
composer require j-rodrigueza-2018/php-hexadrive
⚙️ Configuration
- Go to Google Cloud Console, enable the Google Drive API and create a Service Account.
- Download the
credentials.jsonfile. - Share your target Google Drive folder with the service account email.
- Add a custom key in the credentials file for the folder ID:
{
"type": "service_account",
"project_id": "...",
"...": "...",
"folder_id": "YOUR_FOLDER_ID"
}
- Save the file as
google-credentials.jsonin your project root
(or pass a custom path to the factory).
🚀 Basic Usage
Upload and Download a File
use JRA\HexaDrive\Infrastructure\Factories\GoogleDrive\GoogleDriveCloudServiceFactory; use JRA\HexaDrive\Infrastructure\Adapters\GoogleDrive\GoogleDriveFileAdapter; // Initialize service $service = (new GoogleDriveCloudServiceFactory('/path/to/google-credentials.json'))->create(); $file_manager = new GoogleDriveFileAdapter($service); // Upload $file_id = $file_manager->uploadFile('example.txt', 'Hello world!'); // Download $content = $file_manager->downloadFile($file_id); // Delete $file_manager->deleteFile($file_id);
Folder Management
use JRA\HexaDrive\Infrastructure\Adapters\GoogleDrive\GoogleDriveFolderAdapter; $service = (new GoogleDriveCloudServiceFactory('/path/to/google-credentials.json'))->create(); $folder_manager = new GoogleDriveFolderAdapter($service); // Create $new_folder_id = $folder_manager->createFolder('MyFolder'); // Rename $folder_manager->renameFolder($new_folder_id, 'RenamedFolder'); // Delete $folder_manager->deleteFolder($new_folder_id);
📄 License
This project is licensed under the MIT License.
统计信息
- 总下载量: 7
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-04-15