check24/apitk-* bundles (e.g., apitk-swagger-bundle or apitk-api-bundle). This package is designed as a shared dependency for them.composer require check24/apitk-common-bundle
(Note: Manual installation is rare; it’s typically pulled in via other apitk-* bundles.)EntityAwareParamConverterTrait or RequestParamAwareParamConverterTrait in your custom converter to leverage shared logic.AbstractDescriber to dynamically modify API documentation.src/Annotation/, src/ParamConverter/, and src/Describer/ for reusable components.src/Contract/ for shared interfaces (e.g., EntityAwareInterface).apitk-swagger-bundle or apitk-api-bundle source to see how this package is integrated.Entity-Based Conversion:
use Check24\ApitkCommonBundle\ParamConverter\EntityAwareParamConverterTrait;
class MyParamConverter implements ParamConverterInterface {
use EntityAwareParamConverterTrait;
public function supports(ParamConverterInterface $configuration) {
return $configuration->getClass() === MyEntity::class;
}
public function convert($value, ParamConverterInterface $configuration) {
$entity = $this->getEntity(); // Uses EntityAwareTrait
$repo = $this->getEntityManager()->getRepository(MyEntity::class);
return $repo->find($entity->getId());
}
}
getEntity(), getEntityManager(), callRepositoryMethod().Request Param Handling:
use Check24\ApitkCommonBundle\ParamConverter\RequestParamAwareParamConverterTrait;
class RequestParamConverter implements ParamConverterInterface {
use RequestParamAwareParamConverterTrait;
public function convert($value, ParamConverterInterface $configuration) {
$paramValue = $this->getRequestParamValue('user_id', 1); // Default: 1
return new User($paramValue);
}
}
getRequestParam(), getRequestParamValue().Context-Aware Options:
use Check24\ApitkCommonBundle\ParamConverter\ContextAwareParamConverterTrait;
class ContextParamConverter implements ParamConverterInterface {
use ContextAwareParamConverterTrait;
public function convert($value, ParamConverterInterface $configuration) {
$name = $this->getOption('name', 'default_name'); // Access annotation options
return new Response(['name' => $name]);
}
}
Extending ParamConverter Annotations:
use Check24\ApitkCommonBundle\Annotation\EntityAwareAnnotationTrait;
#[Route('/users/{id}', name: 'user_show')]
#[ParamConverter(
class: 'App\Entity\User',
options: ['entity' => true, 'methodName' => 'findById']
)]
public function show(User $user) { ... }
EntityAwareAnnotationTrait: Adds entity, entityManager, methodName.RequestParamAwareAnnotationTrait: Adds requestParam.Dynamic OpenAPI Descriptions:
use Check24\ApitkCommonBundle\Describer\AbstractDescriber;
class CustomDescriber extends AbstractDescriber {
protected function describeOperation(Operation $operation) {
$operation->setSummary('Custom summary via ' . static::class);
return $operation;
}
}
services.yaml:
services:
App\Describer\CustomDescriber:
tags: ['api_platform.describer']
apitk-* bundles, this package is auto-installed. No manual config needed.EntityAware traits are used with Doctrine entities (e.g., getEntityManager() requires Doctrine).RequestParamAware traits, ensure the request object is available in the converter’s context.Manual Installation:
apitk-* bundles will yield no practical benefit. It’s designed for internal use by the apitk ecosystem.composer require check24/apitk-swagger-bundle (or similar), which pulls this as a dependency.EntityManager Assumptions:
EntityAwareParamConverterTrait assumes Doctrine is configured. If using another ORM (e.g., Eloquent), override getEntityManager() or avoid the trait.EntityManagerInterface manually if needed:
public function __construct(private EntityManagerInterface $em) {}
Request Scope:
RequestParamAwareParamConverterTrait relies on Symfony’s RequestStack. Ensure your converter is request-scoped or the request is passed explicitly.RequestStack service availability with:
bin/console debug:container RequestStack
Annotation Overrides:
EntityAwareAnnotationTrait must match the trait’s expected options (entity, methodName, etc.). Mismatched options will throw errors.supports() method:
public function supports(ParamConverterInterface $configuration) {
return $configuration->getClass() === MyEntity::class
&& $configuration->getOptions()['entity'] ?? false;
}
ParamConverter Issues:
_PROFILE=1 _CONTEXT=dev symfony serve
OpenAPI Describer:
AbstractDescriber changes aren’t reflected, clear the cache:
bin/console cache:clear
services.yaml:
tags: ['api_platform.describer'] # For API Platform
# OR
tags: ['nelmio_api_doc.describer'] # For NelmioApiDoc
Custom Traits:
ContextAwareParamConverterTrait) to add domain-specific logic. Example:
trait MyCustomParamConverterTrait {
use ContextAwareParamConverterTrait;
protected function getCustomOption(string $name, $default = null) {
return $this->getOption('custom.' . $name, $default);
}
}
Describer Hooks:
AbstractDescriber to modify OpenAPI schemas dynamically:
protected function describeSchema(Schema $schema) {
$schema->setExample(['id' => 1, 'name' => 'Example']);
return $schema;
}
Annotation Validation:
entity, requestParam, etc., options:
use Check24\ApitkCommonBundle\Annotation\EntityAwareInterface;
class MyAnnotationValidator implements ConstraintValidator {
public function validate($annotation, $object) {
if (!$annotation instanceof EntityAwareInterface) {
return;
}
if (empty($annotation->getEntity())) {
$this->context->buildViolation('Entity is required.')
->addViolation();
}
}
}
Service Autowiring:
EntityAwareParamConverterTrait assume autowiring for EntityManagerInterface. If not autowired, manually inject it:
public function __construct(private EntityManagerInterface $em) {}
RequestStack Binding:
RequestParamAware traits, bind the RequestStack service explicitly if using custom containers:
# config/services.yaml
services:
App\ParamConverter\RequestParamConverter:
arguments:
$requestStack: '@request_stack'
How can I help you explore Laravel packages today?