Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0.1]

### Added

- Plugin manifest integration for automated configuration installation
- `manifest()` method to `BroadcastingPlugin` implementing `ManifestInterface`
- Automatic installation of `config/broadcasting.php` configuration file
- Automatic installation of `config/channels.php` file from example template
- Automatic bootstrap file configuration loading
- GitHub star repository prompt support

### Changed

- Plugin now uses manifest system for configuration setup
- Configuration files are installed via `bin/cake manifest install --plugin Crustum/Broadcasting`

## [1.0.0]

### Added

- Core broadcasting system for WebSocket-based real-time event broadcasting with support for public, private, presence, and encrypted private channels
- Multiple broadcaster drivers (Pusher Channels, Redis, Log, Null) with queue adapter system for async broadcasting
- Channel authorization system with callbacks and channel classes, plus authentication controller and routes
- Model broadcasting behavior for automatic entity event broadcasting, with conditional and queueable interfaces
- Testing utilities with BroadcastingTrait for comprehensive test assertions
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"cakephp/authentication": "*",
"cakephp/authorization": "*",
"cakephp/queue": "^2.2",
"crustum/plugin-manifest": "^1.0",
"firebase/php-jwt": "^6.11",
"guzzlehttp/psr7": "^2.6",
"pusher/pusher-php-server": "^7.2",
Expand Down
26 changes: 26 additions & 0 deletions config/channels.php.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
declare(strict_types=1);

/**
* Default channel authorization configuration
*
* This file defines channel authorization rules using Broadcasting::channel().
*/

use Crustum\Broadcasting\Broadcasting;

Broadcasting::channel('private-users.{userId}', function ($user, $userId) {
if (!$user) {
return false;
}

return (string)$user->id === $userId;
});

Broadcasting::channel('private-App.Model.Entity.User.{userId}', function ($user, $userId) {
if (!$user) {
return false;
}

return (string)$user->id === $userId;
});
31 changes: 26 additions & 5 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,31 @@ By default, CakePHP includes four server-side broadcasting drivers for you to ch
<a name="quickstart"></a>
## Quickstart

By default, broadcasting is not enabled in new CakePHP applications. You may enable broadcasting by configuring the Broadcasting plugin and setting up your broadcasting drivers.
### Installing the Plugin

First, load the Broadcasting plugin in your `Application.php`:
Install via Composer:

```bash
composer require crustum/broadcasting
```

> [!NOTE]
> This plugin should be registered in your `config/plugins.php` file.

```bash
bin/cake plugin load Crustum/Broadcasting
```

> [!TIP]
> **After the plugin registers itself**, it's recommended to install the configuration with the manifest system:

```bash
bin/cake manifest install --plugin Crustum/Broadcasting
```

The Broadcasting plugin will create the `config/broadcasting.php` configuration file and the `config/channels.php` file where you may register your application's broadcast authorization routes and callbacks. Additionally, it will copy the migrations to the application's migrations directory and append the loading of the `config/broadcasting.php` file to the `config/bootstrap.php` file.

Alternatively, you can load the plugin in your `Application.php`:

```php
// In src/Application.php
Expand All @@ -79,10 +101,9 @@ public function bootstrap(): void
$this->addPlugin('Crustum/Broadcasting');
}
```
This will enable broadcasting by configuring the Broadcasting plugin and setting up your broadcasting drivers.

The Broadcasting plugin will create the `config/broadcasting.php` configuration file and the `config/channels.php` file where you may register your application's broadcast authorization routes and callbacks.

CakePHP supports several broadcast drivers out of the box: [Pusher Channels](https://pusher.com/channels), Redis, and a `log` driver for local development and debugging. Additionally, a `null` driver is included which allows you to disable broadcasting during testing. A configuration example is included for each of these drivers in the `config/broadcasting.php` configuration file.
Plugin supports several broadcast drivers out of the box: [Pusher Channels](https://pusher.com/channels), Redis, and a `log` driver for local development and debugging. Additionally, a `null` driver is included which allows you to disable broadcasting during testing. A configuration example is included for each of these drivers in the `config/broadcasting.php` configuration file.

All of your application's event broadcasting configuration is stored in the `config/broadcasting.php` configuration file:

Expand Down
36 changes: 35 additions & 1 deletion src/BroadcastingPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@
use Cake\Core\PluginApplicationInterface;
use Cake\Routing\RouteBuilder;
use Crustum\Broadcasting\Command\ChannelCommand;
use Crustum\PluginManifest\Manifest\ManifestInterface;
use Crustum\PluginManifest\Manifest\ManifestTrait;

/**
* Plugin for Broadcasting
*
* @uses \Crustum\PluginManifest\Manifest\ManifestTrait
*/
class BroadcastingPlugin extends BasePlugin
class BroadcastingPlugin extends BasePlugin implements ManifestInterface
{
use ManifestTrait;

/**
* Load all the plugin configuration and bootstrap logic.
*
Expand Down Expand Up @@ -60,4 +66,32 @@ function (RouteBuilder $builder): void {
);
parent::routes($routes);
}

/**
* Get the manifest for the plugin.
*
* @return array<int, array<string, mixed>>
*/
public static function manifest(): array
{
$pluginPath = dirname(__DIR__);

return array_merge(
static::manifestConfig(
$pluginPath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'broadcasting.php',
CONFIG . 'broadcasting.php',
false,
),
static::manifestConfig(
$pluginPath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'channels.php.example',
CONFIG . 'channels.php',
false,
),
static::manifestBootstrapAppend(
"if (file_exists(CONFIG . 'broadcasting.php')) {\n Configure::load('broadcasting', 'default');\n}",
'// Broadcasting Plugin Configuration',
),
static::manifestStarRepo('Crustum/Broadcasting'),
);
}
}