-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Asset sys API update. Now supports custom data and could generate pub…
…lic route for asset
- Loading branch information
1 parent
7df3f86
commit 61b85c9
Showing
11 changed files
with
214 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace AnzuSystems\CoreDamBundle\Model\Dto\AssetFile; | ||
|
||
use AnzuSystems\CoreDamBundle\Entity\ExtSystem; | ||
use AnzuSystems\CoreDamBundle\Entity\Interfaces\AssetCustomFormProvidableInterface; | ||
use AnzuSystems\CoreDamBundle\Model\Enum\AssetType; | ||
|
||
final readonly class AssetCustomFormProvidableDto implements AssetCustomFormProvidableInterface | ||
{ | ||
public function __construct( | ||
private AssetType $assetType, | ||
private ExtSystem $extSystem, | ||
) { | ||
} | ||
|
||
public function getAssetType(): AssetType | ||
{ | ||
return $this->assetType; | ||
} | ||
|
||
public function getExtSystem(): ExtSystem | ||
{ | ||
return $this->extSystem; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace AnzuSystems\CoreDamBundle\Validator\Constraints; | ||
|
||
use Attribute; | ||
use Symfony\Component\Validator\Constraint; | ||
|
||
#[Attribute] | ||
final class AssetFileSysCreate extends Constraint | ||
{ | ||
public function getTargets(): string | ||
{ | ||
return self::CLASS_CONSTRAINT; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace AnzuSystems\CoreDamBundle\Validator\Constraints; | ||
|
||
use AnzuSystems\CommonBundle\Exception\ValidationException; | ||
use AnzuSystems\CoreDamBundle\Domain\AssetFile\AssetFileFactory; | ||
use AnzuSystems\CoreDamBundle\Domain\Configuration\ExtSystemConfigurationProvider; | ||
use AnzuSystems\CoreDamBundle\Exception\DomainException; | ||
use AnzuSystems\CoreDamBundle\Exception\InvalidMimeTypeException; | ||
use AnzuSystems\CoreDamBundle\Model\Dto\AssetFile\AssetCustomFormProvidableDto; | ||
use AnzuSystems\CoreDamBundle\Model\Dto\AssetFile\AssetFileSysCreateDto; | ||
use Doctrine\ORM\NonUniqueResultException; | ||
use League\Flysystem\FilesystemException; | ||
use Symfony\Component\Validator\Constraint; | ||
use Symfony\Component\Validator\Exception\UnexpectedTypeException; | ||
use Symfony\Contracts\Service\Attribute\Required; | ||
|
||
final class AssetFileSysCreateValidator extends CustomDataValidator | ||
{ | ||
private ExtSystemConfigurationProvider $configurationProvider; | ||
private AssetFileFactory $assetFileFactory; | ||
|
||
#[Required] | ||
public function setConfigurationProvider(ExtSystemConfigurationProvider $configurationProvider): void | ||
{ | ||
$this->configurationProvider = $configurationProvider; | ||
} | ||
|
||
#[Required] | ||
public function setAssetFileFactory(AssetFileFactory $assetFileFactory): void | ||
{ | ||
$this->assetFileFactory = $assetFileFactory; | ||
} | ||
|
||
/** | ||
* @throws InvalidMimeTypeException | ||
* @throws FilesystemException | ||
* @throws NonUniqueResultException | ||
*/ | ||
public function validate(mixed $value, Constraint $constraint): void | ||
{ | ||
if (false === ($value instanceof AssetFileSysCreateDto)) { | ||
throw new UnexpectedTypeException($constraint, AssetFileSysCreateDto::class); | ||
} | ||
|
||
$configuration = $this->configurationProvider->getExtSystemConfiguration($value->getExtSystem()->getSlug()); | ||
|
||
try { | ||
$assetType = $this->assetFileFactory->getTypeFromPath($configuration->getExtStorage(), $value->getPath()); | ||
} catch (DomainException) { | ||
$this->context | ||
->buildViolation(ValidationException::ERROR_FIELD_INVALID) | ||
->atPath('path') | ||
->addViolation(); | ||
|
||
return; | ||
} | ||
|
||
$this->validateForm( | ||
form: $this->customFormProvider->provideForm( | ||
(new AssetCustomFormProvidableDto( | ||
assetType: $assetType, | ||
extSystem: $value->getExtSystem() | ||
)) | ||
), | ||
value: $value | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters