raymond10 / nuxeo-php-client
Nuxeo Automation API 的 PHP 客户端库
Requires
- php: ~7.2 || ~8.1
- ext-json: *
- guzzlehttp/guzzle: ~6.0 <= 6.5.5 || ~7.0 <= 7.4.2
- jms/serializer: ~2.0 <=2.3.0 || ~3.0 <= 3.28.0
- monolog/monolog: ~1.3 <= 1.27.0 || ~2.0, <= 2.5.0
- zbateson/mail-mime-parser: ~1.3 <= 1.3.3 || ~2.2 <= 2.2.1
Requires (Dev)
- dms/phpunit-arraysubset-asserts: ~v0.4.0
- enlightn/security-checker: ~1.10.0
- phpunit/phpunit: ~8.5.26 || ~9.5.20
- symfony/http-foundation: ~4.4.41
- symfony/mime: ~4.4.41
This package is auto-updated.
Last update: 2024-09-04 17:05:30 UTC
README
Nuxeo PHP 客户端
Nuxeo PHP 客户端是 Nuxeo Rest API 的 PHP 客户端库。
该库由 Nuxeo 支持,并与 Nuxeo LTS 2015 和最新 Fast Tracks 兼容。
代码
要求
仍在使用旧版本的 PHP?请查看 v1.5,它提供有限但有效的支持,需要 PHP 5.3+
入门指南
服务器
-
下载 Nuxeo 服务器(zip 版本)
-
解压它
-
Linux/Mac
NUXEO_HOME/bin/nuxeoctl start
-
Windows
NUXEO_HOME\bin\nuxeoctl.bat start
-
在浏览器中,转到
https://:8080/nuxeo
-
按照 Nuxeo 向导点击“下一步”按钮,完成后重新启动
-
检查 Nuxeo 是否正确重新启动
https://:8080/nuxeo
- 用户名:Administrator
- 密码:Administrator
库导入
下载最新的构建版本 Nuxeo PHP Client main。
Composer
"require": {
"nuxeo/nuxeo-php-client": "~2.0"
}
用法
创建客户端
以下文档和示例适用于 1.5 及更高版本。对客户端旧版本的 Automation API 的调用将需要调整。
对于给定的 url
$url = 'https://:8080/nuxeo';
和给定的凭据
use Nuxeo\Client\NuxeoClient; $client = new NuxeoClient($url, 'Administrator', 'Administrator');
选项
可以在客户端或 API 对象上设置选项。这确保了选项的继承和隔离,这些选项应用于对象。因此,客户端将其选项提供给 API 对象。
// To define global schemas, global enrichers and global headers in general $client = $client->schemas("dublincore", "common") ->enrichers('document', ['acls'])
// For defining all schemas $client = $client->schemas("*");
// For changing authentication method use Nuxeo\Client\Auth\PortalSSOAuthentication; use Nuxeo\Client\Auth\TokenAuthentication; // PortalSSOAuthentication with nuxeo-platform-login-portal-sso $client = $client->setAuthenticationMethod(new PortalSSOAuthentication($secret, $username)); // TokenAuthentication $client = $client->setAuthenticationMethod(new TokenAuthentication($token)); // OAuth2Authentication // The PHP client doesn't implement OAuth2 authorization flow as // it depends completely on the architecture choices of your app. // To help understanding and implement, please find a sample SF4 app under intergation/oauth2. // Once the authorization flow is ready and you have an access token, // you can use the OAuth2Authentication in the PHP client: $client = $client->setAuthenticationMethod(new OAuth2Authentication($accessToken));
APIs
Automation API
要使用 Automation API,Nuxeo\Client\NuxeoClient#automation()
是所有调用的入口点
// Fetch the root document $result = $client->automation('Repository.GetDocument')->param("value", "/")->execute(); // Type auto-detected and cast as Nuxeo\Client\Objects\Document
// Execute query $operation = $client->automation('Repository.Query')->param('query', 'SELECT * FROM Document'); $result = $operation->execute(); // Type auto-detected and cast as Nuxeo\Client\Objects\Documents
use Nuxeo\Client\Objects\Blob\Blob; use Nuxeo\Client\Objects\Blob\Blobs; // To upload|download blob(s) $fileBlob = Blob::fromFile('/local/file.txt', 'text/plain'); $blob = $client->automation('Blob.AttachOnDocument')->param('document', '/folder/file')->input($fileBlob)->execute(Blob::class); $inputBlobs = new Blobs(); $inputBlobs->add('/local/file1.txt', 'text/plain'); $inputBlobs->add('/local/file2.txt', 'text/plain'); $blobs = $client->automation('Blob.AttachOnDocument')->param('xpath', 'files:files')->param('document', '/folder/file')->input($inputBlobs)->execute(Blobs::class); $resultBlob = $client->automation('Document.GetBlob')->input('folder/file')->execute(Blob::class);
use Nuxeo\Client\Objects\Document; class MyBusinessClass extends Nuxeo\Client\Objects\Document { ... } // Unserialize document in a custom class $operation = $client->automation('Document.Fetch')->param('value', '0fa9d2a0-e69f-452d-87ff-0c5bd3b30d7d'); $result = $operation->execute(MyBusinessClass::class);
use Nuxeo\Client\Objects\Document; use Nuxeo\Client\Objects\Operation\DocRef; // Enforce type of a property $doc = $client->automation('Document.Fetch')->param('value', '0fa9d2a0-e69f-452d-87ff-0c5bd3b30d7d')->execute(Document::class); $property = $doc->getProperty('custom:related', DocRef::class);
Repository API
// Fetch the root document $document = $client->repository()->fetchDocumentRoot();
// Fetch document by path $document = $client->repository()->fetchDocumentByPath('/folders_2');
// Create a document $document = Objects\Document::create() ->setProperty('dc:title', 'Some title');
// Update a document $repository = $client->repository(); $document = $repository->fetchDocumentByPath('/note_0'); document->setPropertyValue("dc:title", "note updated"); $repository->updateDocumentByPath('/note_0', $document);
// Delete a document $client->repository()->deleteDocumentByPath('/note_2');
用户/组
// Get current user used to connect to Nuxeo Server /** @var \Nuxeo\Client\Objects\User\User $user */ $user = $client->userManager()->fetchCurrentUser();
// Create User $userManager->createUser((new User()) ->setUsername('my_login') ->setCompany('Nuxeo') ->setEmail('user@company.com') ->setFirstName('Thomas A.') ->setLastName('Anderson') ->setPassword('passw0rd'));
//Update user $userManager->updateUser($user);
//Attach user to group $userManager->attachGroupToUser('username', 'group_name'); $userManager->attachUserToGroup('group_name', 'username');
工作流
// Fetch current user workflow tasks /** @var \Nuxeo\Client\Objects\Workflow\Tasks $tasks */ $tasks = $client->workflows()->fetchTasks();
错误/异常
主要的异常类型是 Nuxeo\Client\Spi\NuxeoClientException
,它包含
-
HTTP 错误状态码(内部错误为 666)
-
信息消息
Docker
我们提供了一个 docker-compose.yml 用于快速测试
只需安装 docker-compose 并运行 docker-compose up
,你将在 https://:9081/ 上运行 nuxeo,并在 https://:9080/ 上运行 nginx
例如,您可以通过 https://:9080/samples/B1.php 访问示例。
贡献/报告问题
我们很高兴欢迎新的开发者,即使是简单的使用反馈也很好
- 在 http://answers.nuxeo.com/ 上提问
- 在此 GitHub 仓库中报告问题(参见右侧的 问题链接)
许可
关于 Nuxeo
《Nuxeo Platform》(Nuxeo 平台)是一个开源的、可定制和可扩展的内容管理平台,用于构建商业应用程序。它为开发文档管理、数字资产管理、案件管理应用和知识管理提供了基础。您可以通过使用现成的插件或通过使用其扩展点系统扩展平台来轻松添加功能。
Nuxeo 平台由 Nuxeo 开发并支持,并得到了社区的贡献。
Nuxeo 显著提高了基于内容的应用程序的构建、管理和部署方式,使客户更加敏捷、创新和成功。Nuxeo 为构建传统和前沿的内容应用提供了一个下一代企业级平台。结合强大的应用开发环境、基于 SaaS 的工具和模块化架构,Nuxeo 平台和产品为包括 Verizon、Electronic Arts、Sharp、FICO、美国海军和波音在内的知名品牌提供了明确的企业价值。Nuxeo 的总部位于纽约和巴黎。更多信息请访问 www.nuxeo.com。