public function createFolder($repositoryId, $typeId, $properties, $folderId)
 {
     $objectId = null;
     // fetch type definition of supplied type and check for base type "folder", if not true throw exception
     $RepositoryService = new CMISRepositoryService();
     try {
         $typeDefinition = $RepositoryService->getTypeDefinition($repositoryId, $typeId);
     } catch (Exception $e) {
         throw new ConstraintViolationException('Object is not of base type folder. ' . $e->getMessage());
     }
     if ($typeDefinition['attributes']['baseType'] != 'folder') {
         throw new ConstraintViolationException('Object is not of base type folder');
     }
     // Attempt to decode $folderId, use as is if not detected as encoded
     $tmpObjectId = $folderId;
     $tmpObjectId = CMISUtil::decodeObjectId($tmpObjectId, $tmpTypeId);
     if ($tmpTypeId != 'Unknown') {
         $folderId = $tmpObjectId;
     }
     // if parent folder is not allowed to hold this type, throw exception
     $CMISFolder = new CMISFolderObject($folderId, $this->ktapi);
     $allowed = $CMISFolder->getProperty('AllowedChildObjectTypeIds');
     if (!is_array($allowed) || !in_array($typeId, $allowed)) {
         throw new ConstraintViolationException('Parent folder may not hold objects of this type (' . $typeId . ')');
     }
     // TODO if name is blank! throw another exception (check type) - using invalidArgument Exception for now
     if (trim($properties['name']) == '') {
         throw new InvalidArgumentException('Refusing to create an un-named folder');
     }
     $response = $this->ktapi->create_folder((int) $folderId, $properties['name'], $sig_username = '', $sig_password = '', $reason = '');
     if ($response['status_code'] != 0) {
         throw new StorageException('The repository was unable to create the folder: ' . $response['message']);
     } else {
         $objectId = CMISUtil::encodeObjectId('Folder', $response['results']['id']);
     }
     return $objectId;
 }
 public function checkIn($repositoryId, $documentId, $major, $contentStream = null, $changeToken = '', $properties = array(), $checkinComment = '')
 {
     $documentId = CMISUtil::decodeObjectId($documentId, $typeId);
     // throw updateConflictException if the operation is attempting to update an object that is no longer current (as determined by the repository).
     try {
         $pwc = new CMISDocumentObject($documentId, $this->ktapi);
     } catch (exception $e) {
         throw new UpdateConflictException($e->getMessage());
     }
     // throw exception if the object is not versionable
     if (!$pwc->getAttribute('versionable')) {
         throw new ConstraintViolationException('This document is not versionable and may not be checked in');
     }
     $RepositoryService = new CMISRepositoryService();
     try {
         $typeDefinition = $RepositoryService->getTypeDefinition($repositoryId, $typeId);
     } catch (exception $e) {
         // if we can't get the type definition, then we can't store the content
         throw new StorageException($e->getMessage());
     }
     if ($typeDefinition['attributes']['contentStreamAllowed'] == 'notAllowed' && !empty($contentStream)) {
         throw new StreamNotSupportedException('Content Streams are not supported');
     }
     // check that this is the latest version
     if ($pwc->getProperty('IsLatestVersion') != true) {
         throw new VersioningException('The document is not the latest version and cannot be checked in');
     }
     // now do the checkin
     $tempfilename = CMISUtil::createTemporaryFile($contentStream);
     $response = $this->ktapi->checkin_document($documentId, $pwc->getProperty('ContentStreamFilename'), $reason, $tempfilename, $major, $sig_username, $sig_password);
     // if there was any error in cancelling the checkout
     if ($response['status_code'] == 1) {
         throw new RuntimeException('There was an error checking in the document: ' . $response['message']);
     }
     return CMISUtil::encodeObjectId(DOCUMENT, $documentId);
 }