Giter Site home page Giter Site logo

xcorp1986 / sandstone Goto Github PK

View Code? Open in Web Editor NEW

This project forked from eole-io/sandstone

0.0 0.0 0.0 666 KB

PHP microframework designed to build a RestApi working together with a websocket server. Build a real time RestApi!

Home Page: https://eole-io.github.io/sandstone-doc

License: MIT License

PHP 95.92% HTML 3.57% Makefile 0.51%

sandstone's Introduction

Sandstone

Build Status Latest Stable Version Scrutinizer Code Quality SensioLabsInsight License

PHP microframework designed to build a RestApi working together with a websocket server.

Build a real time RestApi!

๐Ÿ’ฌ New (18 April 2018)

I opened a chat channel where you can get help, give feedback, and talk about Sandstone (Mattermost instance):

๐Ÿ’ฌ https://framateam.org/sandstone ๐Ÿ’ฌ

Install

composer require eole/sandstone

Usage

Create a Sandstone application

Sandstone is a Silex application with websockets:

$app = new Eole\Sandstone\Application();

Declare a websocket topic

Similar as declaring a Silex route:

$app->topic('chat/{channel}', function ($topicPattern, $arguments) {
    $channelName = $arguments['channel'];

    return new ChatTopic($topicPattern, $channelName);
});

See ChatTopic class here.

Send push notifications

When an endpoint is called on the RestApi, i.e POST /api/articles and update a resource, you can send a push notification to notify this update.

On the RestApi stack:

use Symfony\Component\HttpFoundation\Response;

$app->post('api/articles', function () use ($app) {
    // Dispatch an event on article creation
    $app['dispatcher']->dispatch('article.created', new ArticleEvent());

    return new Response([], 201);
});

// Send all 'article.created' events to push server
$app->forwardEventToPushServer('article.created');

Then on the websocket stack:

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Eole\Sandstone\Websocket\Topic;

class MyWebsocketTopic extends Topic implements EventSubscriberInterface
{
    public static function getSubscribedEvents()
    {
        return [
            'article.created' => 'onArticleCreated',
        ];
    }

    public function onArticleCreated(ArticleEvent $event)
    {
        $this->broadcast([
            'message' => 'An article has just been published: '.$event->title,
        ]);
    }
}

Examples

Working examples from scratch:

Documentation

See the full documentation here

Sandstone documentation

Sandstone edition

You're planning to start a new real-time Rest Api application based on Sandstone?

You may be interested by Sandstone edition.

It already integrates a Sandstone application with a docker environment, a database, debug tools...

Get started with Sandstone edition.

Misc

Articles about Sandstone:

Big picture: https://eole-io.github.io/sandstone-doc/big-picture

Changelog

See Releases page.

License

This library is under MIT License.

sandstone's People

Contributors

alcalyn avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.