Skip to content

Conversation

@JakovKnezovicc
Copy link
Contributor

@JakovKnezovicc JakovKnezovicc commented Dec 17, 2025

Adds command and service for generating iri templates in json format using dumper.
Included to container build if enabled as a feature in config passed via container parameter.

@JakovKnezovicc JakovKnezovicc self-assigned this Dec 17, 2025
@JakovKnezovicc JakovKnezovicc force-pushed the NGSTACK-1017-iri-template-generation branch from 7fa0502 to 892ad6a Compare January 15, 2026 09:52

try {
$content = json_encode($iriTemplates, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
} catch (\JsonException) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Root classes like these should also be imported with use JsonException.

IriTemplatesService::class,
new Definition(IriTemplatesService::class),
)
->setAutowired(true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, autowiring should not be used in vendor libraries because autowiring should always be opt-in for project developers.

) {}

/**
* @throws ResourceClassNotFoundException
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method does not actually throw anything.


use function preg_replace;

final readonly class IriTemplatesService
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need readonly.

$iriTemplates = [];

foreach ($resourceClasses as $class) {
/** @var ApiResource $resourceMetadata */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All PHPDoc should have FQCN.

use const JSON_UNESCAPED_SLASHES;

#[AsCommand(
name: 'api-platform-extras:generate-iri-templates',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefix command names with netgen:

use const JSON_THROW_ON_ERROR;
use const JSON_UNESCAPED_SLASHES;

#[AsCommand(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will almost certainly clash with service definition in compiler pass.


final class IriTemplateGeneratorCompilerPass implements CompilerPassInterface
{
private const FEATURE_ENABLED_PARAMETER = 'netgen_api_platform_extras.features.iri_template_generator.enabled';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private const string can be used.

@JakovKnezovicc JakovKnezovicc force-pushed the NGSTACK-1017-iri-template-generation branch from 892ad6a to 5845b9e Compare January 15, 2026 14:14
@JakovKnezovicc JakovKnezovicc force-pushed the NGSTACK-1017-iri-template-generation branch from 5845b9e to c4811ee Compare January 15, 2026 14:57
@JakovKnezovicc
Copy link
Contributor Author

prethodni komentari rijeseni u jednom commitu a36809a

private ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory,
private ResourceNameCollectionFactoryInterface $resourceExtractor,
private RouterInterface $router,
private readonly ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I meant we don't need readonly, I meant at all :D It's just unnecessary noise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants