-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce
DirectiveSetBuilderInterface
to allow runtime modification
- Loading branch information
Showing
7 changed files
with
222 additions
and
27 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
src/ContentSecurityPolicy/ConfigurationDirectiveSetBuilder.php
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,63 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Nelmio SecurityBundle. | ||
* | ||
* (c) Nelmio <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Nelmio\SecurityBundle\ContentSecurityPolicy; | ||
|
||
class ConfigurationDirectiveSetBuilder implements DirectiveSetBuilderInterface | ||
{ | ||
private PolicyManager $policyManager; | ||
|
||
/** | ||
* @phpstan-var array{ | ||
* enforce?: array<string, mixed>, | ||
* report?: array<string, mixed>, | ||
* } $config | ||
*/ | ||
private array $config; | ||
|
||
/** | ||
* @phpstan-var 'enforce'|'report' $kind | ||
*/ | ||
private string $kind; | ||
|
||
/** | ||
* @phpstan-param array{ | ||
* enforce?: array<string, mixed>, | ||
* report?: array<string, mixed>, | ||
* } $config | ||
* @phpstan-param 'enforce'|'report' $kind | ||
*/ | ||
public function __construct(PolicyManager $policyManager, array $config, string $kind) | ||
{ | ||
$this->policyManager = $policyManager; | ||
$this->config = $config; | ||
$this->kind = $kind; | ||
} | ||
|
||
public function buildDirectiveSet(): DirectiveSet | ||
{ | ||
return DirectiveSet::fromConfig($this->policyManager, $this->config, $this->kind); | ||
} | ||
|
||
/** | ||
* @phpstan-param array{ | ||
* enforce?: array<string, mixed>, | ||
* report?: array<string, mixed>, | ||
* } $config | ||
* @phpstan-param 'enforce'|'report' $kind | ||
*/ | ||
public static function create(PolicyManager $policyManager, array $config, string $kind): self | ||
{ | ||
return new self($policyManager, $config, $kind); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/ContentSecurityPolicy/DirectiveSetBuilderInterface.php
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,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Nelmio SecurityBundle. | ||
* | ||
* (c) Nelmio <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Nelmio\SecurityBundle\ContentSecurityPolicy; | ||
|
||
interface DirectiveSetBuilderInterface | ||
{ | ||
public function buildDirectiveSet(): DirectiveSet; | ||
} |
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,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Nelmio SecurityBundle. | ||
* | ||
* (c) Nelmio <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Nelmio\SecurityBundle\ContentSecurityPolicy; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
class LegacyDirectiveSetBuilder implements DirectiveSetBuilderInterface | ||
{ | ||
private DirectiveSet $directiveSet; | ||
|
||
public function __construct(DirectiveSet $directiveSet) | ||
{ | ||
$this->directiveSet = $directiveSet; | ||
} | ||
|
||
public function buildDirectiveSet(): DirectiveSet | ||
{ | ||
return clone $this->directiveSet; | ||
} | ||
} |
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