-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Task] Introduce lifetime and hubservice (#236)
* Introduce lifetime and hubservice * Apply php-cs-fixer changes * Add doc --------- Co-authored-by: mattamon <[email protected]>
- Loading branch information
Showing
8 changed files
with
132 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license GPLv3 and PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\StudioBackendBundle\Mercure\Service; | ||
|
||
use Pimcore\Bundle\StudioBackendBundle\Mercure\Util\Constants\Mercure; | ||
use Symfony\Component\HttpFoundation\Cookie; | ||
use Symfony\Component\Mercure\HubInterface; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final readonly class HubService implements HubServiceInterface | ||
{ | ||
public function __construct( | ||
private HubInterface $clientHub, | ||
private int $cookieLifetime = 3600 | ||
) { | ||
} | ||
|
||
public function createCookie(): Cookie | ||
{ | ||
$urlParts = parse_url($this->clientHub->getPublicUrl()); | ||
|
||
return new Cookie( | ||
Mercure::AUTHORIZATION_COOKIE_NAME->value, | ||
$this->clientHub->getProvider()->getJwt(), | ||
time() + $this->cookieLifetime, | ||
$urlParts[Mercure::URL_PATH->value] ?? '/', | ||
$urlParts[Mercure::URL_HOST->value] ?? '', | ||
$urlParts[Mercure::URL_SCHEME->value] === Mercure::URL_SCHEME_HTTPS->value, | ||
true, | ||
false, | ||
Cookie::SAMESITE_STRICT | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license GPLv3 and PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\StudioBackendBundle\Mercure\Service; | ||
|
||
use Symfony\Component\HttpFoundation\Cookie; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
interface HubServiceInterface | ||
{ | ||
public function createCookie(): Cookie; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license GPLv3 and PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\StudioBackendBundle\Mercure\Util\Constants; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
enum Mercure: string | ||
{ | ||
case AUTHORIZATION_COOKIE_NAME = 'mercureAuthorization'; | ||
case URL_PATH = 'path'; | ||
case URL_HOST = 'host'; | ||
case URL_SCHEME = 'scheme'; | ||
case URL_SCHEME_HTTPS = 'https'; | ||
} |