public function objectPropertyDataProvider()
 {
     $baseTypeId = BaseTypeId::cast(BaseTypeId::CMIS_ITEM);
     $propertyDefinition = $this->getMockBuilder('\\Dkd\\PhpCmis\\Definitions\\PropertyDefinitionInterface')->setMethods(array('getId'))->getMockForAbstractClass();
     $propertyDefinition->expects($this->any())->method('getId')->willReturn('fooId');
     $propertyDefinitions = array('fooId' => $propertyDefinition);
     $typeMutability = $this->getMockBuilder('\\Dkd\\PhpCmis\\Definitions\\TypeMutabilityInterface')->getMockForAbstractClass();
     return array(array('baseTypeId', $baseTypeId, $baseTypeId), array('propertyDefinitions', $propertyDefinitions, $propertyDefinitions), array('typeMutability', $typeMutability, $typeMutability));
 }
 /**
  * DataProvider for all properties with a valid value and an invalid value
  *
  * @return array
  */
 public function propertiesOfSutDataProvider()
 {
     return array(array('propertyName' => 'id', 'validValue' => 'exampleString', 'invalidValue' => 123), array('propertyName' => 'name', 'validValue' => 'exampleString', 'invalidValue' => 123), array('propertyName' => 'description', 'validValue' => 'exampleString', 'invalidValue' => 123), array('propertyName' => 'rootFolderId', 'validValue' => 'exampleString', 'invalidValue' => 123), array('propertyName' => 'principalIdAnonymous', 'validValue' => 'exampleString', 'invalidValue' => 123), array('propertyName' => 'principalIdAnyone', 'validValue' => 'exampleString', 'invalidValue' => 123), array('propertyName' => 'thinClientUri', 'validValue' => 'exampleString', 'invalidValue' => 123), array('propertyName' => 'latestChangeLogToken', 'validValue' => 'exampleString', 'invalidValue' => 123), array('propertyName' => 'vendorName', 'validValue' => 'exampleString', 'invalidValue' => 123), array('propertyName' => 'productName', 'validValue' => 'exampleString', 'invalidValue' => 123), array('propertyName' => 'productVersion', 'validValue' => 'exampleString', 'invalidValue' => 123), array('propertyName' => 'changesIncomplete', 'validValue' => true, 'invalidValue' => 1), array('propertyName' => 'capabilities', 'validValue' => $this->getMockForAbstractClass('\\Dkd\\PhpCmis\\Data\\RepositoryCapabilitiesInterface'), 'invalidValue' => self::DO_NOT_TEST_INVALID_TYPE_VALUE), array('propertyName' => 'aclCapabilities', 'validValue' => $this->getMockForAbstractClass('\\Dkd\\PhpCmis\\Data\\AclCapabilitiesInterface'), 'invalidValue' => self::DO_NOT_TEST_INVALID_TYPE_VALUE), array('propertyName' => 'cmisVersion', 'validValue' => CmisVersion::cast(CmisVersion::CMIS_1_1), 'invalidValue' => self::DO_NOT_TEST_INVALID_TYPE_VALUE), array('propertyName' => 'changesOnType', 'validValue' => array(BaseTypeId::cast(BaseTypeId::CMIS_DOCUMENT)), 'invalidValue' => array('foo')), array('propertyName' => 'extensionFeatures', 'validValue' => array($this->getMockForAbstractClass('\\Dkd\\PhpCmis\\Data\\ExtensionFeatureInterface')), 'invalidValue' => array(new \stdClass())));
 }
    die("Please add your connection credentials to the file \"" . __DIR__ . "/conf/Configuration.php\".\n");
} else {
    require_once __DIR__ . '/conf/Configuration.php';
}
$httpInvoker = new \GuzzleHttp\Client(array('defaults' => array('auth' => array(CMIS_BROWSER_USER, CMIS_BROWSER_PASSWORD))));
$parameters = array(\Dkd\PhpCmis\SessionParameter::BINDING_TYPE => \Dkd\PhpCmis\Enum\BindingType::BROWSER, \Dkd\PhpCmis\SessionParameter::BROWSER_URL => CMIS_BROWSER_URL, \Dkd\PhpCmis\SessionParameter::BROWSER_SUCCINCT => false, \Dkd\PhpCmis\SessionParameter::HTTP_INVOKER_OBJECT => $httpInvoker);
$sessionFactory = new \Dkd\PhpCmis\SessionFactory();
// If no repository id is defined use the first repository
if (CMIS_REPOSITORY_ID === null) {
    $repositories = $sessionFactory->getRepositories($parameters);
    $parameters[\Dkd\PhpCmis\SessionParameter::REPOSITORY_ID] = $repositories[0]->getId();
} else {
    $parameters[\Dkd\PhpCmis\SessionParameter::REPOSITORY_ID] = CMIS_REPOSITORY_ID;
}
$session = $sessionFactory->createSession($parameters);
echo "Create CMIS type\n\n";
try {
    $typeMutability = new \Dkd\PhpCmis\DataObjects\TypeMutability();
    $typeMutability->setCanCreate(true);
    $typeMutability->setCanUpdate(true);
    $typeMutability->setCanDelete(true);
    $typeDefinition = $session->getObjectFactory()->createTypeDefinition('typo3:page', 'page', (string) \Dkd\PhpCmis\Enum\BaseTypeId::cast(\Dkd\PhpCmis\Enum\BaseTypeId::CMIS_DOCUMENT), (string) \Dkd\PhpCmis\Enum\BaseTypeId::cast(\Dkd\PhpCmis\Enum\BaseTypeId::CMIS_DOCUMENT), true, true, true, true, true, true, true, '', '', 'TYPO3 Page', 'TYPO3 Page object', $typeMutability);
    $session->createType($typeDefinition);
    echo "Type definition has been created. Id: " . $typeDefinition->getId() . "\n";
    echo "Please delete that definition now by hand!\n";
} catch (\Dkd\PhpCmis\Exception\CmisContentAlreadyExistsException $e) {
    echo "********* ERROR **********\n";
    echo $e->getMessage() . "\n";
    echo "**************************\n";
    exit;
}
 /**
  * Returns the paths of this object.
  *
  * @return string[] the list of paths of this object or an empty list if this object is unfiled or if this object
  *     is the root folder
  * @throws CmisRuntimeException Throws exception if repository sends invalid data
  */
 public function getPaths()
 {
     $folderType = $this->getSession()->getTypeDefinition((string) BaseTypeId::cast(BaseTypeId::CMIS_FOLDER));
     $propertyDefinition = $folderType->getPropertyDefinition(PropertyIds::PATH);
     $pathQueryName = $propertyDefinition === null ? null : $propertyDefinition->getQueryName();
     // get object paths of the parent folders
     $bindingParents = $this->getBinding()->getNavigationService()->getObjectParents($this->getRepositoryId(), $this->getId(), $pathQueryName, false, IncludeRelationships::cast(IncludeRelationships::NONE), Constants::RENDITION_NONE, true, null);
     $paths = array();
     foreach ($bindingParents as $parent) {
         if ($parent->getObject()->getProperties() === null) {
             // that should never happen but could in case of an faulty repository implementation
             throw new CmisRuntimeException('Repository sent invalid data! No properties given.');
         }
         $parentProperties = $parent->getObject()->getProperties()->getProperties();
         $pathProperty = null;
         if (isset($parentProperties[PropertyIds::PATH])) {
             $pathProperty = $parentProperties[PropertyIds::PATH];
         }
         if (!$pathProperty instanceof PropertyStringInterface) {
             // the repository sent an object without a valid path...
             throw new CmisRuntimeException('Repository sent invalid data! Path is not set!');
         }
         if ($parent->getRelativePathSegment() === null) {
             throw new CmisRuntimeException('Repository sent invalid data! No relative path segement!');
         }
         $folderPath = rtrim((string) $pathProperty->getFirstValue(), '/') . '/';
         $paths[] = $folderPath . $parent->getRelativePathSegment();
     }
     return $paths;
 }
 public function testGetBaseTypeIdReturnsFirstValueOfIdMultiValuePropertyValue()
 {
     $idProperty = new PropertyId(PropertyIds::BASE_TYPE_ID, array('cmis:item', 'cmis:document'));
     $properties = new Properties();
     $properties->addProperty($idProperty);
     $this->objectData->setProperties($properties);
     $this->assertEquals(BaseTypeId::cast(BaseTypeId::CMIS_ITEM), $this->objectData->getBaseTypeId());
 }
 /**
  * Returns the base type of this CMIS object (object type identified by cmis:baseTypeId).
  *
  * @return BaseTypeId|null the base type of the object or <code>null</code> if the property
  *         cmis:baseTypeId hasn't been requested or hasn't been provided by the repository
  */
 public function getBaseTypeId()
 {
     $baseTypeProperty = $this->getProperty(PropertyIds::BASE_TYPE_ID);
     if ($baseTypeProperty === null) {
         return null;
     }
     return BaseTypeId::cast($baseTypeProperty->getFirstValue());
 }
 /**
  * @param RepositoryCapabilities $repositoryCapabilities
  * @param AclCapabilities $aclCapabilities
  * @return RepositoryInfoBrowserBinding
  */
 protected function getExpectedRepositoryInfoObjectForFullRequest($repositoryCapabilities, $aclCapabilities)
 {
     $repositoryInfo = new RepositoryInfoBrowserBinding();
     $repositoryInfo->setId('A1');
     $repositoryInfo->setName('Apache Chemistry OpenCMIS InMemory Repository');
     $repositoryInfo->setCmisVersion(CmisVersion::cast(CmisVersion::CMIS_1_1));
     $repositoryInfo->setDescription('Apache Chemistry OpenCMIS InMemory Repository (Version: ?)');
     $repositoryInfo->setVendorName('Apache Chemistry');
     $repositoryInfo->setProductName('OpenCMIS InMemory-Server');
     $repositoryInfo->setProductVersion('?');
     $repositoryInfo->setRootFolderId('100');
     $repositoryInfo->setRepositoryUrl('http://www.example.com:8080/inmemory/browser/A1');
     $repositoryInfo->setCapabilities($repositoryCapabilities);
     $repositoryInfo->setRootUrl('http://www.example.com:8080/inmemory/browser/A1/root');
     $repositoryInfo->setAclCapabilities($aclCapabilities);
     $repositoryInfo->setLatestChangeLogToken('0');
     $repositoryInfo->setCmisVersion(CmisVersion::cast('1.1'));
     $repositoryInfo->setChangesIncomplete(true);
     $repositoryInfo->setChangesOnType(array(BaseTypeId::cast(BaseTypeId::CMIS_DOCUMENT)));
     $repositoryInfo->setPrincipalIdAnonymous('anonymous');
     $repositoryInfo->setPrincipalIdAnyone('anyone');
     $repositoryInfo->setExtensions($this->cmisExtensionsDummy);
     $extensionFeature = new ExtensionFeature();
     $extensionFeature->setId('E1');
     $extensionFeature->setUrl('http://foo.bar.baz');
     $extensionFeature->setCommonName('commonName');
     $extensionFeature->setVersionLabel('versionLabel');
     $extensionFeature->setDescription('Description');
     $extensionFeature->setFeatureData(array('foo' => 'bar'));
     $extensionFeature->setExtensions($this->cmisExtensionsDummy);
     $repositoryInfo->setExtensionFeatures(array($extensionFeature));
     return $repositoryInfo;
 }
 /**
  * Get a type definition object by its base type id
  *
  * @param string $baseTypeIdString
  * @param string $typeId
  * @return FolderTypeDefinition|DocumentTypeDefinition|RelationshipTypeDefinition|PolicyTypeDefinition|ItemTypeDefinition|SecondaryTypeDefinition
  * @throws CmisInvalidArgumentException Exception is thrown if the base type exists in the BaseTypeId enumeration
  *      but is not implemented here. This could only happen if the base type enumeration is extended which requires
  *      a CMIS specification change.
  */
 public function getTypeDefinitionByBaseTypeId($baseTypeIdString, $typeId)
 {
     $baseTypeId = BaseTypeId::cast($baseTypeIdString);
     if ($baseTypeId->equals(BaseTypeId::cast(BaseTypeId::CMIS_FOLDER))) {
         $baseType = new FolderTypeDefinition($typeId);
     } elseif ($baseTypeId->equals(BaseTypeId::cast(BaseTypeId::CMIS_DOCUMENT))) {
         $baseType = new DocumentTypeDefinition($typeId);
     } elseif ($baseTypeId->equals(BaseTypeId::cast(BaseTypeId::CMIS_RELATIONSHIP))) {
         $baseType = new RelationshipTypeDefinition($typeId);
     } elseif ($baseTypeId->equals(BaseTypeId::cast(BaseTypeId::CMIS_POLICY))) {
         $baseType = new PolicyTypeDefinition($typeId);
     } elseif ($baseTypeId->equals(BaseTypeId::cast(BaseTypeId::CMIS_ITEM))) {
         $baseType = new ItemTypeDefinition($typeId);
     } elseif ($baseTypeId->equals(BaseTypeId::cast(BaseTypeId::CMIS_SECONDARY))) {
         $baseType = new SecondaryTypeDefinition($typeId);
     } else {
         // @codeCoverageIgnoreStart
         // this could only happen if a new baseType is added to the enumeration and not implemented here.
         throw new CmisInvalidArgumentException(sprintf('The given type definition "%s" could not be converted.', $baseTypeId));
         // @codeCoverageIgnoreEnd
     }
     $baseType->setBaseTypeId($baseTypeId);
     return $baseType;
 }
 /**
  * @param RepositoryInfoBrowserBinding $object
  * @param array $data
  * @return RepositoryInfoBrowserBinding
  */
 protected function setRepositoryInfoValues(RepositoryInfoBrowserBinding $object, $data)
 {
     if (isset($data[JSONConstants::JSON_REPINFO_CAPABILITIES]) && is_array($data[JSONConstants::JSON_REPINFO_CAPABILITIES])) {
         $repositoryCapabilities = $this->convertRepositoryCapabilities($data[JSONConstants::JSON_REPINFO_CAPABILITIES]);
         if ($repositoryCapabilities !== null) {
             $data[JSONConstants::JSON_REPINFO_CAPABILITIES] = $repositoryCapabilities;
         } else {
             unset($data[JSONConstants::JSON_REPINFO_CAPABILITIES]);
         }
     }
     if (isset($data[JSONConstants::JSON_REPINFO_ACL_CAPABILITIES]) && is_array($data[JSONConstants::JSON_REPINFO_ACL_CAPABILITIES])) {
         $aclCapabilities = $this->convertAclCapabilities($data[JSONConstants::JSON_REPINFO_ACL_CAPABILITIES]);
         if ($aclCapabilities !== null) {
             $data[JSONConstants::JSON_REPINFO_ACL_CAPABILITIES] = $aclCapabilities;
         } else {
             unset($data[JSONConstants::JSON_REPINFO_ACL_CAPABILITIES]);
         }
     }
     if (isset($data[JSONConstants::JSON_REPINFO_CHANGES_ON_TYPE]) && is_array($data[JSONConstants::JSON_REPINFO_CHANGES_ON_TYPE])) {
         $types = array();
         foreach ($data[JSONConstants::JSON_REPINFO_CHANGES_ON_TYPE] as $type) {
             if (!empty($type)) {
                 $types[] = BaseTypeId::cast($type);
             }
         }
         $data[JSONConstants::JSON_REPINFO_CHANGES_ON_TYPE] = $types;
     }
     if (isset($data[JSONConstants::JSON_REPINFO_EXTENDED_FEATURES]) && is_array($data[JSONConstants::JSON_REPINFO_EXTENDED_FEATURES])) {
         $data[JSONConstants::JSON_REPINFO_EXTENDED_FEATURES] = $this->convertExtensionFeatures($data[JSONConstants::JSON_REPINFO_EXTENDED_FEATURES]);
     }
     if (isset($data[JSONConstants::JSON_REPINFO_CMIS_VERSION_SUPPORTED])) {
         $data[JSONConstants::JSON_REPINFO_CMIS_VERSION_SUPPORTED] = CmisVersion::cast($data[JSONConstants::JSON_REPINFO_CMIS_VERSION_SUPPORTED]);
     }
     $object->setExtensions($this->convertExtension($data, JSONConstants::getRepositoryInfoKeys()));
     $object->populate($data, array_merge(array_combine(JSONConstants::getRepositoryInfoKeys(), JSONConstants::getRepositoryInfoKeys()), array(JSONConstants::JSON_REPINFO_DESCRIPTION => 'description', JSONConstants::JSON_REPINFO_CMIS_VERSION_SUPPORTED => 'cmisVersion', JSONConstants::JSON_REPINFO_ID => 'id', JSONConstants::JSON_REPINFO_ROOT_FOLDER_URL => 'rootUrl', JSONConstants::JSON_REPINFO_NAME => 'name', JSONConstants::JSON_REPINFO_EXTENDED_FEATURES => 'extensionFeatures')), true);
     return $object;
 }
 /**
  * Returns the base object type.
  *
  * @return BaseTypeId|null the base object type or <code>null</code> if the base object type is unknown
  */
 public function getBaseTypeId()
 {
     $value = $this->getFirstValue(PropertyIds::BASE_TYPE_ID);
     if (is_string($value)) {
         try {
             return BaseTypeId::cast($value);
         } catch (InvalidEnumerationValueException $e) {
             // invalid base type -> return null
         }
     }
     return null;
 }
Beispiel #11
0
 /**
  * Creates a new document from a source document.
  *
  * @param ObjectIdInterface $source The identifier for the source document.
  * @param string[] $properties The property values that MUST be applied to the object. This list of properties
  *      SHOULD only contain properties whose values differ from the source document.
  * @param ObjectIdInterface|null $folderId If specified, the identifier for the folder that MUST be the parent
  *      folder for the newly-created document object. This parameter MUST be specified if the repository does NOT
  *      support the optional "unfiling" capability.
  * @param VersioningState|null $versioningState An enumeration specifying what the versioning state of the
  *     newly-created object MUST be. Valid values are:
  *      <code>none</code>
  *          (default, if the object-type is not versionable) The document MUST be created as a non-versionable
  *          document.
  *     <code>checkedout</code>
  *          The document MUST be created in the checked-out state. The checked-out document MAY be
  *          visible to other users.
  *     <code>major</code>
  *          (default, if the object-type is versionable) The document MUST be created as a major version.
  *     <code>minor</code>
  *          The document MUST be created as a minor version.
  * @param PolicyInterface[] $policies A list of policy ids that MUST be applied to the newly-created
  *      document object.
  * @param AceInterface[] $addAces A list of ACEs that MUST be added to the newly-created document object,
  *      either using the ACL from folderId if specified, or being applied if no folderId is specified.
  * @param AceInterface[] $removeAces A list of ACEs that MUST be removed from the newly-created document
  *      object, either using the ACL from folderId if specified, or being ignored if no folderId is specified.
  * @return ObjectIdInterface|null the object ID of the new document or <code>null</code> if the document could not
  *      be created.
  * @throws CmisInvalidArgumentException Throws an <code>CmisInvalidArgumentException</code> if empty
  *      property list is given
  */
 public function createDocumentFromSource(ObjectIdInterface $source, array $properties = array(), ObjectIdInterface $folderId = null, VersioningState $versioningState = null, array $policies = array(), array $addAces = array(), array $removeAces = array())
 {
     if (!$source instanceof CmisObjectInterface) {
         $sourceObject = $this->getObject($source);
     } else {
         $sourceObject = $source;
     }
     $type = $sourceObject->getType();
     $secondaryTypes = $sourceObject->getSecondaryTypes();
     if ($secondaryTypes === null) {
         $secondaryTypes = array();
     }
     if (!BaseTypeId::cast($type->getBaseTypeId())->equals(BaseTypeId::CMIS_DOCUMENT)) {
         throw new CmisInvalidArgumentException('Source object must be a document!');
     }
     $objectId = $this->getBinding()->getObjectService()->createDocumentFromSource($this->getRepositoryId(), $source->getId(), $this->getObjectFactory()->convertProperties($properties, $type, $secondaryTypes, self::$createAndCheckoutUpdatability), $folderId === null ? null : $folderId->getId(), $versioningState, $this->getObjectFactory()->convertPolicies($policies), $this->getObjectFactory()->convertAces($addAces), $this->getObjectFactory()->convertAces($removeAces), null);
     if ($objectId === null) {
         return null;
     }
     return $this->createObjectId($objectId);
 }