2017 © Pedro Peláez
 

library nuxeo-php-client

PHP Client Library for the Nuxeo Automation API

image

nuxeo/nuxeo-php-client

PHP Client Library for the Nuxeo Automation API

  • Thursday, June 21, 2018
  • by pgmillon
  • Repository
  • 59 Watchers
  • 8 Stars
  • 107 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 12 Forks
  • 0 Open issues
  • 15 Versions
  • 95 % Grown

The README.md

Packagist Version Packagist Downloads GitHub, (*1)

Dependencies checks Unit tests Functional tests Integration tests, (*2)

Quality Gate Status Security Rating Maintainability Rating Reliability Rating Coverage Vulnerabilities, (*3)

Nuxeo PHP Client

The Nuxeo PHP Client is a PHP client library for Nuxeo Rest API., (*4)

This is supported by Nuxeo and compatible with Nuxeo LTS 2015 and latest Fast Tracks., (*5)

Code

Requirements

Stuck with an old PHP version ? Have a look at v1.5, it offers limited but effective support and requires PHP 5.3+, (*6)

Getting Started

Server

  • Download a Nuxeo server (the zip version), (*7)

  • Unzip it, (*8)

  • Linux/Mac:, (*9)

    • NUXEO_HOME/bin/nuxeoctl start
  • Windows:, (*10)

    • NUXEO_HOME\bin\nuxeoctl.bat start
  • From your browser, go to http://localhost:8080/nuxeo, (*11)

  • Follow Nuxeo Wizard by clicking 'Next' buttons, re-start once completed, (*12)

  • Check Nuxeo correctly re-started http://localhost:8080/nuxeo, (*13)

    • username: Administrator
    • password: Administrator

Library import

Download the latest build Nuxeo PHP Client main., (*14)

Download the latest stable GitHub release (latest SemVer)., (*15)

Composer:, (*16)

  "require": {
    "nuxeo/nuxeo-php-client": "~2.0"
  }

Usage

Creating a Client

The following documentation and samples applies for the 1.5 and newer versions. Calls to the Automation API for previous versions of the client will require adjustments., (*17)

For a given url:, (*18)

$url = 'http://localhost:8080/nuxeo';

And given credentials:, (*19)

use Nuxeo\Client\NuxeoClient;

$client = new NuxeoClient($url, 'Administrator', 'Administrator');
Options

Options can be set on client or API objects. This ensure inheritance and isolation of options on the object whose options are applied. As it, the client gives its options to API objects., (*20)

// 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

To use the Automation API, Nuxeo\Client\NuxeoClient#automation() is the entry point for all calls:, (*21)

// 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');
Users/Groups
// 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');
Workflows
// Fetch current user workflow tasks
/** @var \Nuxeo\Client\Objects\Workflow\Tasks $tasks */
$tasks = $client->workflows()->fetchTasks();

Errors/Exceptions

The main exception type is Nuxeo\Client\Spi\NuxeoClientException and contains:, (*22)

  • The HTTP error status code (666 for internal errors), (*23)

  • An info message, (*24)

Docker

We provide a docker-compose.yml for quick testing, (*25)

Just install docker-compose and run docker-compose up, you'll have a nuxeo running on http://localhost:9081/ and nginx on http://localhost:9080/, (*26)

You can access the samples with http://localhost:9080/samples/B1.php for example., (*27)

Contributing / Reporting issues

We are glad to welcome new developers, and even simple usage feedback is great, (*28)

  • Ask your questions on http://answers.nuxeo.com/
  • Report issues on this GitHub repository (see issues link on the right)

License

Apache License, Version 2.0, (*29)

About Nuxeo

The Nuxeo Platform is an open source customizable and extensible content management platform for building business applications. It provides the foundation for developing document management, digital asset management, case management application and knowledge management. You can easily add features using ready-to-use addons or by extending the platform using its extension point system., (*30)

The Nuxeo Platform is developed and supported by Nuxeo, with contributions from the community., (*31)

Nuxeo dramatically improves how content-based applications are built, managed and deployed, making customers more agile, innovative and successful. Nuxeo provides a next generation, enterprise ready platform for building traditional and cutting-edge content oriented applications. Combining a powerful application development environment with SaaS-based tools and a modular architecture, the Nuxeo Platform and Products provide clear business value to some of the most recognizable brands including Verizon, Electronic Arts, Sharp, FICO, the U.S. Navy, and Boeing. Nuxeo is headquartered in New York and Paris. More information is available at www.nuxeo.com., (*32)

The Versions

21/06 2018

dev-feature-PHPCLIENT-17-drupal8

dev-feature-PHPCLIENT-17-drupal8 http://www.nuxeo.com

PHP Client Library for the Nuxeo Automation API

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Pierre-Gildas MILLON

client automation nuxeo

11/06 2018

dev-master

9999999-dev http://www.nuxeo.com

PHP Client Library for the Nuxeo Automation API

  Sources   Download

Apache-2.0 AL2

The Requires

 

The Development Requires

by Pierre-Gildas MILLON

client automation nuxeo

31/05 2018

1.5.x-dev

1.5.9999999.9999999-dev http://www.nuxeo.com

PHP Client Library for the Nuxeo Automation API

  Sources   Download

AL2

The Requires

 

The Development Requires

by Pierre-Gildas MILLON

automation nuxeo

30/05 2018

dev-feature-PHPCLIENT-11-workflow-api

dev-feature-PHPCLIENT-11-workflow-api http://www.nuxeo.com

PHP Client Library for the Nuxeo Automation API

  Sources   Download

Apache-2.0 AL2

The Requires

 

The Development Requires

by Pierre-Gildas MILLON

client automation nuxeo

30/05 2018

2.0.0-alpha1

2.0.0.0-alpha1 http://www.nuxeo.com

PHP Client Library for the Nuxeo Automation API

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Pierre-Gildas MILLON

client automation nuxeo

12/04 2018

dev-feature-PHPCLIENT-xx-guzzle-upgrade

dev-feature-PHPCLIENT-xx-guzzle-upgrade http://www.nuxeo.com

PHP Client Library for the Nuxeo Automation API

  Sources   Download

AL2

The Requires

 

The Development Requires

by Pierre-Gildas MILLON

client automation nuxeo

25/11 2017

dev-feature-PHPCLIENT-13-upgrade-dependencies

dev-feature-PHPCLIENT-13-upgrade-dependencies http://www.nuxeo.com

PHP Client Library for the Nuxeo Automation API

  Sources   Download

AL2

The Requires

 

The Development Requires

by Pierre-Gildas MILLON

client automation nuxeo

16/02 2017
07/01 2017
07/12 2016

1.5.0-rc2

1.5.0.0-RC2 http://www.nuxeo.com

PHP Client Library for the Nuxeo Automation API

  Sources   Download

AL2

The Requires

 

The Development Requires

by Pierre-Gildas MILLON

automation nuxeo

07/12 2016

1.1.x-dev

1.1.9999999.9999999-dev http://www.nuxeo.com

PHP libraries and sample clients using Nuxeo automation

  Sources   Download

LGPL

The Requires

 

The Development Requires

by Pierre-Gildas MILLON

nuxeo

07/12 2016

1.1.1

1.1.1.0 http://www.nuxeo.com

PHP libraries and sample clients using Nuxeo automation

  Sources   Download

LGPL

The Requires

 

The Development Requires

by Pierre-Gildas MILLON

nuxeo

18/11 2016

1.5.0-rc1

1.5.0.0-RC1 http://www.nuxeo.com

PHP Client Library for the Nuxeo Automation API

  Sources   Download

AL2

The Requires

 

The Development Requires

by Pierre-Gildas MILLON

automation nuxeo

14/04 2016

1.1.0

1.1.0.0 http://www.nuxeo.com

PHP libraries and sample clients using Nuxeo automation

  Sources   Download

LGPL

The Requires

 

The Development Requires

by Pierre-Gildas MILLON

nuxeo

15/10 2015

1.0.0

1.0.0.0 http://www.nuxeo.com

PHP libraries and sample clients using Nuxeo automation

  Sources   Download

LGPL

The Requires

 

The Development Requires

by Pierre-Gildas MILLON

nuxeo