本文整理汇总了PHP中TYPO3\Flow\Resource\ResourceManager类的典型用法代码示例。如果您正苦于以下问题:PHP ResourceManager类的具体用法?PHP ResourceManager怎么用?PHP ResourceManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ResourceManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
示例2: openResolvesAnUpperCaseSha1HashUsingTheResourceManager
/**
* @test
*/
public function openResolvesAnUpperCaseSha1HashUsingTheResourceManager()
{
$sha1Hash = '68AC906495480A3404BEEE4874ED853A037A7A8F';
$tempFile = tmpfile();
$mockResource = $this->getMockBuilder(Resource::class)->disableOriginalConstructor()->getMock();
$this->mockResourceManager->expects($this->once())->method('getResourceBySha1')->with($sha1Hash)->will($this->returnValue($mockResource));
$this->mockResourceManager->expects($this->once())->method('getStreamByResource')->with($mockResource)->will($this->returnValue($tempFile));
$openedPathAndFilename = '';
$this->assertSame($tempFile, $this->resourceStreamWrapper->open('resource://' . $sha1Hash, 'r', 0, $openedPathAndFilename));
}
示例3: openResolvesAnUpperCaseSha1HashUsingTheResourceManager
/**
* @test
*/
public function openResolvesAnUpperCaseSha1HashUsingTheResourceManager()
{
$sha1Hash = '68AC906495480A3404BEEE4874ED853A037A7A8F';
$persistentResourcesStorageBaseUri = 'vfs://Foo/Some/';
$absoluteResourcePath = $persistentResourcesStorageBaseUri . $sha1Hash;
mkdir($persistentResourcesStorageBaseUri);
file_put_contents('vfs://Foo/Some/' . $sha1Hash, 'fixture');
$this->mockResourceManager->expects($this->once())->method('getPersistentResourcesStorageBaseUri')->will($this->returnValue($persistentResourcesStorageBaseUri));
$openedPathAndFilename = '';
$this->assertTrue($this->resourceStreamWrapper->open('resource://' . $sha1Hash, 'r', 0, $openedPathAndFilename));
$this->assertSame($absoluteResourcePath, $openedPathAndFilename);
}
示例4: convertFromReturnsAnErrorIfTheUploadedFileCantBeImported
/**
* @test
*/
public function convertFromReturnsAnErrorIfTheUploadedFileCantBeImported()
{
$source = array('tmp_name' => 'SomeFilename', 'error' => \UPLOAD_ERR_OK);
$this->mockResourceManager->expects($this->once())->method('importUploadedResource')->with($source)->will($this->returnValue(FALSE));
$actualResult = $this->resourceTypeConverter->convertFrom($source, 'TYPO3\\Flow\\Resource\\Resource');
$this->assertInstanceOf('TYPO3\\Flow\\Error\\Error', $actualResult);
}
示例5: convertFromReturnsAnErrorIfTheUploadedFileCantBeImported
/**
* @test
*/
public function convertFromReturnsAnErrorIfTheUploadedFileCantBeImported()
{
$this->inject($this->resourceTypeConverter, 'systemLogger', $this->createMock(\TYPO3\Flow\Log\SystemLoggerInterface::class));
$source = array('tmp_name' => 'SomeFilename', 'error' => \UPLOAD_ERR_OK);
$this->mockResourceManager->expects($this->once())->method('importUploadedResource')->with($source)->will($this->throwException(new \TYPO3\Flow\Resource\Exception()));
$actualResult = $this->resourceTypeConverter->convertFrom($source, \TYPO3\Flow\Resource\Resource::class);
$this->assertInstanceOf(\TYPO3\Flow\Error\Error::class, $actualResult);
}
示例6: publishCommand
/**
* Publish resources
*
* This command publishes the resources of the given or - if none was specified, all - resource collections
* to their respective configured publishing targets.
*
* @param string $collection If specified, only resources of this collection are published. Example: 'persistent'
* @return void
*/
public function publishCommand($collection = NULL)
{
try {
if ($collection === NULL) {
$collections = $this->resourceManager->getCollections();
} else {
$collections = array();
$collections[$collection] = $this->resourceManager->getCollection($collection);
if ($collections[$collection] === NULL) {
$this->outputLine('Collection "%s" does not exist.', array($collection));
$this->quit(1);
}
}
foreach ($collections as $collection) {
/** @var CollectionInterface $collection */
$this->outputLine('Publishing resources of collection "%s"', array($collection->getName()));
$collection->publish();
}
} catch (Exception $exception) {
$this->outputLine();
$this->outputLine('An error occurred while publishing resources (see full description below). You can check and probably fix the integrity of the resource registry by using the resource:clean command.');
$this->outputLine('%s (Exception code: %s)', array(get_class($exception), $exception->getCode()));
$this->outputLine($exception->getMessage());
$this->quit(1);
}
}
示例7: render
/**
* Render the URI to the resource. The filename is used from child content.
*
* @param string $path The location of the resource, can be either a path relative to the Public resource directory of the package or a resource://... URI
* @param string $package Target package key. If not set, the current package key will be used
* @param Resource $resource If specified, this resource object is used instead of the path and package information
* @param boolean $localize Whether resource localization should be attempted or not
* @return string The absolute URI to the resource
* @throws InvalidVariableException
* @api
*/
public function render($path = null, $package = null, Resource $resource = null, $localize = true)
{
if ($resource !== null) {
$uri = $this->resourceManager->getPublicPersistentResourceUri($resource);
if ($uri === false) {
$uri = '404-Resource-Not-Found';
}
} else {
if ($path === null) {
throw new InvalidVariableException('The ResourceViewHelper did neither contain a valuable "resource" nor "path" argument.', 1353512742);
}
if ($package === null) {
$package = $this->controllerContext->getRequest()->getControllerPackageKey();
}
if (strpos($path, 'resource://') === 0) {
try {
list($package, $path) = $this->resourceManager->getPackageAndPathByPublicPath($path);
} catch (Exception $exception) {
throw new InvalidVariableException(sprintf('The specified path "%s" does not point to a public resource.', $path), 1386458851);
}
}
if ($localize === true) {
$resourcePath = 'resource://' . $package . '/Public/' . $path;
$localizedResourcePathData = $this->i18nService->getLocalizedFilename($resourcePath);
$matches = array();
if (preg_match('#resource://([^/]+)/Public/(.*)#', current($localizedResourcePathData), $matches) === 1) {
$package = $matches[1];
$path = $matches[2];
}
}
$uri = $this->resourceManager->getPublicPackageResourceUri($package, $path);
}
return $uri;
}
示例8: 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;
}
示例9: 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;
}
示例10: uploadAction
/**
* Upload a new image and return an image variant, a thumbnail and additional information like it would be
* returned for the Neos backend.
*
* @param Image $image
* @return string
*/
public function uploadAction(Image $image)
{
$this->assetRepository->add($image);
$imageVariant = new ImageVariant($image);
$this->assetRepository->add($imageVariant);
$thumbnail = $image->getThumbnail(100, 100);
$this->response->setHeader('Content-Type', 'application/json');
return json_encode(array('__identity' => $this->persistenceManager->getIdentifierByObject($image), '__resourceUri' => $this->resourceManager->getPublicPersistentResourceUri($image->getResource()), 'width' => $image->getWidth(), 'height' => $image->getHeight(), 'thumbnail' => array('__resourceUri' => $this->resourceManager->getPublicPersistentResourceUri($thumbnail->getResource()), 'width' => $thumbnail->getWidth(), 'height' => $thumbnail->getHeight()), 'variants' => array(array('__identity' => $this->persistenceManager->getIdentifierByObject($imageVariant), '__resourceUri' => $this->resourceManager->getPublicPersistentResourceUri($imageVariant->getResource()), 'width' => $imageVariant->getWidth(), 'height' => $imageVariant->getHeight()))));
}
示例11: getAssetThumbnailImage
/**
* @param AssetInterface $asset
* @param integer $maximumWidth
* @param integer $maximumHeight
* @return array
*/
protected function getAssetThumbnailImage(AssetInterface $asset, $maximumWidth, $maximumHeight)
{
// TODO: Could be configurable at some point
$iconPackage = 'TYPO3.Media';
$iconSize = $this->getDocumentIconSize($maximumWidth, $maximumHeight);
if (is_file('resource://' . $iconPackage . '/Public/Icons/16px/' . $asset->getResource()->getFileExtension() . '.png')) {
$icon = sprintf('Icons/%spx/' . $asset->getResource()->getFileExtension() . '.png', $iconSize);
} else {
$icon = sprintf('Icons/%spx/_blank.png', $iconSize);
}
return array('width' => $iconSize, 'height' => $iconSize, 'src' => $this->resourceManager->getPublicPackageResourceUri($iconPackage, $icon));
}
示例12: render
/**
* Renders an <img> HTML tag for a filetype icon for a given TYPO3.Media's asset instance
*
* @param AssetInterface $file
* @param integer|null $width
* @param integer|null $height
* @return string
*/
public function render(AssetInterface $file, $width = null, $height = null)
{
$icon = FileTypeIconService::getIcon($file, $width, $height);
$this->tag->addAttribute('src', $this->resourceManager->getPublicPackageResourceUriByPath($icon['src']));
$this->tag->addAttribute('alt', $icon['alt']);
if ($width !== null) {
$this->tag->addAttribute('width', $width);
}
if ($height !== null) {
$this->tag->addAttribute('height', $height);
}
return $this->tag->render();
}
示例13: buildAssetObject
/**
* @return Asset
* @throws \TYPO3\Flow\Resource\Exception
*/
protected function buildAssetObject()
{
$resource = $this->resourceManager->importResourceFromContent('Test', 'test.txt');
$asset = new Asset($resource);
$this->assetRepository->add($asset);
return $asset;
}
示例14: 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);
}
示例15: evaluateResourcePath
/**
* Evaluates the absolute path and filename of the resource file specified
* by the given path.
*
* @param string $requestedPath
* @param boolean $checkForExistence Whether a (non-hash) path should be checked for existence before being returned
* @return mixed The full path and filename or FALSE if the file doesn't exist
* @throws \TYPO3\Flow\Resource\Exception
* @throws \InvalidArgumentException
*/
protected function evaluateResourcePath($requestedPath, $checkForExistence = TRUE)
{
if (substr($requestedPath, 0, strlen(self::SCHEME)) !== self::SCHEME) {
throw new \InvalidArgumentException('The ' . __CLASS__ . ' only supports the \'' . self::SCHEME . '\' scheme.', 1256052544);
}
$uriParts = parse_url($requestedPath);
if (!is_array($uriParts) || !isset($uriParts['host'])) {
return FALSE;
}
if (preg_match('/^[0-9a-f]{40}$/i', $uriParts['host']) === 1) {
$resourcePath = $this->resourceManager->getPersistentResourcesStorageBaseUri() . $uriParts['host'];
if ($checkForExistence === FALSE || file_exists($resourcePath)) {
return $resourcePath;
} else {
return FALSE;
}
}
if (!$this->packageManager->isPackageAvailable($uriParts['host'])) {
throw new \TYPO3\Flow\Resource\Exception(sprintf('Invalid resource URI "%s": Package "%s" is not available.', $requestedPath, $uriParts['host']), 1309269952);
}
$package = $this->packageManager->getPackage($uriParts['host']);
$resourcePath = \TYPO3\Flow\Utility\Files::concatenatePaths(array($package->getResourcesPath(), $uriParts['path']));
if ($checkForExistence === FALSE || file_exists($resourcePath)) {
return $resourcePath;
}
return FALSE;
}