nuxeo/nuxeo-php-client

Nuxeo Automation API的PHP客户端库

3.0.0 2022-04-29 12:34 UTC

README

Packagist Version Packagist Downloads GitHub

Dependencies checks Unit tests Functional tests Integration tests

Quality Gate Status Security Rating Maintainability Rating Reliability Rating Coverage Vulnerabilities

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

下载最新的稳定版本GitHub release (latest SemVer)

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));

API

自动化API

要使用自动化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);
仓库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访问示例。

贡献/报告问题

我们很高兴欢迎新的开发者,即使是简单的使用反馈也非常受欢迎

许可

Apache License,版本2.0

关于Nuxeo

《Nuxeo 平台》是一个开源的、可定制的和可扩展的内容管理平台,用于构建商业应用程序。它为开发文档管理、数字资产管理、案例管理应用和知识管理提供了基础。您可以通过使用现成的插件或通过使用其扩展点系统扩展平台来轻松添加功能。

Nuxeo 平台由 Nuxeo 开发并支持,得到了社区的贡献。

Nuxeo 显著提高了基于内容的应用程序的开发、管理和部署方式,使客户更加敏捷、创新和成功。Nuxeo 为构建传统和前沿的内容应用提供了下一代的企业级平台。结合强大的应用程序开发环境、基于 SaaS 的工具和模块化架构,Nuxeo 平台和产品为包括 Verizon、Electronic Arts、Sharp、FICO、美国海军和波音在内的众多知名品牌提供了明显的商业价值。Nuxeo 总部位于纽约和巴黎。更多信息请访问 www.nuxeo.com