PHP code example of bfg / puller

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

    

bfg / puller example snippets


\Puller::user(Auth::user())
    ->channel('my_test')
    ->stream('Hello world!');



namespace App\Pulls;

use Bfg\Puller\Task;

class MyTestPull extends Task
{
    public function handle () {
        //
    }
}

    public function handle () {
        return "Hello world!";
    }

\App\Pulls\MyTest::user(\Auth::user())
    ->stream();



namespace App\Pulls;

use Bfg\Puller\Task;

class MyTestPull extends Task
{
    protected $user_name;

    public function __construct(string $user_name) {
        $this->user_name = $user_name;
    }

    public function handle () {
        return "Hello, " . $this->user_name;
    }
}

\App\Pulls\MyTest::user(\Auth::user()) // Current auth user set  by default
    ->stream('Administrator');

\App\Pulls\MyTest::flux('Administrator');

\App\Pulls\MyTest::flow('Administrator');
\App\Pulls\MyTest::new()->channel('my_test')->flow('Administrator');

\App\Pulls\MyTest::totab($tabid, 'Administrator');
\App\Pulls\MyTest::new()->channel('my_test')->totab($tabid, 'Administrator');

Event::listen(\Bfg\Puller\Events\UserOnlineEvent::class, function (UserOnlineEvent $event) {
    info("User $event->user_id online");
});

Event::listen(\Bfg\Puller\Events\UserOfflineEvent::class, function (UserOfflineEvent $event) {
    info("User $event->user_id offline");
});

Event::listen(\Bfg\Puller\Events\UserNewTabEvent::class, function (UserNewTabEvent $event) {
    info("User $event->user_id new tab $event->tab");
});

Event::listen(\Bfg\Puller\Events\UserCloseTabEvent::class, function (UserCloseTabEvent $event) {
    info("User $event->user_id close tab $event->tab");
});

\Puller::myTab();

\Puller::new();

\Puller::channel();

\Puller::online();

\Puller::users();

\Puller::isOnlineUser(int $user_id);

\Puller::identifications();

\Puller::onOnline(function (UserOnlineEvent $event) {
    info("User $event->user_id online");
});
\Puller::onOffline(callable);
\Puller::onOnlineAndOffline(callable);
\Puller::onNewTab(callable);
\Puller::onCloseTab(callable);
\Puller::onNewAndCloseTab(callable);

\App\Pulls\MyTest::modelWatchToStream( 
    \App\Modeld\Message::class,
    $events = [] // 'updated', 'created', 'deleted' by default
);
\App\Pulls\MyTest::modelWatchToFlow(
    \App\Modeld\Message::class,
    $events = [] // 'updated', 'created', 'deleted' by default
);
\App\Pulls\MyTest::modelWatchToFlux(
    \App\Modeld\Message::class,
    $events = [] // 'updated', 'created', 'deleted' by default
);
\App\Pulls\MyTest::modelOwnerWatchToStream(
    \App\Modeld\Message::class,
    $owner_field = "user_id",
    $events = [] // 'updated', 'created', 'deleted' by default
);
\App\Pulls\MyTest::modelOwnerWatchToFlow(
    \App\Modeld\Message::class,
    $owner_field = "user_id",
    $events = [] // 'updated', 'created', 'deleted' by default
);
\App\Pulls\MyTest::modelOwnerWatchToFlux(
    \App\Modeld\Message::class,
    $owner_field = "user_id",
    $events = [] // 'updated', 'created', 'deleted' by default
);
// Or
\App\Pulls\MyTest::modelWatchToFlow([
    \App\Modeld\Message::class,
    \App\Modeld\User::class,
]);

\Puller::moveZone('admin', function () {
    \Puller::channel('test')->detail('hi');
    \Puller::channel('test2')->detail('hi2');
    \Puller::channel('test3')->detail('hi3');
})->flux();
bash
php artisan vendor:publish --tag=puller-assets
cli
php artisan make:task MyTestPull
cli
php artisan make:task DarkMode_Toggle
cli
php artisan puller:events