public function importResourceFromContent($content, $filename, $collectionName = ResourceManager::DEFAULT_PERSISTENT_COLLECTION_NAME, $forcedPersistenceObjectIdentifier = null)
    {
        if (!is_string($content)) {
            throw new Exception(sprintf('Tried to import content into the resource collection "%s" but the given content was a %s instead of a string.', $collectionName, gettype($content)), 1380878115);
        }
        $this->initialize();

        if (!isset($this->collections[$collectionName])) {
            throw new Exception(sprintf('Tried to import a file into the resource collection "%s" but no such collection exists. Please check your settings and the code which triggered the import.', $collectionName), 1380878131);
        }

        /* @var CollectionInterface $collection */
        $collection = $this->collections[$collectionName];

        try {
            $resource = $collection->importResourceFromContent($content);
            $resource->setFilename($filename);
            if ($forcedPersistenceObjectIdentifier !== null) {
                ObjectAccess::setProperty($resource, 'Persistence_Object_Identifier', $forcedPersistenceObjectIdentifier, true);
            }
        } catch (Exception $exception) {
            throw new Exception(sprintf('Importing content into the resource collection "%s" failed: %s', $collectionName, $exception->getMessage()), 1381156155, $exception);
        }

        $this->resourceRepository->add($resource);
        $this->logger->debug(sprintf('Successfully imported content into the resource collection "%s" (storage: %s, a %s. SHA1: %s)', $collectionName, $collection->getStorage()->getName(), get_class($collection->getStorage()), $resource->getSha1()));

        return $resource;
    }
public function importResourceFromContent($content, $filename, $collectionName = ResourceManager::DEFAULT_PERSISTENT_COLLECTION_NAME, $forcedPersistenceObjectIdentifier = null)
    {
        if (!is_string($content)) {
            throw new Exception(sprintf('Tried to import content into the resource collection "%s" but the given content was a %s instead of a string.', $collectionName, gettype($content)), 1380878115);
        }
        $this->initialize();

        if (!isset($this->collections[$collectionName])) {
            throw new Exception(sprintf('Tried to import a file into the resource collection "%s" but no such collection exists. Please check your settings and the code which triggered the import.', $collectionName), 1380878131);
        }

        /* @var CollectionInterface $collection */
        $collection = $this->collections[$collectionName];

        try {
            $resource = $collection->importResourceFromContent($content);
            $resource->setFilename($filename);
            if ($forcedPersistenceObjectIdentifier !== null) {
                ObjectAccess::setProperty($resource, 'Persistence_Object_Identifier', $forcedPersistenceObjectIdentifier, true);
            }
        } catch (Exception $exception) {
            throw new Exception(sprintf('Importing content into the resource collection "%s" failed: %s', $collectionName, $exception->getMessage()), 1381156155, $exception);
        }

        $this->resourceRepository->add($resource);
        $this->logger->debug(sprintf('Successfully imported content into the resource collection "%s" (storage: %s, a %s. SHA1: %s)', $collectionName, $collection->getStorage()->getName(), get_class($collection->getStorage()), $resource->getSha1()));

        return $resource;
    }
public function importResourceFromContent ( $ content , $ filename , $ collectionName = ResourceManager :: DEFAULT_PERSISTENT_COLLECTION_NAME , $ forcedPersistenceObjectIdentifier = null ) { if ( ! is_string ( $ content ) ) { throw new Exception ( sprintf ( 'Tried to import content into the resource collection "%s" but the given content was a %s instead of a string.' , $ collectionName , gettype ( $ content ) ) , 1380878115 ) ; } $ this -> initialize ( ) ; if ( ! isset ( $ this -> collections [ $ collectionName ] ) ) { throw new Exception ( sprintf ( 'Tried to import a file into the resource collection "%s" but no such collection exists. Please check your settings and the code which triggered the import.' , $ collectionName ) , 1380878131 ) ; } /* @var CollectionInterface $collection */ $ collection = $ this -> collections [ $ collectionName ] ; try { $ resource = $ collection -> importResourceFromContent ( $ content ) ; $ resource -> setFilename ( $ filename ) ; if ( $ forcedPersistenceObjectIdentifier !== null ) { ObjectAccess :: setProperty ( $ resource , 'Persistence_Object_Identifier' , $ forcedPersistenceObjectIdentifier , true ) ; } } catch ( Exception $ exception ) { throw new Exception ( sprintf ( 'Importing content into the resource collection "%s" failed: %s' , $ collectionName , $ exception -> getMessage ( ) ) , 1381156155 , $ exception ) ; } $ this -> resourceRepository -> add ( $ resource ) ; $ this -> logger -> debug ( sprintf ( 'Successfully imported content into the resource collection "%s" (storage: %s, a %s. SHA1: %s)' , $ collectionName , $ collection -> getStorage ( ) -> getName ( ) , get_class ( $ collection -> getStorage ( ) ) , $ resource -> getSha1 ( ) ) ) ; return $ resource ; }
Imports the given content passed as a string as a new persistent resource.

The given content typically is binary data or a text format. On a successful import this method
returns a PersistentResource object representing the imported content and automatically publishes it to the
configured publication target.

The specified filename will be used when presenting the resource to a user. Its file extension is
important because the resource management will derive the IANA Media Type from it.

@param string $content The binary content to import
@param string $filename The filename to use for the newly generated resource
@param string $collectionName Name of the collection this new resource should be added to. By default the standard collection for persistent resources is used.
@param string $forcedPersistenceObjectIdentifier INTERNAL: Force the object identifier for this resource to the given UUID
@return PersistentResource A resource object representing the imported resource
@throws Exception
@api
Imports the given content passed as a string as a new persistent resource .