private function addContentType(RequestInterface $request, StreamInterface $body) { if (!($uri = $body->getMetadata('uri'))) { return; } // Guess the content-type based on the stream's "uri" metadata value. // The file extension is used to determine the appropriate mime-type. if ($contentType = Mimetypes::getInstance()->fromFilename($uri)) { $request->setHeader('Content-Type', $contentType); } }
/** * Creates a document object of the specified type (given by the cmis:objectTypeId property) * in the (optionally) specified location. * * @param string $repositoryId the identifier for the repository * @param PropertiesInterface $properties the property values that must be applied to the newly * created document object * @param string|null $folderId if specified, the identifier for the folder that must be the parent * folder for the newly created document object * @param StreamInterface|null $contentStream the content stream that must be stored for the newly * created document object * @param VersioningState|null $versioningState specifies what the versioning state of the newly created object * must be (default is <code>VersioningState::MAJOR</code>) * @param string[] $policies a list of policy IDs that must be applied to the newly created document object * @param AclInterface|null $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 AclInterface|null $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 * @param ExtensionDataInterface|null $extension * @return string|null Returns the new object id or <code>null</code> if the repository sent an empty * result (which should not happen) */ public function createDocument($repositoryId, PropertiesInterface $properties, $folderId = null, StreamInterface $contentStream = null, VersioningState $versioningState = null, array $policies = array(), AclInterface $addAces = null, AclInterface $removeAces = null, ExtensionDataInterface $extension = null) { if ($folderId === null) { $url = $this->getRepositoryUrl($repositoryId); } else { $url = $this->getObjectUrl($repositoryId, $folderId); } $url->getQuery()->modify($this->convertPropertiesToQueryArray($properties)); $url->getQuery()->modify(array(Constants::CONTROL_CMISACTION => Constants::CMISACTION_CREATE_DOCUMENT, Constants::PARAM_SUCCINCT => $this->getSuccinct() ? 'true' : 'false')); if ($versioningState !== null) { $url->getQuery()->modify(array(Constants::PARAM_VERSIONING_STATE => (string) $versioningState)); } $this->appendAddAcesToUrl($url, $addAces); $this->appendRemoveAcesToUrl($url, $removeAces); $this->appendPoliciesToUrl($url, $policies); // Guzzle gets the mime type for a file by the filename extension. Sometimes the filename does not contain // the correct filename extension for example when a file is uploaded in php it gets a temporary name without // a file extension. If the filename does not contain a file extension we use the given 'cmis:name' property // as filename. See also https://github.com/guzzle/guzzle/issues/571 if ($contentStream !== null && pathinfo($contentStream->getMetadata('uri'), PATHINFO_EXTENSION) === '') { $contentStream = new PostFile('content', $contentStream, $properties->getProperties()['cmis:name']->getFirstValue()); } $responseData = $this->post($url, array('content' => $contentStream))->json(); $newObject = $this->getJsonConverter()->convertObject($responseData); return $newObject === null ? null : $newObject->getId(); }
/** * {@inheritdoc} */ protected function doGetMetadata($key = null) { return method_exists($this->stream, 'getMetadata') ? $this->stream->getMetadata($key) : ($key !== null ? null : array()); }