chancegarcia/php-box-sdk 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

chancegarcia/php-box-sdk

Composer 安装命令:

composer require chancegarcia/php-box-sdk

包简介

PHP SDK and API client for the Box API v2024.0, supporting OAuth2 and JWT/S2S authentication, file and folder operations, uploads, webhook signature verification, typed models, and PSR-3 logging.

README 文档

README

CI Latest Stable Version PHP Version Require License Total Downloads

A modern PHP SDK for interacting with the Box.com API.

Status: v1.0.0 released.

This library is designed as a boundary layer for Box API access, suitable for standalone use or integration into frameworks like Symfony.

Requirements

  • PHP 8.4 or higher
  • ext-fileinfo

Installation

composer require chancegarcia/php-box-sdk

Quickstart

OAuth2 Workflow

The recommended setup uses BoxClientFactory with an EnvConfigProvider, which reads credentials from environment variables (BOX_OAUTH_CLIENT_ID, BOX_OAUTH_CLIENT_SECRET, etc.):

use Box\Service\BoxClientFactory;
use Box\Service\EnvConfigProvider;

$factory = new BoxClientFactory(new EnvConfigProvider());
$client  = $factory->createClient();

Generate the authorization URL and redirect the user:

$authUrl = $client->buildAuthorizationUrl();
// Redirect user to $authUrl

After the user authorizes and is redirected back with a code, exchange it for a token:

$client->setAuthorizationCode($_GET['code']);
$token = $client->exchangeAuthorizationCodeForToken();

JWT / Server-to-Server

For server-to-server integrations (no browser redirect needed), set BOX_AUTH_MODE=jwt and the BOX_JWT_* environment variables, then:

use Box\Service\BoxClientFactory;
use Box\Service\EnvConfigProvider;

$configProvider = new EnvConfigProvider();
$factory        = new BoxClientFactory($configProvider);
$client         = $factory->createClientForCurrentMode(); // JWT client when BOX_AUTH_MODE=jwt

See the Programmatic Usage Guide for enterprise and app-user token exchange examples.

File and Folder Operations

use Box\Http\FileStream;

$client->setToken($token);

// Upload a local file
$result = $client->uploadFileToBox('/path/to/file.txt', '12345');

// Upload via stream (no local file needed)
$stream = FileStream::fromString('Hello World', 'hello.txt');
$result = $client->uploadFileToBox($stream, '0'); // '0' is the root folder ID

// Get a folder
$folder = $client->getFolder('12345');

Advanced Documentation

For in-depth architectural guidance, library integration patterns, and advanced usage:

Development and Quality Checks

composer review    # Run all checks (recommended before pushing)
composer test      # PHPUnit
composer analyse   # PHPStan
composer cs:check  # PHP_CodeSniffer
composer cs:fix    # Fix code style automatically
composer lint      # PHP syntax check

See also:

License

Apache 2.0 License. See LICENSE for details.

This project was previously distributed under the MIT License. As of v1.0.0 it is relicensed under Apache 2.0.

统计信息

  • 总下载量: 9
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 8
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 8
  • Watchers: 3
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2026-05-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固