Skip to content

Commit

Permalink
[stacked 10] DTO more flexible on their creation process. (#2374)
Browse files Browse the repository at this point in the history
  • Loading branch information
ildyria authored Apr 11, 2024
1 parent f057211 commit 92909da
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 70 deletions.
6 changes: 3 additions & 3 deletions app/Actions/Photo/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function add(NativeLocalFile $sourceFile, ?AbstractAlbum $album, ?int $fi
*/
private function handleDuplicate(InitDTO $initDTO): Photo
{
$dto = new DuplicateDTO($initDTO);
$dto = DuplicateDTO::ofInit($initDTO);

$pipes = [];
if ($dto->shallResyncMetadata) {
Expand Down Expand Up @@ -138,7 +138,7 @@ private function handleDuplicate(InitDTO $initDTO): Photo

private function handleStandalone(InitDTO $initDTO): Photo
{
$dto = new StandaloneDTO($initDTO);
$dto = StandaloneDTO::ofInit($initDTO);

$pipes = [
Standalone\FixTimeStamps::class,
Expand Down Expand Up @@ -177,7 +177,7 @@ private function handleStandalone(InitDTO $initDTO): Photo

private function handleVideoLivePartner(InitDTO $initDTO): Photo
{
$dto = new VideoPartnerDTO($initDTO);
$dto = VideoPartnerDTO::ofInit($initDTO);

$pipes = [
VideoPartner\GetVideoPath::class,
Expand Down
47 changes: 25 additions & 22 deletions app/DTO/PhotoCreate/DuplicateDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,39 @@
*/
class DuplicateDTO implements PhotoDTO
{
public readonly bool $shallResyncMetadata;
public readonly bool $shallSkipDuplicates;

public bool $hasBeenReSynced;

// Indicates the intended owner of the image.
public readonly int $intendedOwnerId;
public function __construct(
public readonly bool $shallResyncMetadata,
public readonly bool $shallSkipDuplicates,
// Indicates the intended owner of the image.
public readonly int $intendedOwnerId,

// Indicates whether the new photo shall be starred.
public readonly bool $is_starred;
// Indicates whether the new photo shall be starred.
public readonly bool $is_starred,

// The extracted EXIF information (populated during init phase).
public readonly Extractor $exifInfo;
// The extracted EXIF information (populated during init phase).
public readonly Extractor $exifInfo,

// The intended parent album
public readonly ?AbstractAlbum $album;
// The intended parent album
public readonly ?AbstractAlbum $album,

// During initial steps if liveParner is found, it will be placed here.
public Photo $photo;
// During initial steps if duplicate is found, it will be placed here.
public Photo $photo,
) {
}

public function __construct(InitDTO $initDTO)
public static function ofInit(InitDTO $initDTO): DuplicateDTO
{
$this->shallResyncMetadata = $initDTO->importMode->shallResyncMetadata;
$this->shallSkipDuplicates = $initDTO->importMode->shallSkipDuplicates;

$this->photo = $initDTO->duplicate;
$this->exifInfo = $initDTO->exifInfo;
$this->album = $initDTO->album;
$this->is_starred = $initDTO->is_starred;
$this->intendedOwnerId = $initDTO->intendedOwnerId;
return new DuplicateDTO(
shallResyncMetadata: $initDTO->importMode->shallResyncMetadata,
shallSkipDuplicates: $initDTO->importMode->shallSkipDuplicates,
intendedOwnerId: $initDTO->intendedOwnerId,
is_starred: $initDTO->is_starred,
exifInfo: $initDTO->exifInfo,
album: $initDTO->album,
photo: $initDTO->duplicate,
);
}

public function getPhoto(): Photo
Expand Down
61 changes: 30 additions & 31 deletions app/DTO/PhotoCreate/StandaloneDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,47 +15,46 @@

class StandaloneDTO implements PhotoDTO
{
public readonly bool $shallImportViaSymlink;
public readonly bool $shallDeleteImported;

// The resulting photo
public Photo $photo;

// Indicates the intended owner of the image.
public readonly int $intendedOwnerId;

// Indicates whether the new photo shall be starred.
public readonly bool $is_starred;

// The intended parent album
public readonly ?AbstractAlbum $album;

// The original photo source file that is imported.
public readonly NativeLocalFile $sourceFile;

// The extracted EXIF information (populated during init phase).
public readonly Extractor $exifInfo;

public ImageHandlerInterface|null $sourceImage = null;
public AbstractSizeVariantNamingStrategy $namingStrategy;
public TemporaryLocalFile|null $tmpVideoFile = null;
public FlysystemFile $targetFile;
public StreamStats|null $streamStat;

public function __construct(InitDTO $initDTO)
{
$this->photo = new Photo();
$this->sourceFile = $initDTO->sourceFile;
$this->is_starred = $initDTO->is_starred;
$this->exifInfo = $initDTO->exifInfo;
$this->album = $initDTO->album;
$this->intendedOwnerId = $initDTO->intendedOwnerId;
$this->shallImportViaSymlink = $initDTO->importMode->shallImportViaSymlink;
$this->shallDeleteImported = $initDTO->importMode->shallDeleteImported;
public function __construct(
// The resulting photo
public Photo $photo,
// The original photo source file that is imported.
public readonly NativeLocalFile $sourceFile,
// Indicates whether the new photo shall be starred.
public readonly bool $is_starred,
// The extracted EXIF information (populated during init phase).
public readonly Extractor $exifInfo,
// The intended parent album
public readonly ?AbstractAlbum $album,
// Indicates the intended owner of the image.
public readonly int $intendedOwnerId,
public readonly bool $shallImportViaSymlink,
public readonly bool $shallDeleteImported,
) {
}

public function getPhoto(): Photo
{
return $this->photo;
}

public static function ofInit(InitDTO $initDTO): StandaloneDTO
{
return new StandaloneDTO(
photo: new Photo(),
sourceFile: $initDTO->sourceFile,
is_starred: $initDTO->is_starred,
exifInfo: $initDTO->exifInfo,
album: $initDTO->album,
intendedOwnerId: $initDTO->intendedOwnerId,
shallImportViaSymlink: $initDTO->importMode->shallImportViaSymlink,
shallDeleteImported: $initDTO->importMode->shallDeleteImported,
);
}
}
31 changes: 17 additions & 14 deletions app/DTO/PhotoCreate/VideoPartnerDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,30 @@

class VideoPartnerDTO implements PhotoDTO
{
public readonly bool $shallImportViaSymlink;
public readonly bool $shallDeleteImported;

// The resulting photo
public readonly Photo $photo;

public StreamStats|null $streamStat;

public string $videoPath;
public readonly BaseMediaFile $videoFile;

public function __construct(InitDTO $initDTO)
{
$this->videoFile = $initDTO->sourceFile;
$this->photo = $initDTO->livePartner;
$this->shallImportViaSymlink = $initDTO->importMode->shallImportViaSymlink;
$this->shallDeleteImported = $initDTO->importMode->shallDeleteImported;
public function __construct(
public readonly BaseMediaFile $videoFile,
// The resulting photo
public readonly Photo $photo,
public readonly bool $shallImportViaSymlink,
public readonly bool $shallDeleteImported,
) {
}

public function getPhoto(): Photo
{
return $this->photo;
}

public static function ofInit(InitDTO $initDTO): VideoPartnerDTO
{
return new VideoPartnerDTO(
videoFile: $initDTO->sourceFile,
photo: $initDTO->livePartner,
shallImportViaSymlink: $initDTO->importMode->shallImportViaSymlink,
shallDeleteImported: $initDTO->importMode->shallDeleteImported,
);
}
}

0 comments on commit 92909da

Please sign in to comment.