Installation
Add the bundle to your composer.json:
composer require cekurte/componentbundle
Register the bundle in config/bundles.php (Symfony 4+):
return [
// ...
Cekurte\ComponentBundle\CekurteComponentBundle::class => ['all' => true],
];
First Use Case: Basic REST Controller
Use the ResourceManagerInterface to handle Doctrine entities. Example:
use Cekurte\ComponentBundle\Resource\ResourceManagerInterface;
use Doctrine\ORM\EntityManagerInterface;
class PostController extends AbstractController
{
public function __construct(private ResourceManagerInterface $resourceManager)
{
}
public function index(EntityManagerInterface $em)
{
$posts = $this->resourceManager->findAll('App\Entity\Post', $em);
return $this->json($posts);
}
}
Where to Look First
ResourceManagerInterface in src/Resource/ResourceManagerInterface.php.CekurteGeneratorBundle for practical usage patterns (even if outdated, it hints at intended workflows).Resource Management
$resourceManager->findAll(EntityClass::class, $em); // List all
$resourceManager->findOneBy($id, $em); // Single entity
ResourceManagerInterface for non-Doctrine resources (e.g., MongoDB, API clients).
class CustomManager implements ResourceManagerInterface {
public function findAll($resource, $context) { ... }
public function findOneBy($id, $context) { ... }
}
Integration with Symfony
# config/services.yaml
services:
App\Service\CustomManager:
tags: ['cekurte.resource_manager']
RESTful Controllers
CekurteGeneratorBundle (if available) to auto-generate controllers:
php bin/console generate:cekurte:crud
abstract class ApiController extends AbstractController
{
use ResourceManagerTrait; // Hypothetical trait for shared methods
}
Validation and Serialization
SerializerInterface (Symfony’s serializer) to transform entities to/from JSON.Outdated Codebase
AbstractController may not exist in newer versions).
Symfony\Bundle\FrameworkBundle\Controller\AbstractController instead.EntityManagerInterface for testing.Lack of Documentation
ResourceManagerInterface is minimal; assume undocumented methods may change.
CekurteGeneratorBundle for practical examples (despite its age).Testing Challenges
$this->container->get('test.service_ids')->has('cekurte.resource_manager');
Service Binding Issues
ResourceManagerInterface isn’t autowired, ensure your custom manager is tagged:
tags:
- { name: cekurte.resource_manager }
php bin/console debug:container | grep cekurte
Entity Not Found
findOneBy() returns null unexpectedly.App\Entity\Post, not Post).Performance
Criteria in custom managers:
$query = $em->createQuery('SELECT p FROM App\Entity\Post p');
$query->setMaxResults(10);
return $query->getResult();
Add New Resource Managers
ResourceManagerInterface and tag the service:
class ElasticManager implements ResourceManagerInterface {
public function findAll($resource, $context) {
return $context->get('elasticsearch')->search($resource);
}
// ...
}
Customize Serialization
$serializer = $this->container->get('serializer');
$data = $serializer->serialize($entity, 'json', [
'groups' => ['api']
]);
Event-Driven Extensions
$dispatcher->dispatch(new ResourceEvent($entity, 'pre.persist'), 'resource.pre_persist');
Configuration
config/packages/cekurte.yaml.
How can I help you explore Laravel packages today?