2017 © Pedro Peláez
 

cakephp-plugin ratchet-model-push

Allows models to push data on write operations to wyrihaximus/ratchet.

image

wyrihaximus/ratchet-model-push

Allows models to push data on write operations to wyrihaximus/ratchet.

  • Sunday, March 13, 2016
  • by WyriHaximus
  • Repository
  • 2 Watchers
  • 2 Stars
  • 46,843 Installations
  • PHP
  • 0 Dependents
  • 1 Suggesters
  • 1 Forks
  • 0 Open issues
  • 2 Versions
  • 9 % Grown

The README.md

RatchetModelPush

Build Status Latest Stable Version Total Downloads Code Coverage License PHP 7 ready, (*1)

Model Push for the CakePHP Ratchet plugin., (*2)

What is Ratchet

Ratchet for CakePHP brings the Ratchet websocket server to CakePHP. Websockets allow you to utilize near-real-time communication between your application and it's visitors. For example notifying a page the associated record in the database has been updated using the Pushable behaviour., (*3)

Getting started

1. Requirements

This plugin depends on the following plugins and their dependencies and are pulled in by composer later on:, (*4)

2. Composer

Make sure you have composer installed and configured with the autoloader registering during bootstrap as described here. Make sure you have a composer.json and add the following to your required section., (*5)

composer require wyrihaximus/ratchet-model-push 

When you've set everything up, run composer install., (*6)

3. Setup the plugin

Make sure you load RatchetModelPush and all the plugins it depends on and their dependecies in your bootstrap and set then up properly., (*7)

4. Setting up the behavior

The following code example attaches the Pushable behavior to the WyriProject model. The events do the following in order:, (*8)

  1. Fires on creating on a new record and binds to WyriProject.created.
  2. Fires on updating any record and binds to WyriProject.updated.
  3. Fires on any updating record and binds to WyriProject.updated.{id} where {id} is the id for that record. So if id is 1 it binds to WyriProject.updated.1.

The data is passed into the event as a 1 dimensional array., (*9)

<?php

class Model extends AppModel {
    public $actsAs = array(
        'RatchetModelPush.Pushable' => array(
            'events' => array(
                array(
                    'eventName' => 'WyriProject.created',
                    'created' => true,
                ),
                array(
                    'eventName' => 'WyriProject.updated',
                    'created' => false,
                ),
                array(
                    'eventName' => 'WyriProject.updated.{id}',
                    'created' => false,
                    'fields' => true,
                ),
            ),
        ), 
    );
}

5. Client side

On the client side the only thing required is subscribing to the event:, (*10)

cakeWamp.subscribe('Rachet.WampServer.ModelUpdate.WyriProject.updated.1', function(topicUri, event) {
    // Do your stuff with the data
});

Note: the actual event you're subscribing to is prefixed by *Rachet.WampServer.ModelUpdate..*, (*11)

Make sure to include the JavaScript file and its dependencies in your view:, (*12)

echo $this->Html->script(array(
    'Ratchet.when/when',
    'Ratchet.autobahn/autobahn',
    'Ratchet.cake-wamp'
));

Plugin License

(The MIT License), (*13)

Copyright © 2012 - 2013 Cees-Jan Kiewiet, (*14)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:, (*15)

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software., (*16)

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE., (*17)

The Versions

13/03 2016

dev-master

9999999-dev

Allows models to push data on write operations to wyrihaximus/ratchet.

  Sources   Download

MIT

The Requires

 

The Development Requires

cakephp ratchet

22/01 2015

0.1.0

0.1.0.0 http://github.com/WyriHaximus/RatchetModelPush

Allows models to push data on write operations to wyrihaximus/ratchet.

  Sources   Download

MIT

The Requires

 

cakephp ratchet