本文整理汇总了PHP中TYPO3\Flow\Resource\ResourceManager::importResource方法的典型用法代码示例。如果您正苦于以下问题:PHP ResourceManager::importResource方法的具体用法?PHP ResourceManager::importResource怎么用?PHP ResourceManager::importResource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TYPO3\Flow\Resource\ResourceManager
的用法示例。
在下文中一共展示了ResourceManager::importResource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildTestResource
/**
* @return \TYPO3\Flow\Resource\Resource
* @throws \TYPO3\Flow\Resource\Exception
*/
protected function buildTestResource()
{
$testImagePath = Files::concatenatePaths([__DIR__, 'Fixtures/Resources/Lighthouse.jpg']);
$resource = $this->resourceManager->importResource($testImagePath);
$asset = new \TYPO3\Media\Domain\Model\Asset($resource);
return $asset;
}
示例2: processImage
/**
* @param FlowResource $originalResource
* @param array $adjustments
* @return array resource, width, height as keys
* @throws ImageFileException
* @throws InvalidConfigurationException
* @throws \TYPO3\Flow\Resource\Exception
*/
public function processImage(FlowResource $originalResource, array $adjustments)
{
$additionalOptions = array();
$adjustmentsApplied = false;
// TODO: Special handling for SVG should be refactored at a later point.
if ($originalResource->getMediaType() === 'image/svg+xml') {
$originalResourceStream = $originalResource->getStream();
$resource = $this->resourceManager->importResource($originalResourceStream, $originalResource->getCollectionName());
fclose($originalResourceStream);
$resource->setFilename($originalResource->getFilename());
return ['width' => null, 'height' => null, 'resource' => $resource];
}
$resourceUri = $originalResource->createTemporaryLocalCopy();
$resultingFileExtension = $originalResource->getFileExtension();
$transformedImageTemporaryPathAndFilename = $this->environment->getPathToTemporaryDirectory() . uniqid('ProcessedImage-') . '.' . $resultingFileExtension;
if (!file_exists($resourceUri)) {
throw new ImageFileException(sprintf('An error occurred while transforming an image: the resource data of the original image does not exist (%s, %s).', $originalResource->getSha1(), $resourceUri), 1374848224);
}
$imagineImage = $this->imagineService->open($resourceUri);
if ($this->imagineService instanceof \Imagine\Imagick\Imagine && $originalResource->getFileExtension() === 'gif' && $this->isAnimatedGif(file_get_contents($resourceUri)) === true) {
$imagineImage->layers()->coalesce();
$layers = $imagineImage->layers();
$newLayers = array();
foreach ($layers as $index => $imagineFrame) {
$imagineFrame = $this->applyAdjustments($imagineFrame, $adjustments, $adjustmentsApplied);
$newLayers[] = $imagineFrame;
}
$imagineImage = array_shift($newLayers);
$layers = $imagineImage->layers();
foreach ($newLayers as $imagineFrame) {
$layers->add($imagineFrame);
}
$additionalOptions['animated'] = true;
} else {
$imagineImage = $this->applyAdjustments($imagineImage, $adjustments, $adjustmentsApplied);
}
if ($adjustmentsApplied === true) {
$imagineImage->save($transformedImageTemporaryPathAndFilename, $this->getOptionsMergedWithDefaults($additionalOptions));
$imageSize = $imagineImage->getSize();
// TODO: In the future the collectionName of the new resource should be configurable.
$resource = $this->resourceManager->importResource($transformedImageTemporaryPathAndFilename, $originalResource->getCollectionName());
if ($resource === false) {
throw new ImageFileException('An error occurred while importing a generated image file as a resource.', 1413562208);
}
unlink($transformedImageTemporaryPathAndFilename);
$pathInfo = UnicodeFunctions::pathinfo($originalResource->getFilename());
$resource->setFilename(sprintf('%s-%ux%u.%s', $pathInfo['filename'], $imageSize->getWidth(), $imageSize->getHeight(), $pathInfo['extension']));
} else {
$originalResourceStream = $originalResource->getStream();
$resource = $this->resourceManager->importResource($originalResourceStream, $originalResource->getCollectionName());
fclose($originalResourceStream);
$resource->setFilename($originalResource->getFilename());
$imageSize = $this->getImageSize($originalResource);
$imageSize = new Box($imageSize['width'], $imageSize['height']);
}
$this->imageSizeCache->set($resource->getCacheEntryIdentifier(), array('width' => $imageSize->getWidth(), 'height' => $imageSize->getHeight()));
$result = array('width' => $imageSize->getWidth(), 'height' => $imageSize->getHeight(), 'resource' => $resource);
return $result;
}
示例3: importAction
/**
* Imports a new image and persists it, including one variant
*
* @param string $importUri
* @return string
*/
public function importAction($importUri)
{
$imageResource = $this->resourceManager->importResource($importUri);
$image = new Image($imageResource);
$imageVariant = new ImageVariant($image);
$this->assetRepository->add($image);
$this->assetRepository->add($imageVariant);
$this->response->setHeader('X-ImageVariantUuid', $this->persistenceManager->getIdentifierByObject($imageVariant));
return 'ok';
}
示例4: setUp
public function setUp()
{
parent::setUp();
if (!$this->persistenceManager instanceof \TYPO3\Flow\Persistence\Doctrine\PersistenceManager) {
$this->markTestSkipped('Doctrine persistence is not enabled');
}
$this->resourceManager = $this->objectManager->get('TYPO3\\Flow\\Resource\\ResourceManager');
$resource = $this->resourceManager->importResource(__DIR__ . '/Fixtures/ReferenceImage.jpg');
$this->originalImage = new Image($resource);
}
示例5: createUserPhlu
/**
* Creates a user based on the given information
*
* The created user and account are automatically added to their respective repositories and thus be persisted.
*
* @param string $username The username of the user to be created.
* @param string $password Password of the user to be created
* @param string $firstName First name of the user to be created
* @param string $lastName Last name of the user to be created
* @param string $department department of the user to be created
* @param string $photo photo of the user to be created
* @param array $roleIdentifiers A list of role identifiers to assign
* @param string $authenticationProviderName Name of the authentication provider to use. Example: "Typo3BackendProvider"
* @return User The created user instance
* @api
*/
public function createUserPhlu($username, $password, $firstName, $lastName, $department, $photo, array $roleIdentifiers = null, $authenticationProviderName = null)
{
$collection = $this->assetCollectionRepository->findByCollectionName('phluCollection2')->getFirst();
if (!$collection) {
$collection = new \TYPO3\Media\Domain\Model\AssetCollection('phluCollection2');
$this->assetCollectionRepository->add($collection);
$this->persistenceManager->persistAll();
}
$user = new User();
$user->setDepartment($department);
$name = new PersonName('', $firstName, '', $lastName, '', $username);
$user->setName($name);
$resource = $this->resourceManager->importResource($photo);
$image = new Image($resource);
$image->setTitle($name->getFullName());
$tag = $this->tagRepository->findBySearchTerm('Hauswart')->getFirst();
if (!$tag) {
$tag = new Tag();
$tag->setLabel('Hauswart');
$this->tagRepository->add($tag);
$collection->addTag($tag);
}
$image->addTag($tag);
$user->setPhoto($image);
$this->assetRepository->add($image);
$collection->addAsset($image);
$this->assetCollectionRepository->update($collection);
return $this->addUserPhlu($username, $password, $user, $roleIdentifiers, $authenticationProviderName);
}
示例6: openFile
/**
* Opens the specified file. If a file is opened currently it gets closed first.
*
* @param string $odsFile: The ODS file to open
* @return void
*/
public function openFile($odsFile)
{
if ($odsFile === $this->currentFile) {
return;
}
if ($this->odsResource !== NULL) {
$this->closeFile();
}
// Create a local copy of the template
$resource = $this->resourceManager->importResource($odsFile);
$this->temporaryFileName = $resource->createTemporaryLocalCopy();
$this->odsResource = new \ZipArchive();
if ($this->odsResource->open($this->temporaryFileName) !== true) {
throw new \Exception('Couldn\'t open ODS file!');
}
$this->currentFile = $odsFile;
}
示例7: importImage
protected function importImage($filename)
{
$resource = $this->resourceManager->importResource($filename);
$image = new Image($resource);
$this->imageRepository->add($image);
$processingInstructions = array();
return $this->objectManager->get('TYPO3\\Media\\Domain\\Model\\ImageVariant', $image, $processingInstructions);
}
示例8: showAction
/**
* @param \GIB\GradingTool\Domain\Model\Project $project
*/
public function showAction($project)
{
$radarChartFileName = $this->submissionService->getRadarImage($project);
$radarChartResource = $this->resourceManager->importResource($radarChartFileName);
$radarChartResource->setFilename('radarChart.jpg');
$radarChartImage = new \TYPO3\Media\Domain\Model\Image($radarChartResource);
$this->persistenceManager->persistAll();
$this->view->assignMultiple(array('project' => $project, 'submission' => $this->submissionService->getProcessedSubmission($project), 'radarChartImage' => $radarChartImage));
}
示例9: reviewSubmissionAction
/**
* Review a submission
*
* The create action is missing because the project is added in the
* SubmissionFinisher (see Form/Finishers)
*
* @param \GIB\GradingTool\Domain\Model\Project $project
*/
public function reviewSubmissionAction(\GIB\GradingTool\Domain\Model\Project $project)
{
// access check
$this->checkOwnerOrAdministratorAndDenyIfNeeded($project);
$submission = $this->submissionService->getProcessedSubmission($project);
$radarChartImagePathAndFilename = $this->submissionService->getRadarImage($project);
$radarChartImageResource = $this->resourceManager->importResource($radarChartImagePathAndFilename);
$radarChartUri = $this->resourcePublisher->getPersistentResourceWebUri($radarChartImageResource);
// this is necessary because we're in a safe request, but generate a resource
$this->persistenceManager->persistAll();
$this->view->assignMultiple(array('submission' => $submission, 'project' => $project, 'radarChartUri' => $radarChartUri));
}
示例10: sendGradingToProjectManager
/**
* Send a mail to the project manager with the spider graph as attachement
*
* @param Project $project
*/
public function sendGradingToProjectManager($project)
{
// send mail to project manager
$radarChartImagePathAndFilename = $this->getRadarImage($project);
$radarChartImageResource = $this->resourceManager->importResource($radarChartImagePathAndFilename);
$radarChartUri = $this->resourcePublisher->getPersistentResourceWebUri($radarChartImageResource);
// this is necessary because we're in a safe request, but generate a resource
$this->persistenceManager->persistAll();
$attachements = array(array('source' => $radarChartUri, 'fileName' => 'gib-grading.png'));
$templateIdentifierOverlay = $this->templateService->getTemplateIdentifierOverlay('newSubmissionProjectManagerNotification', $project);
$this->notificationMailService->sendNotificationMail($templateIdentifierOverlay, $project, $project->getProjectManager(), $project->getProjectManager()->getName()->getFirstName() . ' ' . $project->getProjectManager()->getName()->getLastName(), $project->getProjectManager()->getPrimaryElectronicAddress()->getIdentifier(), '', $attachements);
// CC to GIB
$this->notificationMailService->sendNotificationMail($templateIdentifierOverlay, $project, $project->getProjectManager(), $project->getProjectManager()->getName()->getFirstName() . ' ' . $project->getProjectManager()->getName()->getLastName(), 'grading@gib-foundation.org', '', $attachements);
}
示例11: initializeValue
/**
* @param string $value
* @throws Exception
* @throws \TYPO3\Flow\Resource\Exception
* @throws \TYPO3\Flow\Utility\Exception
*/
protected function initializeValue($value)
{
if (!is_array($value)) {
throw new Exception('Value must be an array, with source URI (sourceUri) and filename (filename)', 1425981082);
}
if (!isset($value['sourceUri'])) {
throw new Exception('Missing source URI', 1425981083);
}
$sourceUri = trim($value['sourceUri']);
if (!isset($value['filename'])) {
throw new Exception('Missing filename URI', 1425981084);
}
$filename = trim($value['filename']);
$overrideFilename = isset($value['overrideFilename']) ? trim($value['overrideFilename']) : $filename;
if (!isset($this->options['downloadDirectory'])) {
throw new Exception('Missing download directory data type option', 1425981085);
}
Files::createDirectoryRecursively($this->options['downloadDirectory']);
$temporaryFileAndPathname = trim($this->options['downloadDirectory'] . $filename);
$this->download($sourceUri, $temporaryFileAndPathname);
$sha1Hash = sha1_file($temporaryFileAndPathname);
# Try to add file extenstion if missing
if (!$this->downloadCache->has($sha1Hash)) {
$fileExtension = pathinfo($temporaryFileAndPathname, PATHINFO_EXTENSION);
if (trim($fileExtension) === '') {
$mimeTypeGuesser = new MimeTypeGuesser();
$mimeType = $mimeTypeGuesser->guess($temporaryFileAndPathname);
$this->logger->log(sprintf('Try to guess mime type for "%s" (%s), result: %s', $sourceUri, $filename, $mimeType), LOG_DEBUG);
$fileExtension = MediaTypes::getFilenameExtensionFromMediaType($mimeType);
if ($fileExtension !== '') {
$oldTemporaryDestination = $temporaryFileAndPathname;
$temporaryDestination = $temporaryFileAndPathname . '.' . $fileExtension;
copy($oldTemporaryDestination, $temporaryDestination);
$this->logger->log(sprintf('Rename "%s" to "%s"', $oldTemporaryDestination, $temporaryDestination), LOG_DEBUG);
}
}
}
$resource = $this->resourceManager->getResourceBySha1($sha1Hash);
if ($resource === NULL) {
$resource = $this->resourceManager->importResource($temporaryFileAndPathname);
if ($filename !== $overrideFilename) {
$resource->setFilename($overrideFilename);
}
}
$this->temporaryFileAndPathname = $temporaryFileAndPathname;
$this->downloadCache->set($sha1Hash, ['sha1Hash' => $sha1Hash, 'filename' => $filename, 'sourceUri' => $sourceUri, 'temporaryFileAndPathname' => $temporaryFileAndPathname]);
$this->value = $resource;
}
示例12: createResource
/**
*
* @param \Lelesys\Plugin\News\Domain\Model\Asset $media
* @param integer $dimension
*/
public function createResource(\Lelesys\Plugin\News\Domain\Model\Asset $media, $dimension)
{
$imagine = $this->objectManager->get('Imagine\\Image\\ImagineInterface');
$imagineImage = $imagine->open(FLOW_PATH_DATA . 'Persistent/Resources/' . $media->getOriginalResource()->getResourcePointer());
if ($dimension === 150) {
$aspectedHeight = $this->getCalculatedHeight(FLOW_PATH_DATA . 'Persistent/Resources/' . $media->getOriginalResource()->getResourcePointer(), $dimension);
$box = $this->objectManager->get('Imagine\\Image\\Box', $dimension, $aspectedHeight);
} else {
$aspectedWidth = $this->getCalculatedWidth(FLOW_PATH_DATA . 'Persistent/Resources/' . $media->getOriginalResource()->getResourcePointer(), $dimension);
$box = $this->objectManager->get('Imagine\\Image\\Box', $aspectedWidth, $dimension);
}
$imagineImage->thumbnail($box)->save(FLOW_PATH_DATA . 'Persistent/Resources/' . $media->getOriginalResource()->getFileName());
$resource = $this->resourceManager->importResource(FLOW_PATH_DATA . 'Persistent/Resources/' . $media->getOriginalResource()->getFileName());
$media->setResource($resource);
unlink(FLOW_PATH_DATA . 'Persistent/Resources/' . $media->getOriginalResource()->getFileName());
}
示例13: handleHashAndData
/**
* @param array $source
* @param PropertyMappingConfigurationInterface $configuration
* @return Resource|Error
*/
protected function handleHashAndData(array $source, PropertyMappingConfigurationInterface $configuration = NULL)
{
$hash = NULL;
$resource = FALSE;
$givenResourceIdentity = NULL;
if (isset($source['__identity'])) {
$givenResourceIdentity = $source['__identity'];
unset($source['__identity']);
$resource = $this->persistenceManager->getObjectByIdentifier($givenResourceIdentity, 'TYPO3\\Flow\\Resource\\Resource');
if ($resource instanceof \TYPO3\Flow\Resource\Resource) {
return $resource;
}
if ($configuration->getConfigurationValue('TYPO3\\Flow\\Resource\\ResourceTypeConverter', self::CONFIGURATION_IDENTITY_CREATION_ALLOWED) !== TRUE) {
throw new \TYPO3\Flow\Property\Exception\InvalidPropertyMappingConfigurationException('Creation of resource objects with identity not allowed. To enable this, you need to set the PropertyMappingConfiguration Value "CONFIGURATION_IDENTITY_CREATION_ALLOWED" to TRUE');
}
}
if (isset($source['hash']) && preg_match('/[0-9a-f]{40}/', $source['hash'])) {
$hash = $source['hash'];
}
if ($hash !== NULL) {
$resourcePointer = $this->persistenceManager->getObjectByIdentifier($hash, 'TYPO3\\Flow\\Resource\\ResourcePointer');
if ($resourcePointer) {
$resource = new Resource();
$resource->setFilename($source['filename']);
$resource->setResourcePointer($resourcePointer);
}
}
if ($resource === NULL) {
if (isset($source['data'])) {
$resource = $this->resourceManager->createResourceFromContent($source['data'], $source['filename']);
} elseif ($hash !== NULL) {
$resource = $this->resourceManager->importResource($configuration->getConfigurationValue('TYPO3\\Flow\\Resource\\ResourceTypeConverter', self::CONFIGURATION_RESOURCE_LOAD_PATH) . '/' . $hash);
if (is_array($source) && isset($source['filename'])) {
$resource->setFilename($source['filename']);
}
}
}
if ($resource instanceof \TYPO3\Flow\Resource\Resource) {
if ($givenResourceIdentity !== NULL) {
$this->setIdentity($resource, $givenResourceIdentity);
}
return $resource;
} else {
return new Error('The resource manager could not create a Resource instance.', 1404312901);
}
}
示例14: handleHashAndData
/**
* @param array $source
* @param PropertyMappingConfigurationInterface $configuration
* @return Resource|Error
* @throws Exception
* @throws InvalidPropertyMappingConfigurationException
*/
protected function handleHashAndData(array $source, PropertyMappingConfigurationInterface $configuration = null)
{
$hash = null;
$resource = false;
$givenResourceIdentity = null;
if (isset($source['__identity'])) {
$givenResourceIdentity = $source['__identity'];
unset($source['__identity']);
$resource = $this->resourceRepository->findByIdentifier($givenResourceIdentity);
if ($resource instanceof Resource) {
return $resource;
}
if ($configuration->getConfigurationValue(\TYPO3\Flow\Resource\ResourceTypeConverter::class, self::CONFIGURATION_IDENTITY_CREATION_ALLOWED) !== true) {
throw new InvalidPropertyMappingConfigurationException('Creation of resource objects with identity not allowed. To enable this, you need to set the PropertyMappingConfiguration Value "CONFIGURATION_IDENTITY_CREATION_ALLOWED" to TRUE');
}
}
if (isset($source['hash']) && preg_match('/[0-9a-f]{40}/', $source['hash'])) {
$hash = $source['hash'];
}
if ($hash !== null && count($source) === 1) {
$resource = $this->resourceManager->getResourceBySha1($hash);
}
if ($resource === null) {
$collectionName = $this->getCollectionName($source, $configuration);
if (isset($source['data'])) {
$resource = $this->resourceManager->importResourceFromContent($source['data'], $source['filename'], $collectionName, $givenResourceIdentity);
} elseif ($hash !== null) {
$resource = $this->resourceManager->importResource($configuration->getConfigurationValue(\TYPO3\Flow\Resource\ResourceTypeConverter::class, self::CONFIGURATION_RESOURCE_LOAD_PATH) . '/' . $hash, $collectionName, $givenResourceIdentity);
if (is_array($source) && isset($source['filename'])) {
$resource->setFilename($source['filename']);
}
}
}
if ($resource instanceof Resource) {
return $resource;
} else {
return new Error('The resource manager could not create a Resource instance.', 1404312901);
}
}
示例15: indexAction
//.........这里部分代码省略.........
//@TODO report error
return;
}
if (isset($json->error)) {
$this->systemLogger->log('JSON error: ' . $json->error->message, LOG_DEBUG);
//@TODO report error $json->error->message;
return;
}
$postNumber = 0;
for ($i = 0; $i < count($json->data); ++$i) {
$post = $json->data[$i];
$story = isset($post->story) ? $post->story : null;
$message = isset($post->message) ? $post->message : $story;
if (!empty($fb['ignore']) && preg_match($fb['ignore'], $message)) {
continue;
}
if ($postNumber < $requestedPostNumber) {
++$postNumber;
continue;
}
$actions = array();
if (isset($post->actions)) {
foreach ($post->actions as $action) {
//@TODO use neos l18n
$action->label = $l18n[$action->name];
}
$actions = array_merge($actions, array_filter($post->actions, function ($v) use($fb) {
return in_array(strtolower($v->name), $fb['links']);
}));
}
if (in_array('more', $fb['links'])) {
$actions = array_merge($actions, array(array('label' => 'Mehr', 'name' => 'more', 'link' => 'https://facebook.com/' . $fb['pageid'])));
}
if (count($actions) > 0) {
$this->view->assign('actions', $actions);
}
if (isset($post->likes)) {
$concat = '';
for ($i = 0; $i < count($post->likes->data) && $i < 3; ++$i) {
$concat .= $post->likes->data[$i]->name . ', ';
}
$concat = rtrim($concat, ', ');
$more_concat = '';
for ($i = 3; $i < count($post->likes->data); ++$i) {
$more_concat .= $post->likes->data[$i]->name . ', ';
}
$more_concat = rtrim($more_concat, ', ');
$this->view->assign('likes_count', count($post->likes->data));
$this->view->assign('likes_first_concat', $concat);
$this->view->assign('likes_more_count', count($post->likes->data) - 3);
$this->view->assign('likes_more_concat', $more_concat);
$this->view->assign('likes', $post->likes->data);
}
if (isset($post->link)) {
$this->view->assign('link', $post->link);
}
// (https?:\/\/([-\w\.]+)+(\/[\w\/_\.%\-,=#?]*[\w\/%\-,=#?])?\/?)
// $this->view->assign('story', $story);
$this->view->assign('message', $message);
$this->view->assign('created_time', $post->created_time);
$attachmentUrl = 'https://graph.facebook.com/v2.4/' . $post->id . '/attachments?';
$attachmentUrl .= http_build_query(array('access_token' => $fb['token']));
$attachmentResponse = file_get_contents($attachmentUrl);
$attachmentJson = json_decode($attachmentResponse);
if (isset($attachmentJson) && $attachmentJson !== null) {
if (isset($attachmentJson->data)) {
$images = array();
$attachments = isset($attachmentJson->data[0]->subattachments) ? $attachmentJson->data[0]->subattachments->data : $attachmentJson->data;
for ($j = 0; $j < count($attachments); ++$j) {
if ($attachments[$j]->type !== 'photo') {
continue;
}
if (!isset($attachments[$j]->media->image)) {
continue;
}
$src = $attachments[$j]->media->image->src;
$sha1 = sha1_file($src);
//$resource = $this->resourceManager->getResourceBySha1($sha1);
$image = $this->assetRepository->findOneByResourceSha1($sha1);
if ($image === null) {
$resource = $this->resourceManager->importResource($src);
$image = new \TYPO3\Media\Domain\Model\Image($resource);
} else {
//$this->systemLogger->log('Image found', LOG_DEBUG);
}
// Allow image to be persisted even if this is a "safe" HTTP request:
$this->persistenceManager->whiteListObject($image);
$this->persistenceManager->whiteListObject($image->getResource());
$images[] = $image;
}
$this->view->assign('images', $images);
} elseif (isset($attachmentJson->error)) {
//@TODO report error $attachmentJson->error->message;
}
}
if ($postNumber === $requestedPostNumber) {
break;
}
}
}