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

Doctrine Api Bundle Laravel Package

bankiru/doctrine-api-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup in Laravel

Since this is a Symfony bundle, use Laravel's Symfony Bridge (symfony/console, symfony/finder, etc.) or wrap it in a Laravel package. Install via Composer:

composer require bankiru/doctrine-api-bundle

First Use Case: API Entity Management

  1. Register the Bundle (if using Symfony Bridge): In config/bundles.php (Symfony) or manually bootstrap in Laravel:

    // config/app.php (Laravel)
    'providers' => [
        // Add Symfony bridge if not present
        SymfonyBridge\ServiceProvider::class,
    ];
    
  2. Access the Entity Manager:

    $entityManager = app('bankiru_api.entity_manager');
    // Use like Doctrine's ORM but for API calls
    
  3. Define API Entities: Extend ApiEntity (from bankiru/doctrine-api-client) and configure API endpoints in config/packages/bankiru_api.yaml (Symfony) or a Laravel config file.


Implementation Patterns

Workflow: CRUD via API

  1. Entity Definition:

    use Bankiru\DoctrineApiClient\Entity\ApiEntity;
    
    class User extends ApiEntity
    {
        protected $apiEndpoint = '/users';
        protected $apiResource = 'user';
    }
    
  2. Repository Pattern:

    class UserRepository
    {
        protected $entityManager;
    
        public function __construct($entityManager)
        {
            $this->entityManager = $entityManager;
        }
    
        public function find($id)
        {
            return $this->entityManager->find(User::class, $id);
        }
    
        public function save(User $user)
        {
            $this->entityManager->persist($user);
            $this->entityManager->flush();
        }
    }
    
  3. Service Layer:

    class UserService
    {
        protected $repository;
    
        public function __construct(UserRepository $repository)
        {
            $this->repository = $repository;
        }
    
        public function createUser(array $data)
        {
            $user = new User();
            $user->fromArray($data); // Hydrate from API response
            $this->repository->save($user);
            return $user;
        }
    }
    

Integration with Laravel

  • Service Container Binding:

    $this->app->bind('bankiru_api.entity_manager', function ($app) {
        return new \Bankiru\DoctrineApiBundle\ApiEntityManager(
            new \Bankiru\DoctrineApiClient\Client($app['config']['api.client'])
        );
    });
    
  • API Client Configuration:

    // config/api.php
    'client' => [
        'base_uri' => env('API_BASE_URI', 'https://api.example.com'),
        'auth' => [
            'token' => env('API_TOKEN'),
        ],
    ],
    

Gotchas and Tips

Pitfalls

  1. Outdated Codebase:

    • Last release in 2017; test thoroughly. May lack support for modern PHP/Laravel features (e.g., PSR-15 middleware, Symfony 5+).
    • Workaround: Fork and update dependencies (e.g., symfony/http-client, doctrine/annotations).
  2. Symfony-Specific Assumptions:

    • Bundle expects Symfony’s ContainerInterface. In Laravel, mock or adapt:
      $container = new \Symfony\Component\DependencyInjection\Container();
      $container->set('bankiru_api.entity_manager', $entityManager);
      
  3. Entity Hydration:

    • API responses may not auto-hydrate entities. Override fromArray() or use a mapper:
      $user = new User();
      $user->setName($apiResponse['name']); // Manual mapping
      

Debugging

  • Enable API Client Logging: Configure the underlying bankiru/doctrine-api-client to log requests/responses:

    $client = new \Bankiru\DoctrineApiClient\Client($config, [
        'logger' => new \Monolog\Logger('api'),
    ]);
    
  • Check HTTP Status Codes: The bundle may silently fail on non-200 responses. Add validation:

    try {
        $entityManager->find(User::class, 1);
    } catch (\Bankiru\DoctrineApiClient\Exception\ApiException $e) {
        \Log::error('API Error: ' . $e->getMessage());
    }
    

Extension Points

  1. Custom API Endpoints: Override $apiEndpoint in entities or use a dynamic resolver:

    class DynamicUser extends User
    {
        protected $apiEndpoint = '/custom-users';
    }
    
  2. Event Listeners: Attach to prePersist, postLoad via Doctrine events (if supported):

    $entityManager->getEventManager()->addEventListener(
        \Doctrine\ORM\Events::prePersist,
        new \Your\ApiEntityListener()
    );
    
  3. Testing: Mock the ApiEntityManager in PHPUnit:

    $mockManager = $this->createMock(\Bankiru\DoctrineApiBundle\ApiEntityManager::class);
    $mockManager->method('find')->willReturn(new User());
    $this->app->instance('bankiru_api.entity_manager', $mockManager);
    
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.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui