{{Obsolete}}
The PHP SDK is now being maintained as a separate project at Google Code:
http://code.google.com/p/alfresco-php-sdk/
This is the API documentation for the Alfresco PHP library. Please note that this API is currently in development.
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', 'http://alfresco.domain.com/alfresco/api');
When you have finished with the session, it can be closed with a call to 'close'.
$session->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.
$session->clear();
Both close and clear will cause any unsaved modifications to be lost.
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'.
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 {http://www.alfresco.org/model/content/1.0}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['{http://www.alfresco.org/model/content/1.0}title'] = 'updated title';
$properties['{http://www.alfresco.org/model/content/1.0}description'] = 'updated description';
$contentNode->properties = $properties;
Aspects can be applied to a node using the 'applyAspect' method.
// Apply the versionable aspect
$contentNode.applyAspect('{http://www.alfresco.org/model/content/1.0}versionable');
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.
A node can be created as a child of another node by calling the 'addNode' method.
// Create a new content node
$contentNode = $folderNode.addChild('{http://www.alfresco.org/model/content/1.0}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');
Note:
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.
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)
{
print($parent);
}
The 'primaryParent' attribute contains the primary parent node object.
// Get the primary parent node
$primaryParentNode = $node->primaryParent;
Note:
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)
{
print($childNode);
}
Note:
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.
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
$session->save();
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.
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)
{
echo($node->cm_name.'
');
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ask for and offer help to other Alfresco Content Services Users and members of the Alfresco team.
Related links:
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.