Skip to content

Commit caa1b7a

Browse files
committed
Add configuration file override
1 parent ea5cb9b commit caa1b7a

File tree

2 files changed

+25
-28
lines changed

2 files changed

+25
-28
lines changed

README.md

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -127,48 +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.
149-
150-
**Configuration structure:**
151-
152-
```php
153-
'Mercure' => [
154-
'url' => 'http://localhost:3000/.well-known/mercure',
155-
'public_url' => null, // Optional, defaults to 'url'
156-
'jwt' => [
157-
'secret' => '!ChangeThisMercureHubJWTSecretKey!',
158-
'algorithm' => 'HS256',
159-
'publish' => ['*'],
160-
'subscribe' => ['*'],
161-
],
162-
]
163-
```
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.
164162
165-
The `url` is used by your CakePHP application to publish updates. Set `public_url` when clients need to connect to a different URL (e.g., when using Docker with internal networking).
166-
167-
To customize the configuration, copy the plugin's config file to your application:
168-
169-
```bash
170-
cp vendor/josbeir/cakephp-mercure/config/mercure.php config/mercure.php
171-
```
163+
For a complete list of available environment variables, see the plugin's `config/mercure.php` [file](https://github.com/josbeir/cakephp-mercure/blob/main/config/mercure.php).
172164
173165
## Basic Usage
174166
@@ -397,7 +389,7 @@ Publisher::publish($update);
397389
> **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:
398390
>
399391
> ```php
400-
> // In config/mercure.php
392+
> // In config/app_mercure.php
401393
> return [
402394
> 'Mercure' => [
403395
> '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)