Skip to content

Commit

Permalink
Merge pull request #20 from flownative/feature/multiple-tenants
Browse files Browse the repository at this point in the history
Support for multiple tenants
  • Loading branch information
kdambekalns authored Jan 24, 2025
2 parents 861c1ce + 355c2ae commit b0ff958
Show file tree
Hide file tree
Showing 24 changed files with 576 additions and 831 deletions.
142 changes: 22 additions & 120 deletions Classes/AssetSource/PixxioAssetProxy.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace Flownative\Pixxio\AssetSource;

Expand Down Expand Up @@ -35,92 +36,47 @@
*/
final class PixxioAssetProxy implements AssetProxyInterface, HasRemoteOriginalInterface, SupportsIptcMetadataInterface
{
/**
* @var PixxioAssetSource
*/
private $assetSource;
private PixxioAssetSource $assetSource;

/**
* @var string
*/
private $identifier;
private string $identifier;

/**
* @var string
*/
private $label;
private string $label;

/**
* @var string
*/
private $filename;
private string $filename;

/**
* @var \DateTime
*/
private $lastModified;
private \DateTime $lastModified;

/**
* @var int
*/
private $fileSize;
private int $fileSize;

/**
* @var string
*/
private $mediaType;
private string $mediaType;

/**
* @var array
*/
private $iptcProperties = [];
private array $iptcProperties = [];

/**
* @var UriInterface
*/
private $thumbnailUri;
private UriInterface $thumbnailUri;

/**
* @var UriInterface
*/
private $previewUri;
private UriInterface $previewUri;

/**
* @var UriInterface
*/
private $originalUri;
private UriInterface $originalUri;

/**
* @var int
*/
private $widthInPixels;
private ?int $widthInPixels;

/**
* @var int
*/
private $heightInPixels;
private ?int $heightInPixels;

/**
* @var array
*/
private $tags = [];
private array $tags = [];

/**
* @Flow\Inject
* @var ImportedAssetRepository
*/
protected $importedAssetRepository;
protected ImportedAssetRepository $importedAssetRepository;

/**
* @param stdClass $jsonObject
* @param PixxioAssetSource $assetSource
* @return static
* @throws Exception
*/
public static function fromJsonObject(stdClass $jsonObject, PixxioAssetSource $assetSource): PixxioAssetProxy
{
$assetSourceOptions = $assetSource->getAssetSourceOptions();
$pixxioOriginalMediaType = MediaTypes::getMediaTypeFromFilename('foo.' . strtolower($jsonObject->fileType));;
$pixxioOriginalMediaType = MediaTypes::getMediaTypeFromFilename('foo.' . strtolower($jsonObject->fileType));
$usePixxioThumbnailAsOriginal = (!isset($assetSourceOptions['mediaTypes'][$pixxioOriginalMediaType]) || $assetSourceOptions['mediaTypes'][$pixxioOriginalMediaType]['usePixxioThumbnailAsOriginal'] === false);
$modifiedFileType = $usePixxioThumbnailAsOriginal ? 'jpg' : strtolower($jsonObject->fileType);

Expand All @@ -130,16 +86,16 @@ public static function fromJsonObject(stdClass $jsonObject, PixxioAssetSource $a
$assetProxy->label = $jsonObject->subject;
$assetProxy->filename = Transliterator::urlize($jsonObject->subject) . '.' . $modifiedFileType;
$assetProxy->lastModified = new \DateTime($jsonObject->modifyDate ?? '1.1.2000');
$assetProxy->fileSize = $jsonObject->fileSize;
$assetProxy->fileSize = (int)$jsonObject->fileSize;
$assetProxy->mediaType = MediaTypes::getMediaTypeFromFilename('foo.' . $modifiedFileType);
$assetProxy->tags = isset($jsonObject->keywords) ? explode(',', $jsonObject->keywords) : [];

$assetProxy->iptcProperties['Title'] = $jsonObject->subject ?? '';
$assetProxy->iptcProperties['CaptionAbstract'] = $jsonObject->description ?? '';
$assetProxy->iptcProperties['CopyrightNotice'] = $jsonObject->dynamicMetadata->CopyrightNotice ?? '';

$assetProxy->widthInPixels = $jsonObject->imageWidth ?? null;
$assetProxy->heightInPixels = $jsonObject->imageHeight ?? null;
$assetProxy->widthInPixels = $jsonObject->imageWidth ? (int)$jsonObject->imageWidth : null;
$assetProxy->heightInPixels = $jsonObject->imageHeight ? (int)$jsonObject->imageHeight : null;

if (isset($jsonObject->modifiedImagePaths)) {
$modifiedImagePaths = $jsonObject->modifiedImagePaths;
Expand Down Expand Up @@ -171,122 +127,77 @@ public static function fromJsonObject(stdClass $jsonObject, PixxioAssetSource $a
return $assetProxy;
}

/**
* @return AssetSourceInterface
*/
public function getAssetSource(): AssetSourceInterface
{
return $this->assetSource;
}

/**
* @return string
*/
public function getIdentifier(): string
{
return $this->identifier;
}

/**
* @return string
*/
public function getLabel(): string
{
return $this->label;
}

/**
* @return string
*/
public function getFilename(): string
{
return $this->filename;
}

/**
* @return \DateTimeInterface
*/
public function getLastModified(): \DateTimeInterface
{
return $this->lastModified;
}

/**
* @return int
*/
public function getFileSize(): int
{
return $this->fileSize;
}

/**
* @return string
*/
public function getMediaType(): string
{
return $this->mediaType;
}

/**
* @param string $propertyName
* @return bool
*/
public function hasIptcProperty(string $propertyName): bool
{
return isset($this->iptcProperties[$propertyName]);
}

/**
* @param string $propertyName
* @return string
*/
public function getIptcProperty(string $propertyName): string
{
return $this->iptcProperties[$propertyName] ?? '';
}

/**
* @return array
*/
public function getIptcProperties(): array
{
return $this->iptcProperties;
}

/**
* @return int|null
*/
public function getWidthInPixels(): ?int
{
return $this->widthInPixels;
}

/**
* @return int|null
*/
public function getHeightInPixels(): ?int
{
return $this->heightInPixels;
}

/**
* @return UriInterface
*/
public function getThumbnailUri(): ?UriInterface
{
return $this->thumbnailUri;
}

/**
* @return UriInterface
*/
public function getPreviewUri(): ?UriInterface
{
return $this->previewUri;
}

/**
* @return bool|resource
* @throws ConnectionException
*/
public function getImportStream()
Expand All @@ -299,31 +210,22 @@ public function getImportStream()
}

return false;
} catch (GuzzleException $e) {
throw new ConnectionException('Retrieving file failed: ' . $e->getMessage(), 1542808207, $e);
} catch (GuzzleException $exception) {
throw new ConnectionException('Retrieving file failed: ' . $exception->getMessage(), 1542808207, $exception);
}
}

/**
* @return string
*/
public function getLocalAssetIdentifier(): ?string
{
$importedAsset = $this->importedAssetRepository->findOneByAssetSourceIdentifierAndRemoteAssetIdentifier($this->assetSource->getIdentifier(), $this->identifier);
return ($importedAsset instanceof ImportedAsset ? $importedAsset->getLocalAssetIdentifier() : null);
}

/**
* @return array
*/
public function getTags(): array
{
return $this->tags;
}

/**
* @return bool
*/
public function isImported(): bool
{
return true;
Expand Down
Loading

0 comments on commit b0ff958

Please sign in to comment.