Skip to content

Commit b923d57

Browse files
committed
feat: ✨ Added ability to specify the cookie name prefix
- Standardized the PHPDoc
1 parent 9029215 commit b923d57

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

src/Flarum.php

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,31 @@ class Flarum
3737
/** @var bool Verify SSL cert. More details on https://docs.guzzlephp.org/en/stable/request-options.html#verify */
3838
public $verify;
3939

40+
/** @var string */
41+
public $cookies_prefix;
42+
4043
/** @var User|null */
4144
private $user;
4245

4346
/**
4447
* Flarum constructor
4548
*
46-
* @param array $config {
47-
* @type string $url Flarum URL
48-
* @type string $root_domain Main site or SSO system domain
49-
* @type string $api_key Random key from the api_keys table of your Flarum forum
50-
* @type string $password_token Random token to create passwords
51-
* @type bool $remember Should the login be remembered (this equals to 5 years remember from last usage)? If false, token will be remembered only for 1 hour. Default: false
52-
* @type bool|string $verify_ssl Verify SSL cert. More details on https://docs.guzzlephp.org/en/stable/request-options.html#verify. Default: true
53-
* }
49+
* @param array{
50+
* url: string,
51+
* root_domain: string,
52+
* api_key: string,
53+
* password_token: string,
54+
* remember: bool,
55+
* verify_ssl: bool|string,
56+
* cookies_prefix: string
57+
* } $config Options array. It accepts the following elements:
58+
* - url: string - Flarum URL
59+
* - root_domain: string - Main site or SSO system domain
60+
* - pai_key: string - Random key from the api_keys table of your Flarum forum
61+
* - password_token: string - Random token to create passwords
62+
* - remember: bool - Should the login be remembered (this equals to 5 years remember from last usage)? If false, token will be remembered only for 1 hour. Default: false
63+
* - verify_ssl: bool|string - Verify SSL cert. More details on https://docs.guzzlephp.org/en/stable/request-options.html#verify. Default: true
64+
* - cookies_prefix: string - String to prefix the cookie name when creating remember/auth tokens. Default: "flarum"
5465
*/
5566
public function __construct(array $config)
5667
{
@@ -77,6 +88,8 @@ public function __construct(array $config)
7788

7889
$this->remember = Arr::get($config, 'remember', false);
7990

91+
$this->cookies_prefix = Arr::get($config, 'cookies_prefix', 'flarum');
92+
8093
$this->initAddons();
8194
}
8295

src/Traits/Cookies.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function generateCookie(string $name, string $value = null, Carbon $expir
3030
$expiry = Carbon::now();
3131
}
3232

33-
return (new Cookie("flarum_$name"))
33+
return (new Cookie("{$this->cookies_prefix}_$name"))
3434
->setDomain($this->root_domain)
3535
->setSecureOnly($this->verify)
3636
->setValue($value)

0 commit comments

Comments
 (0)