diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..c7742e8 --- /dev/null +++ b/CHANGELOG.md @@ -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 diff --git a/composer.json b/composer.json index b0d7d49..b3ef532 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/config/channels.php.example b/config/channels.php.example new file mode 100644 index 0000000..246166a --- /dev/null +++ b/config/channels.php.example @@ -0,0 +1,26 @@ +id === $userId; +}); + +Broadcasting::channel('private-App.Model.Entity.User.{userId}', function ($user, $userId) { + if (!$user) { + return false; + } + + return (string)$user->id === $userId; +}); diff --git a/docs/index.md b/docs/index.md index 0ba433b..8c28ccc 100644 --- a/docs/index.md +++ b/docs/index.md @@ -66,9 +66,31 @@ By default, CakePHP includes four server-side broadcasting drivers for you to ch ## 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 @@ -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: diff --git a/src/BroadcastingPlugin.php b/src/BroadcastingPlugin.php index 6b45efe..11650f3 100644 --- a/src/BroadcastingPlugin.php +++ b/src/BroadcastingPlugin.php @@ -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. * @@ -60,4 +66,32 @@ function (RouteBuilder $builder): void { ); parent::routes($routes); } + + /** + * Get the manifest for the plugin. + * + * @return array> + */ + 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'), + ); + } }