Skip to content

Commit

Permalink
Refactor Dtos
Browse files Browse the repository at this point in the history
  • Loading branch information
mattamon committed Mar 11, 2024
1 parent 467fd66 commit 3fcafdb
Show file tree
Hide file tree
Showing 15 changed files with 60 additions and 190 deletions.
2 changes: 1 addition & 1 deletion src/Dto/Asset/Archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@

use Pimcore\Bundle\StudioApiBundle\Dto\Asset;

class Archive extends Asset
final class Archive extends Asset
{
}
2 changes: 1 addition & 1 deletion src/Dto/Asset/Audio.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@

use Pimcore\Bundle\StudioApiBundle\Dto\Asset;

class Audio extends Asset
final class Audio extends Asset
{
}
57 changes: 13 additions & 44 deletions src/Dto/Asset/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,61 +18,30 @@

use Pimcore\Bundle\StudioApiBundle\Dto\Asset;

class Document extends Asset
final class Document extends Asset
{
//use MetaData\EmbeddedMetaDataTrait;
private ?int $pageCount = null;

public function __construct(
private readonly ?int $pageCount,
private readonly ?string $imageThumbnailPath,
string $iconName,
bool $hasChildren,
string $type,
string $filename,
string $mimeType,
array $metaData,
bool $workflowWithPermissions,
string $fullPath,
int $id,
int $parentId,
string $path,
int $userOwner,
int $userModification,
?string $locked,
bool $isLocked,
?int $creationDate,
?int $modificationDate,
Permissions $permissions
) {
parent::__construct(
$iconName,
$hasChildren,
$type,
$filename,
$mimeType,
$metaData,
$workflowWithPermissions,
$fullPath,
$id,
$parentId,
$path,
$userOwner,
$userModification,
$locked,
$isLocked,
$creationDate,
$modificationDate,
$permissions
);
}
private ?string $imageThumbnailPath = null;

public function getPageCount(): ?int
{
return $this->pageCount;
}

public function setPageCount(?int $pageCount): void
{
$this->pageCount = $pageCount;
}

public function getImageThumbnailPath(): ?string
{
return $this->imageThumbnailPath;
}

public function setImageThumbnailPath(?string $imageThumbnailPath): void
{
$this->imageThumbnailPath = $imageThumbnailPath;
}
}
2 changes: 1 addition & 1 deletion src/Dto/Asset/Folder.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@

use Pimcore\Bundle\StudioApiBundle\Dto\Asset;

class Folder extends Asset
final class Folder extends Asset
{
}
2 changes: 1 addition & 1 deletion src/Dto/Asset/MetaData.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace Pimcore\Bundle\StudioApiBundle\Dto\Asset;

readonly class MetaData
final readonly class MetaData
{
public function __construct(
private string $name,
Expand Down
2 changes: 1 addition & 1 deletion src/Dto/Asset/Permissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace Pimcore\Bundle\StudioApiBundle\Dto\Asset;

readonly class Permissions
final readonly class Permissions
{
//TODO: remove or change default permissions
public function __construct(
Expand Down
2 changes: 1 addition & 1 deletion src/Dto/Asset/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@

use Pimcore\Bundle\StudioApiBundle\Dto\Asset;

class Text extends Asset
final class Text extends Asset
{
}
2 changes: 1 addition & 1 deletion src/Dto/Asset/Unknown.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@

use Pimcore\Bundle\StudioApiBundle\Dto\Asset;

class Unknown extends Asset
final class Unknown extends Asset
{
}
72 changes: 25 additions & 47 deletions src/Dto/Asset/Video.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,73 +18,51 @@

use Pimcore\Bundle\StudioApiBundle\Dto\Asset;

class Video extends Asset
final class Video extends Asset
{
//use MetaData\EmbeddedMetaDataTrait;

public function __construct(
private readonly ?float $duration,
private readonly ?int $width,
private readonly ?int $height,
private readonly?string $imageThumbnailPath,
string $iconName,
bool $hasChildren,
string $type,
string $filename,
string $mimeType,
array $metaData,
bool $workflowWithPermissions,
string $fullPath,
int $id,
int $parentId,
string $path,
int $userOwner,
int $userModification,
?string $locked,
bool $isLocked,
?int $creationDate,
?int $modificationDate,
Permissions $permissions
) {
parent::__construct(
$iconName,
$hasChildren,
$type,
$filename,
$mimeType,
$metaData,
$workflowWithPermissions,
$fullPath,
$id,
$parentId,
$path,
$userOwner,
$userModification,
$locked,
$isLocked,
$creationDate,
$modificationDate,
$permissions
);
}
private ?float $duration;
private ?int $width;
private ?int $height;
private ?string $imageThumbnailPath;

public function getDuration(): ?float
{
return $this->duration;
}

public function setDuration(?float $duration): void
{
$this->duration = $duration;
}

public function getWidth(): ?int
{
return $this->width;
}

public function setWidth(?int $width): void
{
$this->width = $width;
}

public function getHeight(): ?int
{
return $this->height;
}

public function setHeight(?int $height): void
{
$this->height = $height;
}

public function getImageThumbnailPath(): ?string
{
return $this->imageThumbnailPath;
}

public function setImageThumbnailPath(?string $imageThumbnailPath): void
{
$this->imageThumbnailPath = $imageThumbnailPath;
}
}
20 changes: 2 additions & 18 deletions src/Service/GenericData/V1/Hydrator/Asset/ArchiveHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,8 @@ public function __construct(
public function hydrate(ArchiveItem $item): Archive
{
return new Archive(
$this->iconService->getIconForAsset($item->getType(), $item->getMimeType()),
$item->isHasChildren(),
$item->getType(),
$item->getKey(),
$item->getMimeType(),
$this->metaDataHydrator->hydrate($item->getMetaData()),
$item->isHasWorkflowWithPermissions(),
$item->getFullPath(),
$item->getId(),
$item->getParentId(),
$item->getPath(),
$item->getUserOwner(),
$item->getUserModification(),
$item->getLocked(),
$item->isLocked(),
$item->getCreationDate(),
$item->getModificationDate(),
$this->permissionsHydrator->hydrate($item->getPermissions())
$item->getId()
);
// TODO: Implement hydrate() method.
}
}
20 changes: 2 additions & 18 deletions src/Service/GenericData/V1/Hydrator/Asset/AudioHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,8 @@ public function __construct(
public function hydrate(AudioItem $item): Audio
{
return new Audio(
$this->iconService->getIconForAsset($item->getType(), $item->getMimeType()),
$item->isHasChildren(),
$item->getType(),
$item->getKey(),
$item->getMimeType(),
$this->metaDataHydrator->hydrate($item->getMetaData()),
$item->isHasWorkflowWithPermissions(),
$item->getFullPath(),
$item->getId(),
$item->getParentId(),
$item->getPath(),
$item->getUserOwner(),
$item->getUserModification(),
$item->getLocked(),
$item->isLocked(),
$item->getCreationDate(),
$item->getModificationDate(),
$this->permissionsHydrator->hydrate($item->getPermissions())
$item->getId()
);
// TODO: Implement hydrate() method.
}
}
20 changes: 2 additions & 18 deletions src/Service/GenericData/V1/Hydrator/Asset/FolderHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,8 @@ public function __construct(
public function hydrate(FolderItem $item): Folder
{
return new Folder(
$this->iconService->getIconForAsset($item->getType(), $item->getMimeType()),
$item->isHasChildren(),
$item->getType(),
$item->getKey(),
$item->getMimeType(),
$this->metaDataHydrator->hydrate($item->getMetaData()),
$item->isHasWorkflowWithPermissions(),
$item->getFullPath(),
$item->getId(),
$item->getParentId(),
$item->getPath(),
$item->getUserOwner(),
$item->getUserModification(),
$item->getLocked(),
$item->isLocked(),
$item->getCreationDate(),
$item->getModificationDate(),
$this->permissionsHydrator->hydrate($item->getPermissions())
$item->getId()
);
// TODO Implement hydrate() method.
}
}
21 changes: 3 additions & 18 deletions src/Service/GenericData/V1/Hydrator/Asset/TextHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,9 @@ public function __construct(
public function hydrate(TextItem $item): Text
{
return new Text(
$this->iconService->getIconForAsset($item->getType(), $item->getMimeType()),
$item->isHasChildren(),
$item->getType(),
$item->getKey(),
$item->getMimeType(),
$this->metaDataHydrator->hydrate($item->getMetaData()),
$item->isHasWorkflowWithPermissions(),
$item->getFullPath(),
$item->getId(),
$item->getParentId(),
$item->getPath(),
$item->getUserOwner(),
$item->getUserModification(),
$item->getLocked(),
$item->isLocked(),
$item->getCreationDate(),
$item->getModificationDate(),
$this->permissionsHydrator->hydrate($item->getPermissions())
$item->getId()
);

// TODO: Implement hydrate() method.
}
}
21 changes: 3 additions & 18 deletions src/Service/GenericData/V1/Hydrator/Asset/UnknownHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,9 @@ public function __construct(
public function hydrate(UnknownItem $item): Unknown
{
return new Unknown(
$this->iconService->getIconForAsset($item->getType(), $item->getMimeType()),
$item->isHasChildren(),
$item->getType(),
$item->getKey(),
$item->getMimeType(),
$this->metaDataHydrator->hydrate($item->getMetaData()),
$item->isHasWorkflowWithPermissions(),
$item->getFullPath(),
$item->getId(),
$item->getParentId(),
$item->getPath(),
$item->getUserOwner(),
$item->getUserModification(),
$item->getLocked(),
$item->isLocked(),
$item->getCreationDate(),
$item->getModificationDate(),
$this->permissionsHydrator->hydrate($item->getPermissions())
$item->getId()
);

// TODO: Implement hydrate() method.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@
use Pimcore\Bundle\StudioApiBundle\Dto\Asset\Text;
use Pimcore\Bundle\StudioApiBundle\Dto\Asset\Unknown;
use Pimcore\Bundle\StudioApiBundle\Dto\Asset\Video;
use Pimcore\Model\Asset as ModelAsset;

interface AssetHydratorServiceInterface
{
/**
* @param \Pimcore\Model\Asset
* @param ModelAsset $item
*
* @return Asset|Archive|Audio|Document|Folder|Image|Text|Unknown|Video
*/
public function hydrate(\Pimcore\Model\Asset $item): Asset|Archive|Audio|Document|Folder|Image|Text|Unknown|Video;
public function hydrate(ModelAsset $item): Asset|Archive|Audio|Document|Folder|Image|Text|Unknown|Video;
}

0 comments on commit 3fcafdb

Please sign in to comment.