PHP code example of jul6art / push-bundle

1. Go to this page and download the library: Download jul6art/push-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jul6art / push-bundle example snippets


/**
 * @ApiResource(mercure=true)
 */
class SomeTopic {}

use Jul6Art\PushBundle\Service\Traits\PusherAwareTrait;

/**
 * Class RequestEventSubscriber
 */
class SomeService
{
    use PusherAwareTrait;

    public function function(): void
    {
        $this->pusher->push('/some/topic', ['test' => true]);
    }
}

/**
 * @ORM\Entity(repositoryClass=MyClassRepository::class)
 * @Asyncable(eventClass="App\Event\MyClassEvent")
 */
class MyClass
{

}



namespace App\Event;

use App\Entity\MyClass;
use Jul6Art\CoreBundle\Event\AbstractEvent;

/**
 * Class MyClassEvent
 */
class MyClassEvent extends AbstractEvent
{
    public const CREATED = 'event.my_class.created';
    public const DELETED = 'event.my_class.deleted';
    public const EDITED = 'event.my_class.edited';
    public const VIEWED = 'event.my_class.viewed';

    /**
     * @var MyClass
     */
    private $myClass;

    public function __construct(MyClass $myClass)
    {
        parent::__construct();

        $this->myClass = $myClass;
    }

    public function getMyClass(): MyClass
    {
        return $this->myClass;
    }

    public function setMyClass(MyClass $myClass): MyClassEvent
    {
        $this->myClass = $myClass;
        return $this;
    }
}

/**
 * @ORM\Entity(repositoryClass=MyClassRepository::class)
 * @Asyncable(eventClass="App\Event\MyClassEvent", events={"postLoad", "postPersist"})
 */
class MyClass
{

}
shell
bin/console messenger:consume async_priority_high --time-limit 600