2017 © Pedro Peláez
 

library pupper-php

PHP components for Pupper

image

pupper/pupper-php

PHP components for Pupper

  • Wednesday, December 20, 2017
  • by bouiboui
  • Repository
  • 1 Watchers
  • 13 Stars
  • 44 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 9 Versions
  • 0 % Grown

The README.md

d005d89e-ff25-4450-9119-aa56ff0d8949, (*1)

Codacy Badge Software License SensioLabsInsight, (*2)

Pupper stands for "PHP Plus React" (PPR > Pupper). The goal is to make a Framework that takes the best of both technologies and makes them communicate bi-directionnaly., (*3)

See an example implementation, (*4)

Quick start

Pupper PHP is based on Aerys, a non-blocking PHP application and Websocket framework., (*5)

Here is a quick overview of the code to get started., (*6)

use Pupper\Pupper\Event;

// Initiates WebSocket connection
$websocket = (new Pupper\Pupper\WebSocket)

    // Filter allowed clients (optional)
    ->allowOrigin('https', 'your.domain.com', 443);

    // Defines a callback for 'my_event'
    ->addEventListener('my_event', function (Event $event) {

        // Dispatches to all clients
        $websocket->broadcastEvent(
            new Event('notify_all', 'Something has happened!');
        );

        // Dispatches to the client that triggered the callback
        return (new Event)
            ->setName('operation_done')
            ->setValue('Your value was ' . $event->getValue());

    });

$router = Aerys\router()->route('GET', '/', Aerys\websocket($websocket));

// Exposes the websocket to the 1337 port
return (new Aerys\Host)->use($router)->expose('*', 1337);

API

WebSocket

WebSocket is the class that initiates the WebSocket on the PHP side., (*7)

addListener, (*8)

addListener takes the event name as first parameter, and a callback function as a second parameter., (*9)

If you return an Event, it will be dispatched to the client that triggered the callback., (*10)

use Pupper\Pupper\Event;

$websocket = (new Pupper\Pupper\WebSocket)
    ->addEventListener('custom', function (Event $event) {
        return (new Event)
            ->setName('custom')
            ->setValue('From PHP: ' . $event->getValue());
    });

broadcastEvent, (*11)

broadcastEvent dispatches an event to all the clients., (*12)

use Pupper\Pupper\Event;

$websocket = (new Pupper\Pupper\WebSocket)
    ->addEventListener('player_has_joined', function (Event $event) {
        $websocket->broadcastEvent(
            'player_count_updated',
            'A new player has joined!'
        );
    });

Client filtering, (*13)

Set WebSocket's constructor's protocol, host and port parameters to restrict the access to your websocket ., (*14)

$websocket = (new \Pupper\WebSocket)->allowOrigin('https', 'your.domain.com', 80);

Event

Event represents an event from the PHP side., (*15)

Read, (*16)

Event has getName() and getValue() methods to read the event's name and value., (*17)

use Pupper\Pupper\Event;

function (Event $event) {
    echo $event->getName();
    echo $event->getValue();
});

Write, (*18)

Event has setName() and setValue() methods to write the event's name and value., (*19)

use Pupper\Pupper\Event;

$event = (new Event)
    ->setName('hello_event')
    ->setValue('Hello from PHP!');

Construct, (*20)

Event's constructor also accepts the event's name and value as parameters., (*21)

use Pupper\Pupper\Event;

$event = new Event(
    'hello_event', 
    'Hello from PHP!'
);

Credits

License

Unlicense. Please see License File for more information., (*22)

The Versions

20/12 2017

dev-master

9999999-dev

PHP components for Pupper

  Sources   Download

Unlicense

The Requires

 

30/10 2017

dev-dependabot/composer/amphp/aerys-0.7.2

dev-dependabot/composer/amphp/aerys-0.7.2

PHP components for Pupper

  Sources   Download

Unlicense

The Requires

 

23/10 2017

0.3.2

0.3.2.0

PHP components for Pupper

  Sources   Download

Unlicense

The Requires

 

23/10 2017

0.3.1

0.3.1.0

PHP components for Pupper

  Sources   Download

Unlicense

The Requires

 

23/10 2017

0.3.0

0.3.0.0

PHP components for Pupper

  Sources   Download

Unlicense

The Requires

 

21/10 2017

0.2.3

0.2.3.0

PHP components for Pupper

  Sources   Download

Unlicense

The Requires

 

21/10 2017

0.2.2

0.2.2.0

PHP components for Pupper

  Sources   Download

Unlicense

The Requires

 

19/10 2017

0.2.1

0.2.1.0

PHP components for Pupper

  Sources   Download

Unlicense

The Requires

 

19/10 2017

0.2.0

0.2.0.0

PHP components for Pupper

  Sources   Download

Unlicense

The Requires