Exemplo n.º 1
0
 public function createBinaryFile(BinaryFileCreateStruct $binaryFileCreateStruct)
 {
     if (empty($binaryFileCreateStruct->id) || !is_string($binaryFileCreateStruct->id)) {
         throw new InvalidArgumentValue('id', $binaryFileCreateStruct->id, 'BinaryFileCreateStruct');
     }
     if (!is_int($binaryFileCreateStruct->size) || $binaryFileCreateStruct->size < 0) {
         throw new InvalidArgumentValue('size', $binaryFileCreateStruct->size, 'BinaryFileCreateStruct');
     }
     if (!is_resource($binaryFileCreateStruct->inputStream)) {
         throw new InvalidArgumentValue('inputStream', 'property is not a file resource', 'BinaryFileCreateStruct');
     }
     if (!isset($binaryFileCreateStruct->mimeType)) {
         $buffer = fread($binaryFileCreateStruct->inputStream, $binaryFileCreateStruct->size);
         $binaryFileCreateStruct->mimeType = $this->mimeTypeDetector->getFromBuffer($buffer);
         unset($buffer);
     }
     $spiBinaryCreateStruct = $this->buildSPIBinaryFileCreateStructObject($binaryFileCreateStruct);
     try {
         $this->binarydataHandler->create($spiBinaryCreateStruct);
     } catch (Exception $e) {
         throw new IOException('An error occured creating binarydata', $e);
     }
     $spiBinaryFile = $this->metadataHandler->create($spiBinaryCreateStruct);
     if (!isset($spiBinaryFile->uri)) {
         $spiBinaryFile->uri = $this->binarydataHandler->getUri($spiBinaryFile->id);
     }
     return $this->buildDomainBinaryFileObject($spiBinaryFile);
 }
Exemplo n.º 2
0
 /**
  * Creates a binary file in the repository
  *
  * @param \eZ\Publish\Core\IO\Values\BinaryFileCreateStruct $binaryFileCreateStruct
  *
  * @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentValue
  *
  * @return \eZ\Publish\Core\IO\Values\BinaryFile The created BinaryFile object
  */
 public function createBinaryFile(BinaryFileCreateStruct $binaryFileCreateStruct)
 {
     if (empty($binaryFileCreateStruct->id) || !is_string($binaryFileCreateStruct->id)) {
         throw new InvalidArgumentValue("id", $binaryFileCreateStruct->id, "BinaryFileCreateStruct");
     }
     if (!is_int($binaryFileCreateStruct->size) || $binaryFileCreateStruct->size < 0) {
         throw new InvalidArgumentValue("size", $binaryFileCreateStruct->size, "BinaryFileCreateStruct");
     }
     if (!is_resource($binaryFileCreateStruct->inputStream)) {
         throw new InvalidArgumentValue("inputStream", "property is not a file resource", "BinaryFileCreateStruct");
     }
     if (!isset($binaryFileCreateStruct->mimeType)) {
         $buffer = fread($binaryFileCreateStruct->inputStream, $binaryFileCreateStruct->size);
         $binaryFileCreateStruct->mimeType = $this->mimeTypeDetector->getFromBuffer($buffer);
         unset($buffer);
     }
     $spiBinaryCreateStruct = $this->buildSPIBinaryFileCreateStructObject($binaryFileCreateStruct);
     $spiBinaryFile = $this->ioHandler->create($spiBinaryCreateStruct);
     return $this->buildDomainBinaryFileObject($spiBinaryFile);
 }