Skip to content

Commit 7b4226f

Browse files
committed
Add configuration file override
1 parent ea5cb9b commit 7b4226f

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

README.md

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,25 +127,40 @@ The hub will be available at `http://localhost:3000/.well-known/mercure`.
127127

128128
## Configuration
129129

130-
The plugin includes a default configuration file with all available options. The configuration is automatically loaded from the plugin's `config/mercure.php` file.
130+
The plugin comes with sensible defaults and multiple configuration options.
131131

132-
Set the required environment variables in your `.env` file:
132+
**Quick Setup (Environment Variables):**
133+
134+
For development, the fastest way to get started is using environment variables in your `.env` file:
133135

134136
```env
135137
MERCURE_URL=http://localhost:3000/.well-known/mercure
136138
MERCURE_PUBLIC_URL=http://localhost:3000/.well-known/mercure
137139
MERCURE_JWT_SECRET=!ChangeThisMercureHubJWTSecretKey!
138140
```
139141

142+
**Configuration Files:**
143+
144+
The plugin loads configuration in this order:
145+
146+
1. **Plugin defaults** - `vendor/josbeir/cakephp-mercure/config/mercure.php` (loaded automatically)
147+
2. **Your overrides** - `config/app_mercure.php` (optional, loaded after plugin defaults)
148+
149+
Create `config/app_mercure.php` in your project to customize any settings. Your values will override the plugin defaults.
150+
151+
**Cross-Subdomain Setup:**
152+
140153
> [!NOTE]
141-
> If your Mercure hub is running on a different subdomain than your CakePHP application, you need to set the cookie domain to the top-level domain:
154+
> If your Mercure hub runs on a different subdomain than your CakePHP application (e.g., `hub.example.com` vs `app.example.com`), you must configure the cookie domain:
142155
>
143156
> ```env
144-
> # For cross-subdomain authorization
157+
> # Allow cookie sharing across subdomains
145158
> MERCURE_COOKIE_DOMAIN=.example.com
146159
> ```
147160
>
148-
> This allows the authorization cookie to be accessible by both your application and the Mercure hub when they are on different subdomains of the same parent domain.
161+
> This enables the authorization cookie to be accessible by both your application and the Mercure hub. Without this setting, authorization will fail for cross-subdomain requests.
162+
163+
For a complete list of available environment variables, see the plugin's `config/mercure.php` file.
149164
150165
**Configuration structure:**
151166
@@ -397,7 +412,7 @@ Publisher::publish($update);
397412
> **View Class Configuration:** By default, `ViewUpdate` uses CakePHP's automatic view class selection (your `AppView` if it exists, otherwise the base `View` class). You can override this by setting `view_class` in your configuration:
398413
>
399414
> ```php
400-
> // In config/mercure.php
415+
> // In config/app_mercure.php
401416
> return [
402417
> 'Mercure' => [
403418
> 'view_class' => \App\View\CustomView::class,

src/MercurePlugin.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ public function bootstrap(PluginApplicationInterface $app): void
2626

2727
// Load plugin configuration
2828
Configure::load('Mercure.mercure');
29+
30+
// Load app specific config file.
31+
if (file_exists(ROOT . DS . 'config' . DS . 'app_mercure.php')) {
32+
Configure::load('app_mercure');
33+
}
2934
}
3035

3136
/**

0 commit comments

Comments
 (0)