PHP Classes

File: test/Helpers/SocketTestMessage.php

Recommend this page to a friend!
  Classes of Artur Graniszewski   ZEUS for PHP   test/Helpers/SocketTestMessage.php   Download  
File: test/Helpers/SocketTestMessage.php
Role: Unit test script
Content type: text/plain
Description: Unit test script
Class: ZEUS for PHP
Manage the execution of multiple parallel tasks
Author: By
Last change: Improvements to Socket Server, moved network layer to Kernel and used SocketStream in FIFO IPC
Date: 6 years ago
Size: 1,834 bytes
 

Contents

Class file image Download
<?php

namespace ZeusTest\Helpers;

use
Zeus\Kernel\Networking\ConnectionInterface;
use
Zeus\ServerService\Shared\Networking\MessageComponentInterface;
use
Zeus\ServerService\Shared\Networking\HeartBeatMessageInterface;

class
SocketTestMessage implements MessageComponentInterface, HeartBeatMessageInterface
{
    protected
$readCallback;
   
/**
     * @var
     */
   
private $heartBeatCallback;

    public function
__construct($readCallback, $heartBeatCallback = null)
    {
       
$this->readCallback = $readCallback;
       
$this->heartBeatCallback = $heartBeatCallback;
    }

   
/**
     * @param \Zeus\Kernel\Networking\ConnectionInterface $connection
     * @throws \Exception
     */
   
function onOpen(ConnectionInterface $connection)
    {
       
// TODO: Implement onOpen() method.
   
}

   
/**
     * @param \Zeus\Kernel\Networking\ConnectionInterface $connection
     * @throws \Exception
     */
   
function onClose(ConnectionInterface $connection)
    {
       
// TODO: Implement onClose() method.
   
}

   
/**
     * @param ConnectionInterface $connection
     * @param \Exception $exception
     * @throws \Exception
     */
   
function onError(ConnectionInterface $connection, $exception)
    {
       
// TODO: Implement onError() method.
   
}

   
/**
     * @param ConnectionInterface $connection
     * @param string $message
     * @throws \Exception
     */
   
function onMessage(ConnectionInterface $connection, $message)
    {
       
call_user_func($this->readCallback, $connection, $message);
    }

    public function
onHeartBeat(ConnectionInterface $connection, $data = null)
    {
       
$callback = $this->heartBeatCallback ? $this->heartBeatCallback : function() {};

       
$callback($connection, $data);
    }
}