PHP code example of stas-zozulja / pushpin-bundle

1. Go to this page and download the library: Download stas-zozulja/pushpin-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/ */

    

stas-zozulja / pushpin-bundle example snippets



namespace AppBundle\WebsocketEvents\Chat;

use Gamma\Pushpin\PushpinBundle\Events\Base\AbstractJsonEvent;
use JMS\Serializer\Annotation\Type as JMS;

class ChatMessage extends AbstractJsonEvent
{

    /**
     * @var string
     * @JMS("string")
     */
    public $room;

    /**
     * @var string
     * @JMS("string")
     */
    public $comment;

}


namespace AppBundle\Services\WebSocket;

use Gamma\Pushpin\PushpinBundle\Events\Base\AbstractEvent;
use Gamma\Pushpin\PushpinBundle\Handlers\Base\AbstractEventHandler;
use Gamma\Pushpin\PushpinBundle\Interfaces\Events\TextEventInterface;
use GripControl\WebSocketEvent;

class ChatMessageHandler extends AbstractEventHandler
{
    const EVENT_TYPE = TextEventInterface::EVENT_TYPE;

    /**
     * {@inheritdoc}
     */
    public function handle(AbstractEvent $event)
    {
        //your logic


        //Example of creating response event to client:
        //$resultEvent = new WebSocketEvent('TEXT', 'Hello Client');
    }
}


namespace AppBundle\Controller;

use Gamma\Pushpin\PushpinBundle\DTO\WebSocketEventsDTO;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Gamma\Pushpin\PushpinBundle\Configuration\PushpinResponse;

class ChatController extends Controller
{

    /**
     * @Route("/websocket/chat", name="app_websocket_chat_message")
     *
     * @param WebSocketEventsDto $inputEvents
     *
     * @PushpinResponse(format="ws-message")
     * @ParamConverter("inputEvents", converter="gamma.web_socket.events", options={"format": "json"})
     * 
     * @return Response
     */
    public function chatMessageAction(WebSocketEventsDTO $inputEvents)
    {
        return $this->get('gamma.pushpin.grip.events_handler')->handleEvents($inputEvents);
    }
}
unit
 php
public function registerBundles()
{
    return array(
        // ...
        new Gamma\Pushpin\PushpinBundle\GammaPushpinBundle()
    );
}