Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Componentbundle Laravel Package

cekurte/componentbundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. 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],
    ];
    
  2. 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);
        }
    }
    
  3. Where to Look First

    • Documentation: The README is minimal; focus on the ResourceManagerInterface in src/Resource/ResourceManagerInterface.php.
    • Example: Check CekurteGeneratorBundle for practical usage patterns (even if outdated, it hints at intended workflows).
    • Tests: The bundle’s tests (if any) may reveal edge cases or expected behavior.

Implementation Patterns

Core Workflows

  1. Resource Management

    • Fetching Data:
      $resourceManager->findAll(EntityClass::class, $em); // List all
      $resourceManager->findOneBy($id, $em); // Single entity
      
    • Custom Managers: Implement ResourceManagerInterface for non-Doctrine resources (e.g., MongoDB, API clients).
      class CustomManager implements ResourceManagerInterface {
          public function findAll($resource, $context) { ... }
          public function findOneBy($id, $context) { ... }
      }
      
  2. Integration with Symfony

    • Dependency Injection: Bind your custom manager as a service:
      # config/services.yaml
      services:
          App\Service\CustomManager:
              tags: ['cekurte.resource_manager']
      
    • Event Listeners: Extend functionality via Symfony events (e.g., pre/post resource operations).
  3. RESTful Controllers

    • CRUD Boilerplate: Pair with CekurteGeneratorBundle (if available) to auto-generate controllers:
      php bin/console generate:cekurte:crud
      
    • Manual Approach: Use traits or base controllers to DRY up logic:
      abstract class ApiController extends AbstractController
      {
          use ResourceManagerTrait; // Hypothetical trait for shared methods
      }
      
  4. Validation and Serialization

    • Forms: Leverage Symfony’s form component to validate incoming data before resource operations.
    • Serialization: Use SerializerInterface (Symfony’s serializer) to transform entities to/from JSON.

Gotchas and Tips

Pitfalls

  1. Outdated Codebase

    • Last Release (2015): Assumes Symfony 2.x patterns (e.g., AbstractController may not exist in newer versions).
      • Fix: Extend Symfony\Bundle\FrameworkBundle\Controller\AbstractController instead.
    • Doctrine ORM Dependency: Hardcoded assumptions about Doctrine may break with other DBALs.
      • Fix: Abstract further or mock EntityManagerInterface for testing.
  2. Lack of Documentation

    • No Clear API: The ResourceManagerInterface is minimal; assume undocumented methods may change.
      • Tip: Override methods explicitly to avoid surprises.
    • No Examples: The README lacks usage snippets beyond the interface.
      • Tip: Study CekurteGeneratorBundle for practical examples (despite its age).
  3. Testing Challenges

    • No Built-in Tests: The package may lack test coverage for edge cases.
      • Tip: Write integration tests for your custom managers:
        $this->container->get('test.service_ids')->has('cekurte.resource_manager');
        

Debugging Tips

  1. Service Binding Issues

    • If ResourceManagerInterface isn’t autowired, ensure your custom manager is tagged:
      tags:
          - { name: cekurte.resource_manager }
      
    • Debug: Dump service IDs:
      php bin/console debug:container | grep cekurte
      
  2. Entity Not Found

    • Symptom: findOneBy() returns null unexpectedly.
    • Fix: Verify the entity class is fully qualified (e.g., App\Entity\Post, not Post).
  3. Performance

    • N+1 Queries: The bundle doesn’t handle eager-loading by default.
      • Tip: Use DQL or Criteria in custom managers:
        $query = $em->createQuery('SELECT p FROM App\Entity\Post p');
        $query->setMaxResults(10);
        return $query->getResult();
        

Extension Points

  1. Add New Resource Managers

    • Implement ResourceManagerInterface and tag the service:
      class ElasticManager implements ResourceManagerInterface {
          public function findAll($resource, $context) {
              return $context->get('elasticsearch')->search($resource);
          }
          // ...
      }
      
  2. Customize Serialization

    • Override the default serializer in your controller:
      $serializer = $this->container->get('serializer');
      $data = $serializer->serialize($entity, 'json', [
          'groups' => ['api']
      ]);
      
  3. Event-Driven Extensions

    • Dispatch events before/after resource operations:
      $dispatcher->dispatch(new ResourceEvent($entity, 'pre.persist'), 'resource.pre_persist');
      
  4. Configuration

    • No Config File: The bundle doesn’t expose settings via config/packages/cekurte.yaml.
      • Workaround: Use parameters or environment variables for manager-specific settings.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
comsave/common
alecsammon/php-raml-parser
chrome-php/wrench
lendable/composer-license-checker
typhoon/reflection
mesilov/moneyphp-percentage
mike42/gfx-php
bookdown/themes
aura/view
aura/html
aura/cli
povils/phpmnd
nayjest/manipulator
omnipay/tests
psr-mock/http-message-implementation
psr-mock/http-factory-implementation
psr-mock/http-client-implementation
voku/email-check
voku/urlify
rtheunissen/guzzle-log-middleware