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 Riak Admin Bundle Laravel Package

cosmow/doctrine-riak-admin-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require cosmow/doctrine-riak-admin-bundle
    

    Add the bundle to config/bundles.php:

    return [
        // ...
        Cosmow\SonataDoctrineRiakAdminBundle\SonataDoctrineRiakAdminBundle::class => ['all' => true],
    ];
    
  2. Configuration: Ensure your config/packages/sonata_admin.yaml includes Riak-specific settings:

    sonata_admin:
        options:
            riak:
                host: '%env(RIAK_HOST)%'
                port: '%env(RIAK_PORT)%'
                bucket: '%env(RIAK_BUCKET)%'
    
  3. First Use Case: Extend SonataAdminBundle's AbstractAdmin to work with Riak:

    use Cosmow\SonataDoctrineRiakAdminBundle\Admin\RiakAdmin;
    
    class YourAdmin extends RiakAdmin
    {
        protected function configureModelClass(DoctrineRiak\Client $client)
        {
            return $client->getBucket('your_bucket')->getType('YourEntity');
        }
    }
    

Implementation Patterns

Workflow Integration

  1. CRUD Operations: Override create, update, and delete methods to handle Riak-specific logic:

    public function create($object)
    {
        $riakObject = $this->getRiakClient()->getBucket('your_bucket')->getType('YourEntity');
        $riakObject->setData($object->toArray());
        $riakObject->save();
    }
    
  2. List Queries: Use Riak’s secondary indexes or MapReduce for filtering:

    public function getListQuery()
    {
        $query = $this->getRiakClient()->getBucket('your_bucket')
            ->getType('YourEntity')
            ->findAll();
    
        return $query->where('field', '=', $this->getFilterValue('field'));
    }
    
  3. Form Handling: Extend configureFormFields to bind Riak-specific validation:

    protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper->add('field', 'text', [
            'constraints' => [
                new Assert\NotBlank(),
                new Assert\Length(['max' => 255]),
            ],
        ]);
    }
    

Common Patterns

  • Batch Operations: Use Riak’s batch API for bulk updates:

    $batch = $this->getRiakClient()->getBucket('your_bucket')->batch();
    foreach ($ids as $id) {
        $batch->update($id, ['field' => 'new_value']);
    }
    $batch->execute();
    
  • Event Subscribers: Listen to sonata.admin.pre_persist and sonata.admin.pre_update to preprocess Riak objects:

    public function onPrePersist($object, AdminInterface $admin)
    {
        $object->set('timestamp', time());
    }
    

Gotchas and Tips

Pitfalls

  1. Schema Mismatches: Riak is schemaless, but SonataAdmin expects strict entity structures. Validate data before saving:

    public function prePersist($object)
    {
        if (empty($object->get('required_field'))) {
            throw new \RuntimeException('Required field missing');
        }
    }
    
  2. Secondary Indexes: Riak’s secondary indexes are not real-time. Use MapReduce for accurate filtering:

    $results = $this->getRiakClient()->getBucket('your_bucket')
        ->mapReduce()
        ->map('function(value) { return [value.field]; }')
        ->reduce('function(values) { return values; }')
        ->execute();
    
  3. Caching: Disable Sonata’s default ORM caching for Riak:

    sonata_admin:
        options:
            riak:
                cache: false
    

Debugging Tips

  • Enable Riak Logging: Add to config/packages/monolog.yaml:

    handlers:
        riak:
            type: stream
            path: "%kernel.logs_dir%/riak.log"
            level: debug
            channels: ["riak"]
    
  • Check Bucket Existence: Verify buckets exist before operations:

    if (!$this->getRiakClient()->getBucket('your_bucket')->exists()) {
        throw new \RuntimeException('Bucket does not exist');
    }
    

Extension Points

  1. Custom Riak Client: Override the default client in services.yaml:

    services:
        your_riak.client:
            class: Your\Custom\Riak\Client
            arguments: ['%riak_host%', '%riak_port%']
    
  2. Hybrid ORM: Combine Riak with Doctrine ORM for relational data:

    use Doctrine\ORM\EntityManagerInterface;
    
    class HybridAdmin extends RiakAdmin
    {
        private $em;
    
        public function __construct(EntityManagerInterface $em)
        {
            $this->em = $em;
        }
    
        public function create($object)
        {
            $this->em->persist($object->getRelatedEntity());
            $this->em->flush();
            // Save Riak object...
        }
    }
    
  3. Async Operations: Use Symfony’s Messenger component for background Riak writes:

    use Symfony\Component\Messenger\MessageBusInterface;
    
    public function __construct(MessageBusInterface $bus)
    {
        $this->bus = $bus;
    }
    
    public function create($object)
    {
        $this->bus->dispatch(new SaveRiakObjectMessage($object));
    }
    
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