作者:neo
项目:ImageProcessingTes
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);
}
作者:kszym
项目:flow-development-collectio
/**
* @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));
}
作者:sokunthearit
项目:Intern-Project-Week-
/**
* @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);
}
作者:sokunthearit
项目:Intern-Project-Week-
/**
* @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);
}
作者:cerleste
项目:flow-development-collectio
/**
* @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);
}
作者:sandstor
项目:newslette
public function inlineStyles($html)
{
//return $html;
// TODO: the following won't work with Cloud Publishing...
$staticResourceBaseUri = $this->resourceManager->getCollection(ResourceManager::DEFAULT_STATIC_COLLECTION_NAME)->getTarget()->getPublicStaticResourceUri('');
$stylesheetLinks = array();
$html = preg_replace_callback(self::STYLE_LINK_TAG_REGEX, function ($match) use(&$stylesheetLinks, $staticResourceBaseUri) {
$stylesheetLink = $match[1];
$stylesheetLinks[] = FLOW_PATH_WEB . substr($stylesheetLink, strpos($staticResourceBaseUri, '_Resources'));
return '';
}, $html);
$finalCss = '';
foreach ($stylesheetLinks as $stylesheetLink) {
$finalCss .= "\n{$stylesheetLink}\n" . file_get_contents($stylesheetLink) . "\n\n";
}
$cssToInlineStyleConverter = new CssToInlineStyles($html, $finalCss);
return $cssToInlineStyleConverter->convert();
}
作者:robertlemk
项目:flow-development-collectio
/**
* Get the collection name this resource will be stored in. Default will be ResourceManager::DEFAULT_PERSISTENT_COLLECTION_NAME
* The propertyMappingConfiguration CONFIGURATION_COLLECTION_NAME will directly override the default. Then if CONFIGURATION_ALLOW_COLLECTION_OVERRIDE is TRUE
* and __collectionName is in the $source this will finally be the value.
*
* @param array $source
* @param PropertyMappingConfigurationInterface $configuration
* @return string
* @throws InvalidPropertyMappingConfigurationException
*/
protected function getCollectionName($source, PropertyMappingConfigurationInterface $configuration = null)
{
if ($configuration === null) {
return ResourceManager::DEFAULT_PERSISTENT_COLLECTION_NAME;
}
$collectionName = $configuration->getConfigurationValue(\TYPO3\Flow\Resource\ResourceTypeConverter::class, self::CONFIGURATION_COLLECTION_NAME) ?: ResourceManager::DEFAULT_PERSISTENT_COLLECTION_NAME;
if (isset($source['__collectionName']) && $source['__collectionName'] !== '') {
$collectionName = $source['__collectionName'];
}
if ($this->resourceManager->getCollection($collectionName) === null) {
throw new InvalidPropertyMappingConfigurationException(sprintf('The selected resource collection named "%s" does not exist, a resource could not be imported.', $collectionName), 1416687475);
}
return $collectionName;
}
作者:sakona99
项目:flow-logi
/**
* 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);
}
}
作者:cerleste
项目:flow-development-collectio
/**
* 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;
}
作者:neo
项目:metadata-extracto
/**
* @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;
}
作者:mgoldbec
项目:neos-development-collectio
/**
* @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;
}
作者:netlogi
项目:medi
/**
* 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()))));
}
作者:hlube
项目:neos-development-collectio
/**
* @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));
}
作者:sbruggman
项目:neos-development-collectio
/**
* 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();
}
作者:robertlemk
项目:neos-development-collectio
/**
* @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;
}
作者:phluzer
项目:sites.phlu.c
/**
* 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);
}
作者:sokunthearit
项目:Intern-Project-Week-
/**
* 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;
}
作者:kraft
项目:ThinkopenAt.TimeFlie
/**
* 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;
}
作者:mkuiphui
项目:flow-aws-s
/**
* Retrieve all Objects stored in this storage.
*
* @return array<\TYPO3\Flow\Resource\Storage\Object>
* @api
*/
public function getObjects()
{
$objects = array();
foreach ($this->resourceManager->getCollectionsByStorage($this) as $collection) {
$objects = array_merge($objects, $this->getObjectsByCollection($collection));
}
return $objects;
}
作者:psm
项目:KateheoDist
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);
}