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

Elastica Bundle Laravel Package

bok/elastica-bundle

View on GitHub
Deep Wiki
Context7
Custom Properties

Since FOSElasticaBundle 3.1.0, we now dispatch an event for each transformation of an object into an Elastica document which allows you to set custom properties on the Elastica document for indexing.

Set up an event listener or subscriber for FOS\ElasticaBundle\Event\PostTransformEvent to be able to inject your own parameters.


namespace AcmeBundle\EventListener;

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use FOS\ElasticaBundle\Event\PostTransformEvent;

class CustomPropertyListener implements EventSubscriberInterface
{
    private $anotherService;
    
    // ...
    
    public function addCustomProperty(PostTransformEvent $event)
    {
        $document = $event->getDocument();
        $custom = $this->anotherService->calculateCustom($event->getObject());
                    
        $document->set('custom', $custom);
    }
    
    public static function getSubscribedEvents()
    {
        return [
            PostTransformEvent::class => 'addCustomProperty',
        ];
    }
}

Service definition (when autoconfigure is disabled):

acme.listener.custom_property:
    class: AcmeBundle\EventListener\CustomPropertyListener
    tags:
        - { name: kernel.event_subscriber }

Note that if you use serializer you cannot use this, see #1142 and #1185.

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.
graham-campbell/flysystem
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
directorytree/opensearch-client
directorytree/opensearch-adapter
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin