Skip to content

Commit

Permalink
move video output "formats" documentation to each related transformer…
Browse files Browse the repository at this point in the history
… module.

move conf validator to attribute (not full entity)
  • Loading branch information
jygaulier committed Dec 5, 2024
1 parent 272c5ff commit 1d69779
Show file tree
Hide file tree
Showing 17 changed files with 161 additions and 148 deletions.
2 changes: 2 additions & 0 deletions databox/api/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,5 @@ services:
$decorated: '@.inner'

Alchemy\RenditionFactory\Templating\TemplateResolverInterface: '@App\Asset\Attribute\TemplateResolver'

App\Validator\ValidRenditionDefinitionConstraintValidator: ~
5 changes: 2 additions & 3 deletions databox/api/config/validator/validation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ App\Entity\Core\RenditionDefinition:
- workspace
- class.workspace
- parent.workspace
- App\Validator\ValidRenditionDefinitionConstraint: ~
properties:
class:
- NotNull: ~
Expand Down Expand Up @@ -177,8 +176,8 @@ App\Entity\Core\Tag:
errorPath: name

App\Entity\Integration\WorkspaceIntegration:
constraints:
- App\Validator\ValidIntegrationOptionsConstraint: ~
constraints:
- App\Validator\ValidIntegrationOptionsConstraint: ~

App\Entity\Integration\IntegrationData:
properties:
Expand Down
12 changes: 4 additions & 8 deletions databox/api/src/Command/DocumentationDumperCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Alchemy\RenditionFactory\DocumentationDumper as RenditionFactoryDocumentationDumper;
use Alchemy\RenditionFactory\RenditionBuilderConfigurationDocumentation;


#[AsCommand('app:documentation:dump')]
class DocumentationDumperCommand extends Command
{
public function __construct(
private readonly RenditionFactoryDocumentationDumper $renditionFactoryDocumentationDumper,
private readonly RenditionBuilderConfigurationDocumentation $renditionBuilderConfigurationDocumentation,
)
{
parent::__construct();
Expand All @@ -24,16 +24,12 @@ public function __construct(
protected function configure(): void
{
parent::configure();

$this
->setName('app:documentation:dump')
;
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$output->writeln('# ' . $this->renditionFactoryDocumentationDumper::getName());
$output->writeln($this->renditionFactoryDocumentationDumper->dump());
$output->writeln('# ' . $this->renditionBuilderConfigurationDocumentation::getName());
$output->writeln($this->renditionBuilderConfigurationDocumentation->generate());

return 0;
}
Expand Down
7 changes: 4 additions & 3 deletions databox/api/src/Entity/Core/RenditionDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
namespace App\Entity\Core;

use Alchemy\CoreBundle\Entity\AbstractUuidEntity;
use Alchemy\CoreBundle\Entity\Traits\CreatedAtTrait;
use Alchemy\CoreBundle\Entity\Traits\UpdatedAtTrait;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Delete;
Expand All @@ -16,10 +18,8 @@
use App\Api\Model\Input\RenditionDefinitionInput;
use App\Api\Provider\RenditionDefinitionCollectionProvider;
use App\Controller\Core\RenditionDefinitionSortAction;

use Alchemy\CoreBundle\Entity\Traits\CreatedAtTrait;
use Alchemy\CoreBundle\Entity\Traits\UpdatedAtTrait;
use App\Entity\Traits\WorkspaceTrait;
use App\Validator as CustomAssert;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection as DoctrineCollection;
use Doctrine\DBAL\Types\Types;
Expand Down Expand Up @@ -153,6 +153,7 @@ class RenditionDefinition extends AbstractUuidEntity implements \Stringable
#[Groups([RenditionDefinition::GROUP_LIST, RenditionDefinition::GROUP_READ, RenditionDefinition::GROUP_WRITE])]
#[ORM\Column(type: Types::TEXT, nullable: true)]
#[ApiProperty(security: self::GRANT_ADMIN_PROP)]
#[CustomAssert\ValidRenditionDefinitionConstraint]
private ?string $definition = null;

#[Groups([RenditionDefinition::GROUP_READ])]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@

use Symfony\Component\Validator\Constraint;

/** @uses ValidRenditionDefinitionConstraintValidator */
#[\Attribute]
class ValidRenditionDefinitionConstraint extends Constraint
{
public function getTargets(): string|array
{
return self::CLASS_CONSTRAINT;
return self::PROPERTY_CONSTRAINT;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,31 @@

namespace App\Validator;


use Alchemy\RenditionFactory\Config\Validator;
use Alchemy\RenditionFactory\Config\buildConfigValidator;
use Alchemy\RenditionFactory\Config\YamlLoader;
use App\Entity\Core\RenditionDefinition;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;

class ValidRenditionDefinitionConstraintValidator extends ConstraintValidator
{
public function __construct(private readonly YamlLoader $yamlLoader, private readonly Validator $validator)
/** @uses buildConfigValidator */
public function __construct(private readonly YamlLoader $yamlLoader, private readonly buildConfigValidator $validator)
{
}

/**
* @param RenditionDefinition $value
* @param string $value
* @param ValidRenditionDefinitionConstraint $constraint
*/
public function validate($value, Constraint $constraint): void
{
if(!($definition = $value->getDefinition())) {
if(!$value) {
return;
}
try {
$config = $this->yamlLoader->parse($definition);
$config = $this->yamlLoader->parse($value);
$this->validator->validate($config);
} catch (\Throwable $e) {
} catch (\Exception $e) {
$this->context
->buildViolation($e->getMessage())
->addViolation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ services:
tags:
- { name: !php/const Alchemy\RenditionFactory\Transformer\Video\Format\FormatInterface::TAG }

Alchemy\RenditionFactory\Transformer\Video\Format\OutputFormatsDocumentation: ~

Imagine\Imagick\Imagine: ~
Imagine\Image\ImagineInterface: '@Imagine\Imagick\Imagine'
Expand All @@ -103,8 +104,6 @@ services:
Alchemy\RenditionFactory\Format\FormatFactory: ~
Alchemy\RenditionFactory\Config\ModuleOptionsResolver: ~

Alchemy\RenditionFactory\DocumentationDumper:
tags:
- { name: 'documentation.dumper' }
Alchemy\RenditionFactory\RenditionBuilderConfigurationDocumentation: ~

Alchemy\RenditionFactory\Config\Validator: ~
Alchemy\RenditionFactory\Config\buildConfigValidator: ~
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Alchemy\RenditionFactory\Command;

use Alchemy\RenditionFactory\Config\Validator;
use Alchemy\RenditionFactory\Config\buildConfigValidator;
use Alchemy\RenditionFactory\Config\YamlLoader;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
Expand All @@ -17,7 +17,7 @@ class ConfigurationValidateCommand extends Command
{
public function __construct(
private readonly YamlLoader $yamlLoader,
private readonly Validator $validator,
private readonly buildConfigValidator $validator,
) {
parent::__construct();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@
use Symfony\Component\DependencyInjection\Attribute\TaggedLocator;
use Symfony\Component\DependencyInjection\ServiceLocator;

class Validator
readonly class buildConfigValidator
{
public function __construct(
#[TaggedLocator(TransformerModuleInterface::TAG, defaultIndexMethod: 'getName')]
private readonly ServiceLocator $transformers,
private ServiceLocator $transformers,
) {

}

public function getTransformers(): ServiceLocator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@

use Alchemy\RenditionFactory\Transformer\Documentation;
use Alchemy\RenditionFactory\Transformer\TransformerModuleInterface;
use Alchemy\RenditionFactory\Transformer\Video\Format\FormatInterface;
use Symfony\Component\Config\Definition\Dumper\YamlReferenceDumper;
use Symfony\Component\DependencyInjection\Attribute\TaggedLocator;
use Symfony\Component\DependencyInjection\ServiceLocator;

final readonly class DocumentationDumper
final readonly class RenditionBuilderConfigurationDocumentation
{
public function __construct(
#[TaggedLocator(TransformerModuleInterface::TAG, defaultIndexMethod: 'getName')]
private ServiceLocator $transformers,
#[TaggedLocator(FormatInterface::TAG, defaultIndexMethod: 'getFormat')]
private ServiceLocator $formats,
) {
}

Expand All @@ -24,48 +21,14 @@ public static function getName(): string
return 'rendition-factory';
}

public function dump(): string
public function generate(): string
{
$text = '';
foreach ($this->transformers->getProvidedServices() as $transformerName => $transformerFqcn) {
/** @var TransformerModuleInterface $transformer */
$transformer = $this->transformers->get($transformerName);
$text .= $this->getTransformerDocumentation($transformerName, $transformer);
}
$text .= $this->listFormats();

return $text;
}

private function listFormats(): string
{
$formats = [];
foreach ($this->formats->getProvidedServices() as $formatName => $formatFqcn) {
/** @var FormatInterface $format */
$format = $this->formats->get($formatName);
$family = $format->getFamily()->value;
if (!array_key_exists($family, $formats)) {
$formats[$family] = [];
}
$formats[$family][] = $format;
}
ksort($formats);

$text = "## Video transformers output `format`s.\n";
$text .= "| Family | Format | Mime type | Extensions |\n";
$text .= "|-|-|-|-|\n";
foreach ($formats as $familyFormats) {
$text .= sprintf("| %s ||||\n",
$familyFormats[0]->getFamily()->value,
);
foreach ($familyFormats as $format) {
$text .= sprintf("|| %s | %s | %s |\n",
$format->getFormat(),
$format->getMimeType(),
implode(', ', $format->getAllowedExtensions())
);
}
}

return $text;
}
Expand Down

This file was deleted.

Loading

0 comments on commit 1d69779

Please sign in to comment.