Alfresco PHP Library API

Showing results for 
Search instead for 
Did you mean: 

Alfresco PHP Library API

0 0 3,724


The PHP SDK is now being maintained as a separate project at Google Code:


This is the API documentation for the Alfresco PHP library.  Please note that this API is currently in development.

Creating A Session

A session object can be created by calling the static method create.

   $session = Session::create('admin', 'admin');

A valid user name and password are required and will be used to authenticate against the repository.  If authentication fails an exception is thrown and the session is not created.

An optional repository location parameter can be passed to specifically identify the web service endpoint for the traget repository.  If no repository is specified then the value is taken from the PHP library configuration file.

   $session = Session::create('admin', 'admin', '');

When you have finished with the session, it can be closed with a call to 'close'.


If you want to re-use a session, but want to minimise the memory consuption by clearing the node cache when a page is complete, then use the clear method.


Both close and clear will cause any unsaved modifications to be lost.

Working with Repository Stores and Root Nodes

A list of currently available is available from the 'stores' property on the session object.

   // Get the list of stores in the repository
   $allStores = $session->stores;

This list will contain a list of store objects.  The root node of each store can be accessed by using the 'rootNode' property.

   // Get the root node of the spaces store
   $spacesStore = new Store($session, 'SpacesStore');
   $rootNode = $spacesStore->rootNode;

Note that in this example we created the store object directly as we knew the store identifier. When no store protocol is specified in the construction of a store object it is defaulted to 'workspace'.

Node Properties

Properties of a node appear as attributes of the node object and can be accessed using the PHP short name form of a standard repository qualified name.

A PHP short name is made up of two parts, the prefix followed by the name.  These parts are delimited by an underscore charater.  For example cm_content is the short name form of the full QName {}content.

In cases where the name part of the QName contains a - character they should be replaced by underscore.

   // Print the title of the document using the short name
   print('The title of the document is '.$contentNode.cm_title);

   // Print the desription of the document using the fully qualified name
   print('The description of the document is '.$contentNode.cm_description);

Setting property values can be set by setting the values of the node objects attributes.

   // Set the title of the document
   $contentNode.cm_title = 'This is the title of the document';

   // Set the description of the document
   $contentNode.cm_description = 'This is the description of the document;

The 'properties' attribute of a node can be used to access the entire map of properties.

   // Display all the properties of a perticular node
   foreach ($contentNode->properties as $name=>$value)
      print($name.' = '.$value.'

This attribute can also be set, but it is worth noteing that the entire map will be replaced with the newly set value.  With this in mind see the suggested usage pattern below:

   // Update the properties map
   $properties = $contentNode->properties;
   $properties['{}title'] = 'updated title';
   $properties['{}description'] = 'updated description';
   $contentNode->properties = $properties;

Applying An Aspect To A Node

Aspects can be applied to a node using the 'applyAspect' method.

   // Apply the versionable aspect

Once applied propeties and associations of the aspect can be modified on the node is the usual way.

A map of property values can also be passed to the apply aspect method where relevant.

Creating A New Node

A node can be created as a child of another node by calling the 'addNode' method.

   // Create a new content node
   $contentNode = $folderNode.addChild('{}content', 'My Document.doc');

The type of the node must be specified and it assumed that it is a sub-type of the standard content or folder types.  As such the child association created will be of type 'contains' and the name of the child association will match the created node's name.

If you do not want this default behaviour then it is possible to explictly declare the association type and name that you want created.

   // Create a new node associated to the parent with a specified node type and assoc
   $newNode = $parentNode.addChid('{myNamespace}myCustomType', 'My New Node', '{myNamespace}myAssocType', '{myNamespace}assocName');

The file folder service is not yet available in the web service API so much of the integrity unique nameing integrity will need to be enfoced in the client or ignored.

Navigating The Node Hierarchy

The 'parents' attribute of a node object contains the parents of that node.

   // Print out the node references of a nodes parents
   foreach ($node->parents as $parent)

The 'primaryParent' attribute contains the primary parent node object.

   // Get the primary parent node
   $primaryParentNode = $node->primaryParent;

I'm not sure if we can currently identify the primary parent of a node using the current Web Service API

The 'children' attribute of a node contains the child nodes.

   // Print out the node references of a nodes children
   foreach ($node->children as $childNode)

It may be desirable to be able to get children based on their child assoc type or name.  This is not currently possible with the current web service API.

Reading And Writing Content Properties

Dealing With Associations

Copying, Moving and Deleting Nodes

Saving Modifications

All modifications to nodes are local untill the 'save' method is called.  At this point the modifications made are gathered up and sent as a single update call via the web service API.

Any failure during this call will prevent all changes from being commited.

   // Change a property value
   $node->cm_title = 'title';

   // Save the currently outstanding changes to the repository

If save is not called, and a session is closed or cleared then any modifications will not be persisted to the respository and therefore lost.

Searching For Nodes

Use the search method on the session object to execute a query against the repository.

   // Search for all content with the phrase 'Alfresco' in them
   $nodes = $session->query($store, 'TEXT:'Alfresco'');

   // Output the name of each node returned by the search
   foreach ($nodes as $node)