@@ -32,10 +32,10 @@ |
||
32 | 32 | */ |
33 | 33 | class UnsupportedLimitOnInitialSyncException extends InsufficientStorage { |
34 | 34 | |
35 | - /** |
|
36 | - * @inheritDoc |
|
37 | - */ |
|
38 | - public function serialize(Server $server, \DOMElement $errorNode) { |
|
39 | - $errorNode->appendChild($errorNode->ownerDocument->createElementNS('DAV:', 'd:number-of-matches-within-limits')); |
|
40 | - } |
|
35 | + /** |
|
36 | + * @inheritDoc |
|
37 | + */ |
|
38 | + public function serialize(Server $server, \DOMElement $errorNode) { |
|
39 | + $errorNode->appendChild($errorNode->ownerDocument->createElementNS('DAV:', 'd:number-of-matches-within-limits')); |
|
40 | + } |
|
41 | 41 | } |
@@ -42,45 +42,45 @@ |
||
42 | 42 | * @deprecated 17.0.0 |
43 | 43 | */ |
44 | 44 | class StrictContentSecurityPolicy extends EmptyContentSecurityPolicy { |
45 | - /** @var bool Whether inline JS snippets are allowed */ |
|
46 | - protected $inlineScriptAllowed = false; |
|
47 | - /** @var bool Whether eval in JS scripts is allowed */ |
|
48 | - protected $evalScriptAllowed = false; |
|
49 | - /** @var array Domains from which scripts can get loaded */ |
|
50 | - protected $allowedScriptDomains = [ |
|
51 | - '\'self\'', |
|
52 | - ]; |
|
53 | - /** @var bool Whether inline CSS is allowed */ |
|
54 | - protected $inlineStyleAllowed = false; |
|
55 | - /** @var array Domains from which CSS can get loaded */ |
|
56 | - protected $allowedStyleDomains = [ |
|
57 | - '\'self\'', |
|
58 | - ]; |
|
59 | - /** @var array Domains from which images can get loaded */ |
|
60 | - protected $allowedImageDomains = [ |
|
61 | - '\'self\'', |
|
62 | - 'data:', |
|
63 | - 'blob:', |
|
64 | - ]; |
|
65 | - /** @var array Domains to which connections can be done */ |
|
66 | - protected $allowedConnectDomains = [ |
|
67 | - '\'self\'', |
|
68 | - ]; |
|
69 | - /** @var array Domains from which media elements can be loaded */ |
|
70 | - protected $allowedMediaDomains = [ |
|
71 | - '\'self\'', |
|
72 | - ]; |
|
73 | - /** @var array Domains from which object elements can be loaded */ |
|
74 | - protected $allowedObjectDomains = []; |
|
75 | - /** @var array Domains from which iframes can be loaded */ |
|
76 | - protected $allowedFrameDomains = []; |
|
77 | - /** @var array Domains from which fonts can be loaded */ |
|
78 | - protected $allowedFontDomains = [ |
|
79 | - '\'self\'', |
|
80 | - ]; |
|
81 | - /** @var array Domains from which web-workers and nested browsing content can load elements */ |
|
82 | - protected $allowedChildSrcDomains = []; |
|
45 | + /** @var bool Whether inline JS snippets are allowed */ |
|
46 | + protected $inlineScriptAllowed = false; |
|
47 | + /** @var bool Whether eval in JS scripts is allowed */ |
|
48 | + protected $evalScriptAllowed = false; |
|
49 | + /** @var array Domains from which scripts can get loaded */ |
|
50 | + protected $allowedScriptDomains = [ |
|
51 | + '\'self\'', |
|
52 | + ]; |
|
53 | + /** @var bool Whether inline CSS is allowed */ |
|
54 | + protected $inlineStyleAllowed = false; |
|
55 | + /** @var array Domains from which CSS can get loaded */ |
|
56 | + protected $allowedStyleDomains = [ |
|
57 | + '\'self\'', |
|
58 | + ]; |
|
59 | + /** @var array Domains from which images can get loaded */ |
|
60 | + protected $allowedImageDomains = [ |
|
61 | + '\'self\'', |
|
62 | + 'data:', |
|
63 | + 'blob:', |
|
64 | + ]; |
|
65 | + /** @var array Domains to which connections can be done */ |
|
66 | + protected $allowedConnectDomains = [ |
|
67 | + '\'self\'', |
|
68 | + ]; |
|
69 | + /** @var array Domains from which media elements can be loaded */ |
|
70 | + protected $allowedMediaDomains = [ |
|
71 | + '\'self\'', |
|
72 | + ]; |
|
73 | + /** @var array Domains from which object elements can be loaded */ |
|
74 | + protected $allowedObjectDomains = []; |
|
75 | + /** @var array Domains from which iframes can be loaded */ |
|
76 | + protected $allowedFrameDomains = []; |
|
77 | + /** @var array Domains from which fonts can be loaded */ |
|
78 | + protected $allowedFontDomains = [ |
|
79 | + '\'self\'', |
|
80 | + ]; |
|
81 | + /** @var array Domains from which web-workers and nested browsing content can load elements */ |
|
82 | + protected $allowedChildSrcDomains = []; |
|
83 | 83 | |
84 | - /** @var array Domains which can embed this Nextcloud instance */ |
|
85 | - protected $allowedFrameAncestors = []; |
|
84 | + /** @var array Domains which can embed this Nextcloud instance */ |
|
85 | + protected $allowedFrameAncestors = []; |
|
86 | 86 | } |
@@ -31,50 +31,50 @@ |
||
31 | 31 | */ |
32 | 32 | interface IRoom { |
33 | 33 | |
34 | - /** |
|
35 | - * Get a unique ID for the room |
|
36 | - * |
|
37 | - * This id has to be unique within the backend |
|
38 | - * |
|
39 | - * @return string |
|
40 | - * @since 14.0.0 |
|
41 | - */ |
|
42 | - public function getId():string; |
|
34 | + /** |
|
35 | + * Get a unique ID for the room |
|
36 | + * |
|
37 | + * This id has to be unique within the backend |
|
38 | + * |
|
39 | + * @return string |
|
40 | + * @since 14.0.0 |
|
41 | + */ |
|
42 | + public function getId():string; |
|
43 | 43 | |
44 | - /** |
|
45 | - * Get the display name for the room |
|
46 | - * |
|
47 | - * @return string |
|
48 | - * @since 14.0.0 |
|
49 | - */ |
|
50 | - public function getDisplayName():string; |
|
44 | + /** |
|
45 | + * Get the display name for the room |
|
46 | + * |
|
47 | + * @return string |
|
48 | + * @since 14.0.0 |
|
49 | + */ |
|
50 | + public function getDisplayName():string; |
|
51 | 51 | |
52 | - /** |
|
53 | - * Get a list of groupIds that are allowed to access this room |
|
54 | - * |
|
55 | - * If an empty array is returned, no group restrictions are |
|
56 | - * applied. |
|
57 | - * |
|
58 | - * @return string[] |
|
59 | - * @since 14.0.0 |
|
60 | - */ |
|
61 | - public function getGroupRestrictions():array; |
|
52 | + /** |
|
53 | + * Get a list of groupIds that are allowed to access this room |
|
54 | + * |
|
55 | + * If an empty array is returned, no group restrictions are |
|
56 | + * applied. |
|
57 | + * |
|
58 | + * @return string[] |
|
59 | + * @since 14.0.0 |
|
60 | + */ |
|
61 | + public function getGroupRestrictions():array; |
|
62 | 62 | |
63 | - /** |
|
64 | - * Get the email-address for the room |
|
65 | - * |
|
66 | - * The email-address has to be globally unique |
|
67 | - * |
|
68 | - * @return string |
|
69 | - * @since 14.0.0 |
|
70 | - */ |
|
71 | - public function getEMail():string; |
|
63 | + /** |
|
64 | + * Get the email-address for the room |
|
65 | + * |
|
66 | + * The email-address has to be globally unique |
|
67 | + * |
|
68 | + * @return string |
|
69 | + * @since 14.0.0 |
|
70 | + */ |
|
71 | + public function getEMail():string; |
|
72 | 72 | |
73 | - /** |
|
74 | - * Get corresponding backend object |
|
75 | - * |
|
76 | - * @return IBackend |
|
77 | - * @since 14.0.0 |
|
78 | - */ |
|
79 | - public function getBackend():IBackend; |
|
73 | + /** |
|
74 | + * Get corresponding backend object |
|
75 | + * |
|
76 | + * @return IBackend |
|
77 | + * @since 14.0.0 |
|
78 | + */ |
|
79 | + public function getBackend():IBackend; |
|
80 | 80 | } |
@@ -35,84 +35,84 @@ |
||
35 | 35 | */ |
36 | 36 | interface IResourceMetadata { |
37 | 37 | |
38 | - /** |
|
39 | - * Type of resource |
|
40 | - * |
|
41 | - * Allowed values for this key include: |
|
42 | - * - projector |
|
43 | - * - tv |
|
44 | - * - vehicle |
|
45 | - * - other |
|
46 | - * |
|
47 | - * @since 17.0.0 |
|
48 | - */ |
|
49 | - public const RESOURCE_TYPE = '{http://nextcloud.com/ns}resource-type'; |
|
38 | + /** |
|
39 | + * Type of resource |
|
40 | + * |
|
41 | + * Allowed values for this key include: |
|
42 | + * - projector |
|
43 | + * - tv |
|
44 | + * - vehicle |
|
45 | + * - other |
|
46 | + * |
|
47 | + * @since 17.0.0 |
|
48 | + */ |
|
49 | + public const RESOURCE_TYPE = '{http://nextcloud.com/ns}resource-type'; |
|
50 | 50 | |
51 | - /** |
|
52 | - * If resource is of type vehicle, this describes the type of vehicle |
|
53 | - * |
|
54 | - * Allowed values: |
|
55 | - * - bicycle |
|
56 | - * - scooter |
|
57 | - * - motorbike |
|
58 | - * - car |
|
59 | - * - plane |
|
60 | - * - helicopter |
|
61 | - * - other |
|
62 | - * |
|
63 | - * @since 17.0.0 |
|
64 | - */ |
|
65 | - public const VEHICLE_TYPE = '{http://nextcloud.com/ns}resource-vehicle-type'; |
|
51 | + /** |
|
52 | + * If resource is of type vehicle, this describes the type of vehicle |
|
53 | + * |
|
54 | + * Allowed values: |
|
55 | + * - bicycle |
|
56 | + * - scooter |
|
57 | + * - motorbike |
|
58 | + * - car |
|
59 | + * - plane |
|
60 | + * - helicopter |
|
61 | + * - other |
|
62 | + * |
|
63 | + * @since 17.0.0 |
|
64 | + */ |
|
65 | + public const VEHICLE_TYPE = '{http://nextcloud.com/ns}resource-vehicle-type'; |
|
66 | 66 | |
67 | - /** |
|
68 | - * Make of the vehicle |
|
69 | - * |
|
70 | - * @since 17.0.0 |
|
71 | - */ |
|
72 | - public const VEHICLE_MAKE = '{http://nextcloud.com/ns}resource-vehicle-make'; |
|
67 | + /** |
|
68 | + * Make of the vehicle |
|
69 | + * |
|
70 | + * @since 17.0.0 |
|
71 | + */ |
|
72 | + public const VEHICLE_MAKE = '{http://nextcloud.com/ns}resource-vehicle-make'; |
|
73 | 73 | |
74 | - /** |
|
75 | - * Model of the vehicle |
|
76 | - * |
|
77 | - * @since 17.0.0 |
|
78 | - */ |
|
79 | - public const VEHICLE_MODEL = '{http://nextcloud.com/ns}resource-vehicle-model'; |
|
74 | + /** |
|
75 | + * Model of the vehicle |
|
76 | + * |
|
77 | + * @since 17.0.0 |
|
78 | + */ |
|
79 | + public const VEHICLE_MODEL = '{http://nextcloud.com/ns}resource-vehicle-model'; |
|
80 | 80 | |
81 | - /** |
|
82 | - * Whether or not the car is electric |
|
83 | - * |
|
84 | - * use '1' for electric, '0' for non-electric |
|
85 | - * |
|
86 | - * @since 17.0.0 |
|
87 | - */ |
|
88 | - public const VEHICLE_IS_ELECTRIC = '{http://nextcloud.com/ns}resource-vehicle-is-electric'; |
|
81 | + /** |
|
82 | + * Whether or not the car is electric |
|
83 | + * |
|
84 | + * use '1' for electric, '0' for non-electric |
|
85 | + * |
|
86 | + * @since 17.0.0 |
|
87 | + */ |
|
88 | + public const VEHICLE_IS_ELECTRIC = '{http://nextcloud.com/ns}resource-vehicle-is-electric'; |
|
89 | 89 | |
90 | - /** |
|
91 | - * Range of vehicle with a full tank |
|
92 | - * |
|
93 | - * @since 17.0.0 |
|
94 | - */ |
|
95 | - public const VEHICLE_RANGE = '{http://nextcloud.com/ns}resource-vehicle-range'; |
|
90 | + /** |
|
91 | + * Range of vehicle with a full tank |
|
92 | + * |
|
93 | + * @since 17.0.0 |
|
94 | + */ |
|
95 | + public const VEHICLE_RANGE = '{http://nextcloud.com/ns}resource-vehicle-range'; |
|
96 | 96 | |
97 | - /** |
|
98 | - * Seating capacity of the vehicle |
|
99 | - * |
|
100 | - * @since 17.0.0 |
|
101 | - */ |
|
102 | - public const VEHICLE_SEATING_CAPACITY = '{http://nextcloud.com/ns}resource-vehicle-seating-capacity'; |
|
97 | + /** |
|
98 | + * Seating capacity of the vehicle |
|
99 | + * |
|
100 | + * @since 17.0.0 |
|
101 | + */ |
|
102 | + public const VEHICLE_SEATING_CAPACITY = '{http://nextcloud.com/ns}resource-vehicle-seating-capacity'; |
|
103 | 103 | |
104 | - /** |
|
105 | - * Contact information about the person who is responsible to administer / maintain this resource |
|
106 | - * This key stores a textual description of name and possible ways to contact the person |
|
107 | - * |
|
108 | - * @since 17.0.0 |
|
109 | - */ |
|
110 | - public const CONTACT_PERSON = '{http://nextcloud.com/ns}resource-contact-person'; |
|
104 | + /** |
|
105 | + * Contact information about the person who is responsible to administer / maintain this resource |
|
106 | + * This key stores a textual description of name and possible ways to contact the person |
|
107 | + * |
|
108 | + * @since 17.0.0 |
|
109 | + */ |
|
110 | + public const CONTACT_PERSON = '{http://nextcloud.com/ns}resource-contact-person'; |
|
111 | 111 | |
112 | - /** |
|
113 | - * Link to the vcard of the contact person |
|
114 | - * |
|
115 | - * @since 17.0.0 |
|
116 | - */ |
|
117 | - public const CONTACT_PERSON_VCARD = '{http://nextcloud.com/ns}resource-contact-person-vcard'; |
|
112 | + /** |
|
113 | + * Link to the vcard of the contact person |
|
114 | + * |
|
115 | + * @since 17.0.0 |
|
116 | + */ |
|
117 | + public const CONTACT_PERSON_VCARD = '{http://nextcloud.com/ns}resource-contact-person-vcard'; |
|
118 | 118 | } |
@@ -33,33 +33,33 @@ |
||
33 | 33 | */ |
34 | 34 | interface IMetadataProvider { |
35 | 35 | |
36 | - /** |
|
37 | - * Get a list of all metadata keys available for this room |
|
38 | - * |
|
39 | - * Room backends are allowed to return custom keys, beyond the ones |
|
40 | - * defined in this class. If they do, they should make sure to use their |
|
41 | - * own namespace. |
|
42 | - * |
|
43 | - * @return String[] - A list of available keys |
|
44 | - * @since 17.0.0 |
|
45 | - */ |
|
46 | - public function getAllAvailableMetadataKeys():array; |
|
36 | + /** |
|
37 | + * Get a list of all metadata keys available for this room |
|
38 | + * |
|
39 | + * Room backends are allowed to return custom keys, beyond the ones |
|
40 | + * defined in this class. If they do, they should make sure to use their |
|
41 | + * own namespace. |
|
42 | + * |
|
43 | + * @return String[] - A list of available keys |
|
44 | + * @since 17.0.0 |
|
45 | + */ |
|
46 | + public function getAllAvailableMetadataKeys():array; |
|
47 | 47 | |
48 | - /** |
|
49 | - * Get whether or not a metadata key is set for this room |
|
50 | - * |
|
51 | - * @param string $key - The key to check for |
|
52 | - * @return bool - Whether or not key is available |
|
53 | - * @since 17.0.0 |
|
54 | - */ |
|
55 | - public function hasMetadataForKey(string $key):bool; |
|
48 | + /** |
|
49 | + * Get whether or not a metadata key is set for this room |
|
50 | + * |
|
51 | + * @param string $key - The key to check for |
|
52 | + * @return bool - Whether or not key is available |
|
53 | + * @since 17.0.0 |
|
54 | + */ |
|
55 | + public function hasMetadataForKey(string $key):bool; |
|
56 | 56 | |
57 | - /** |
|
58 | - * Get the value for a metadata key |
|
59 | - * |
|
60 | - * @param string $key - The key to check for |
|
61 | - * @return string|null - The value stored for the key, null if no value stored |
|
62 | - * @since 17.0.0 |
|
63 | - */ |
|
64 | - public function getMetadataForKey(string $key):?string; |
|
57 | + /** |
|
58 | + * Get the value for a metadata key |
|
59 | + * |
|
60 | + * @param string $key - The key to check for |
|
61 | + * @return string|null - The value stored for the key, null if no value stored |
|
62 | + * @since 17.0.0 |
|
63 | + */ |
|
64 | + public function getMetadataForKey(string $key):?string; |
|
65 | 65 | } |
@@ -61,5 +61,5 @@ |
||
61 | 61 | * @return string|null - The value stored for the key, null if no value stored |
62 | 62 | * @since 17.0.0 |
63 | 63 | */ |
64 | - public function getMetadataForKey(string $key):?string; |
|
64 | + public function getMetadataForKey(string $key): ?string; |
|
65 | 65 | } |
@@ -38,33 +38,33 @@ |
||
38 | 38 | |
39 | 39 | class FeaturePolicyMiddleware extends Middleware { |
40 | 40 | |
41 | - /** @var FeaturePolicyManager */ |
|
42 | - private $policyManager; |
|
41 | + /** @var FeaturePolicyManager */ |
|
42 | + private $policyManager; |
|
43 | 43 | |
44 | - public function __construct(FeaturePolicyManager $policyManager) { |
|
45 | - $this->policyManager = $policyManager; |
|
46 | - } |
|
44 | + public function __construct(FeaturePolicyManager $policyManager) { |
|
45 | + $this->policyManager = $policyManager; |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * Performs the default FeaturePolicy modifications that may be injected by other |
|
50 | - * applications |
|
51 | - * |
|
52 | - * @param Controller $controller |
|
53 | - * @param string $methodName |
|
54 | - * @param Response $response |
|
55 | - * @return Response |
|
56 | - */ |
|
57 | - public function afterController($controller, $methodName, Response $response): Response { |
|
58 | - $policy = !is_null($response->getFeaturePolicy()) ? $response->getFeaturePolicy() : new FeaturePolicy(); |
|
48 | + /** |
|
49 | + * Performs the default FeaturePolicy modifications that may be injected by other |
|
50 | + * applications |
|
51 | + * |
|
52 | + * @param Controller $controller |
|
53 | + * @param string $methodName |
|
54 | + * @param Response $response |
|
55 | + * @return Response |
|
56 | + */ |
|
57 | + public function afterController($controller, $methodName, Response $response): Response { |
|
58 | + $policy = !is_null($response->getFeaturePolicy()) ? $response->getFeaturePolicy() : new FeaturePolicy(); |
|
59 | 59 | |
60 | - if (get_class($policy) === EmptyFeaturePolicy::class) { |
|
61 | - return $response; |
|
62 | - } |
|
60 | + if (get_class($policy) === EmptyFeaturePolicy::class) { |
|
61 | + return $response; |
|
62 | + } |
|
63 | 63 | |
64 | - $defaultPolicy = $this->policyManager->getDefaultPolicy(); |
|
65 | - $defaultPolicy = $this->policyManager->mergePolicies($defaultPolicy, $policy); |
|
66 | - $response->setFeaturePolicy($defaultPolicy); |
|
64 | + $defaultPolicy = $this->policyManager->getDefaultPolicy(); |
|
65 | + $defaultPolicy = $this->policyManager->mergePolicies($defaultPolicy, $policy); |
|
66 | + $response->setFeaturePolicy($defaultPolicy); |
|
67 | 67 | |
68 | - return $response; |
|
69 | - } |
|
68 | + return $response; |
|
69 | + } |
|
70 | 70 | } |
@@ -60,10 +60,10 @@ |
||
60 | 60 | */ |
61 | 61 | public function mergePolicies(FeaturePolicy $defaultPolicy, |
62 | 62 | EmptyFeaturePolicy $originalPolicy): FeaturePolicy { |
63 | - foreach ((object)(array)$originalPolicy as $name => $value) { |
|
64 | - $setter = 'set' . ucfirst($name); |
|
63 | + foreach ((object) (array) $originalPolicy as $name => $value) { |
|
64 | + $setter = 'set'.ucfirst($name); |
|
65 | 65 | if (\is_array($value)) { |
66 | - $getter = 'get' . ucfirst($name); |
|
66 | + $getter = 'get'.ucfirst($name); |
|
67 | 67 | $currentValues = \is_array($defaultPolicy->$getter()) ? $defaultPolicy->$getter() : []; |
68 | 68 | $defaultPolicy->$setter(\array_values(\array_unique(\array_merge($currentValues, $value)))); |
69 | 69 | } elseif (\is_bool($value)) { |
@@ -31,48 +31,48 @@ |
||
31 | 31 | use OCP\Security\FeaturePolicy\AddFeaturePolicyEvent; |
32 | 32 | |
33 | 33 | class FeaturePolicyManager { |
34 | - /** @var EmptyFeaturePolicy[] */ |
|
35 | - private $policies = []; |
|
34 | + /** @var EmptyFeaturePolicy[] */ |
|
35 | + private $policies = []; |
|
36 | 36 | |
37 | - /** @var IEventDispatcher */ |
|
38 | - private $dispatcher; |
|
37 | + /** @var IEventDispatcher */ |
|
38 | + private $dispatcher; |
|
39 | 39 | |
40 | - public function __construct(IEventDispatcher $dispatcher) { |
|
41 | - $this->dispatcher = $dispatcher; |
|
42 | - } |
|
40 | + public function __construct(IEventDispatcher $dispatcher) { |
|
41 | + $this->dispatcher = $dispatcher; |
|
42 | + } |
|
43 | 43 | |
44 | - public function addDefaultPolicy(EmptyFeaturePolicy $policy): void { |
|
45 | - $this->policies[] = $policy; |
|
46 | - } |
|
44 | + public function addDefaultPolicy(EmptyFeaturePolicy $policy): void { |
|
45 | + $this->policies[] = $policy; |
|
46 | + } |
|
47 | 47 | |
48 | - public function getDefaultPolicy(): FeaturePolicy { |
|
49 | - $event = new AddFeaturePolicyEvent($this); |
|
50 | - $this->dispatcher->dispatchTyped($event); |
|
48 | + public function getDefaultPolicy(): FeaturePolicy { |
|
49 | + $event = new AddFeaturePolicyEvent($this); |
|
50 | + $this->dispatcher->dispatchTyped($event); |
|
51 | 51 | |
52 | - $defaultPolicy = new FeaturePolicy(); |
|
53 | - foreach ($this->policies as $policy) { |
|
54 | - $defaultPolicy = $this->mergePolicies($defaultPolicy, $policy); |
|
55 | - } |
|
56 | - return $defaultPolicy; |
|
57 | - } |
|
52 | + $defaultPolicy = new FeaturePolicy(); |
|
53 | + foreach ($this->policies as $policy) { |
|
54 | + $defaultPolicy = $this->mergePolicies($defaultPolicy, $policy); |
|
55 | + } |
|
56 | + return $defaultPolicy; |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * Merges the first given policy with the second one |
|
61 | - * |
|
62 | - */ |
|
63 | - public function mergePolicies(FeaturePolicy $defaultPolicy, |
|
64 | - EmptyFeaturePolicy $originalPolicy): FeaturePolicy { |
|
65 | - foreach ((object)(array)$originalPolicy as $name => $value) { |
|
66 | - $setter = 'set' . ucfirst($name); |
|
67 | - if (\is_array($value)) { |
|
68 | - $getter = 'get' . ucfirst($name); |
|
69 | - $currentValues = \is_array($defaultPolicy->$getter()) ? $defaultPolicy->$getter() : []; |
|
70 | - $defaultPolicy->$setter(\array_values(\array_unique(\array_merge($currentValues, $value)))); |
|
71 | - } elseif (\is_bool($value)) { |
|
72 | - $defaultPolicy->$setter($value); |
|
73 | - } |
|
74 | - } |
|
59 | + /** |
|
60 | + * Merges the first given policy with the second one |
|
61 | + * |
|
62 | + */ |
|
63 | + public function mergePolicies(FeaturePolicy $defaultPolicy, |
|
64 | + EmptyFeaturePolicy $originalPolicy): FeaturePolicy { |
|
65 | + foreach ((object)(array)$originalPolicy as $name => $value) { |
|
66 | + $setter = 'set' . ucfirst($name); |
|
67 | + if (\is_array($value)) { |
|
68 | + $getter = 'get' . ucfirst($name); |
|
69 | + $currentValues = \is_array($defaultPolicy->$getter()) ? $defaultPolicy->$getter() : []; |
|
70 | + $defaultPolicy->$setter(\array_values(\array_unique(\array_merge($currentValues, $value)))); |
|
71 | + } elseif (\is_bool($value)) { |
|
72 | + $defaultPolicy->$setter($value); |
|
73 | + } |
|
74 | + } |
|
75 | 75 | |
76 | - return $defaultPolicy; |
|
77 | - } |
|
76 | + return $defaultPolicy; |
|
77 | + } |
|
78 | 78 | } |
@@ -37,147 +37,147 @@ |
||
37 | 37 | */ |
38 | 38 | class EmptyFeaturePolicy { |
39 | 39 | |
40 | - /** @var string[] of allowed domains to autoplay media */ |
|
41 | - protected $autoplayDomains = null; |
|
42 | - |
|
43 | - /** @var string[] of allowed domains that can access the camera */ |
|
44 | - protected $cameraDomains = null; |
|
45 | - |
|
46 | - /** @var string[] of allowed domains that can use fullscreen */ |
|
47 | - protected $fullscreenDomains = null; |
|
48 | - |
|
49 | - /** @var string[] of allowed domains that can use the geolocation of the device */ |
|
50 | - protected $geolocationDomains = null; |
|
51 | - |
|
52 | - /** @var string[] of allowed domains that can use the microphone */ |
|
53 | - protected $microphoneDomains = null; |
|
54 | - |
|
55 | - /** @var string[] of allowed domains that can use the payment API */ |
|
56 | - protected $paymentDomains = null; |
|
57 | - |
|
58 | - /** |
|
59 | - * Allows to use autoplay from a specific domain. Use * to allow from all domains. |
|
60 | - * |
|
61 | - * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized. |
|
62 | - * @return $this |
|
63 | - * @since 17.0.0 |
|
64 | - */ |
|
65 | - public function addAllowedAutoplayDomain(string $domain): self { |
|
66 | - $this->autoplayDomains[] = $domain; |
|
67 | - return $this; |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Allows to use the camera on a specific domain. Use * to allow from all domains |
|
72 | - * |
|
73 | - * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized. |
|
74 | - * @return $this |
|
75 | - * @since 17.0.0 |
|
76 | - */ |
|
77 | - public function addAllowedCameraDomain(string $domain): self { |
|
78 | - $this->cameraDomains[] = $domain; |
|
79 | - return $this; |
|
80 | - } |
|
81 | - |
|
82 | - /** |
|
83 | - * Allows the full screen functionality to be used on a specific domain. Use * to allow from all domains |
|
84 | - * |
|
85 | - * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized. |
|
86 | - * @return $this |
|
87 | - * @since 17.0.0 |
|
88 | - */ |
|
89 | - public function addAllowedFullScreenDomain(string $domain): self { |
|
90 | - $this->fullscreenDomains[] = $domain; |
|
91 | - return $this; |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * Allows to use the geolocation on a specific domain. Use * to allow from all domains |
|
96 | - * |
|
97 | - * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized. |
|
98 | - * @return $this |
|
99 | - * @since 17.0.0 |
|
100 | - */ |
|
101 | - public function addAllowedGeoLocationDomain(string $domain): self { |
|
102 | - $this->geolocationDomains[] = $domain; |
|
103 | - return $this; |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * Allows to use the microphone on a specific domain. Use * to allow from all domains |
|
108 | - * |
|
109 | - * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized. |
|
110 | - * @return $this |
|
111 | - * @since 17.0.0 |
|
112 | - */ |
|
113 | - public function addAllowedMicrophoneDomain(string $domain): self { |
|
114 | - $this->microphoneDomains[] = $domain; |
|
115 | - return $this; |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * Allows to use the payment API on a specific domain. Use * to allow from all domains |
|
120 | - * |
|
121 | - * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized. |
|
122 | - * @return $this |
|
123 | - * @since 17.0.0 |
|
124 | - */ |
|
125 | - public function addAllowedPaymentDomain(string $domain): self { |
|
126 | - $this->paymentDomains[] = $domain; |
|
127 | - return $this; |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * Get the generated Feature-Policy as a string |
|
132 | - * |
|
133 | - * @return string |
|
134 | - * @since 17.0.0 |
|
135 | - */ |
|
136 | - public function buildPolicy(): string { |
|
137 | - $policy = ''; |
|
138 | - |
|
139 | - if (empty($this->autoplayDomains)) { |
|
140 | - $policy .= "autoplay 'none';"; |
|
141 | - } else { |
|
142 | - $policy .= 'autoplay ' . implode(' ', $this->autoplayDomains); |
|
143 | - $policy .= ';'; |
|
144 | - } |
|
145 | - |
|
146 | - if (empty($this->cameraDomains)) { |
|
147 | - $policy .= "camera 'none';"; |
|
148 | - } else { |
|
149 | - $policy .= 'camera ' . implode(' ', $this->cameraDomains); |
|
150 | - $policy .= ';'; |
|
151 | - } |
|
152 | - |
|
153 | - if (empty($this->fullscreenDomains)) { |
|
154 | - $policy .= "fullscreen 'none';"; |
|
155 | - } else { |
|
156 | - $policy .= 'fullscreen ' . implode(' ', $this->fullscreenDomains); |
|
157 | - $policy .= ';'; |
|
158 | - } |
|
159 | - |
|
160 | - if (empty($this->geolocationDomains)) { |
|
161 | - $policy .= "geolocation 'none';"; |
|
162 | - } else { |
|
163 | - $policy .= 'geolocation ' . implode(' ', $this->geolocationDomains); |
|
164 | - $policy .= ';'; |
|
165 | - } |
|
166 | - |
|
167 | - if (empty($this->microphoneDomains)) { |
|
168 | - $policy .= "microphone 'none';"; |
|
169 | - } else { |
|
170 | - $policy .= 'microphone ' . implode(' ', $this->microphoneDomains); |
|
171 | - $policy .= ';'; |
|
172 | - } |
|
173 | - |
|
174 | - if (empty($this->paymentDomains)) { |
|
175 | - $policy .= "payment 'none';"; |
|
176 | - } else { |
|
177 | - $policy .= 'payment ' . implode(' ', $this->paymentDomains); |
|
178 | - $policy .= ';'; |
|
179 | - } |
|
180 | - |
|
181 | - return rtrim($policy, ';'); |
|
182 | - } |
|
40 | + /** @var string[] of allowed domains to autoplay media */ |
|
41 | + protected $autoplayDomains = null; |
|
42 | + |
|
43 | + /** @var string[] of allowed domains that can access the camera */ |
|
44 | + protected $cameraDomains = null; |
|
45 | + |
|
46 | + /** @var string[] of allowed domains that can use fullscreen */ |
|
47 | + protected $fullscreenDomains = null; |
|
48 | + |
|
49 | + /** @var string[] of allowed domains that can use the geolocation of the device */ |
|
50 | + protected $geolocationDomains = null; |
|
51 | + |
|
52 | + /** @var string[] of allowed domains that can use the microphone */ |
|
53 | + protected $microphoneDomains = null; |
|
54 | + |
|
55 | + /** @var string[] of allowed domains that can use the payment API */ |
|
56 | + protected $paymentDomains = null; |
|
57 | + |
|
58 | + /** |
|
59 | + * Allows to use autoplay from a specific domain. Use * to allow from all domains. |
|
60 | + * |
|
61 | + * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized. |
|
62 | + * @return $this |
|
63 | + * @since 17.0.0 |
|
64 | + */ |
|
65 | + public function addAllowedAutoplayDomain(string $domain): self { |
|
66 | + $this->autoplayDomains[] = $domain; |
|
67 | + return $this; |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Allows to use the camera on a specific domain. Use * to allow from all domains |
|
72 | + * |
|
73 | + * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized. |
|
74 | + * @return $this |
|
75 | + * @since 17.0.0 |
|
76 | + */ |
|
77 | + public function addAllowedCameraDomain(string $domain): self { |
|
78 | + $this->cameraDomains[] = $domain; |
|
79 | + return $this; |
|
80 | + } |
|
81 | + |
|
82 | + /** |
|
83 | + * Allows the full screen functionality to be used on a specific domain. Use * to allow from all domains |
|
84 | + * |
|
85 | + * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized. |
|
86 | + * @return $this |
|
87 | + * @since 17.0.0 |
|
88 | + */ |
|
89 | + public function addAllowedFullScreenDomain(string $domain): self { |
|
90 | + $this->fullscreenDomains[] = $domain; |
|
91 | + return $this; |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * Allows to use the geolocation on a specific domain. Use * to allow from all domains |
|
96 | + * |
|
97 | + * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized. |
|
98 | + * @return $this |
|
99 | + * @since 17.0.0 |
|
100 | + */ |
|
101 | + public function addAllowedGeoLocationDomain(string $domain): self { |
|
102 | + $this->geolocationDomains[] = $domain; |
|
103 | + return $this; |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * Allows to use the microphone on a specific domain. Use * to allow from all domains |
|
108 | + * |
|
109 | + * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized. |
|
110 | + * @return $this |
|
111 | + * @since 17.0.0 |
|
112 | + */ |
|
113 | + public function addAllowedMicrophoneDomain(string $domain): self { |
|
114 | + $this->microphoneDomains[] = $domain; |
|
115 | + return $this; |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * Allows to use the payment API on a specific domain. Use * to allow from all domains |
|
120 | + * |
|
121 | + * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized. |
|
122 | + * @return $this |
|
123 | + * @since 17.0.0 |
|
124 | + */ |
|
125 | + public function addAllowedPaymentDomain(string $domain): self { |
|
126 | + $this->paymentDomains[] = $domain; |
|
127 | + return $this; |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * Get the generated Feature-Policy as a string |
|
132 | + * |
|
133 | + * @return string |
|
134 | + * @since 17.0.0 |
|
135 | + */ |
|
136 | + public function buildPolicy(): string { |
|
137 | + $policy = ''; |
|
138 | + |
|
139 | + if (empty($this->autoplayDomains)) { |
|
140 | + $policy .= "autoplay 'none';"; |
|
141 | + } else { |
|
142 | + $policy .= 'autoplay ' . implode(' ', $this->autoplayDomains); |
|
143 | + $policy .= ';'; |
|
144 | + } |
|
145 | + |
|
146 | + if (empty($this->cameraDomains)) { |
|
147 | + $policy .= "camera 'none';"; |
|
148 | + } else { |
|
149 | + $policy .= 'camera ' . implode(' ', $this->cameraDomains); |
|
150 | + $policy .= ';'; |
|
151 | + } |
|
152 | + |
|
153 | + if (empty($this->fullscreenDomains)) { |
|
154 | + $policy .= "fullscreen 'none';"; |
|
155 | + } else { |
|
156 | + $policy .= 'fullscreen ' . implode(' ', $this->fullscreenDomains); |
|
157 | + $policy .= ';'; |
|
158 | + } |
|
159 | + |
|
160 | + if (empty($this->geolocationDomains)) { |
|
161 | + $policy .= "geolocation 'none';"; |
|
162 | + } else { |
|
163 | + $policy .= 'geolocation ' . implode(' ', $this->geolocationDomains); |
|
164 | + $policy .= ';'; |
|
165 | + } |
|
166 | + |
|
167 | + if (empty($this->microphoneDomains)) { |
|
168 | + $policy .= "microphone 'none';"; |
|
169 | + } else { |
|
170 | + $policy .= 'microphone ' . implode(' ', $this->microphoneDomains); |
|
171 | + $policy .= ';'; |
|
172 | + } |
|
173 | + |
|
174 | + if (empty($this->paymentDomains)) { |
|
175 | + $policy .= "payment 'none';"; |
|
176 | + } else { |
|
177 | + $policy .= 'payment ' . implode(' ', $this->paymentDomains); |
|
178 | + $policy .= ';'; |
|
179 | + } |
|
180 | + |
|
181 | + return rtrim($policy, ';'); |
|
182 | + } |
|
183 | 183 | } |
@@ -139,42 +139,42 @@ |
||
139 | 139 | if (empty($this->autoplayDomains)) { |
140 | 140 | $policy .= "autoplay 'none';"; |
141 | 141 | } else { |
142 | - $policy .= 'autoplay ' . implode(' ', $this->autoplayDomains); |
|
142 | + $policy .= 'autoplay '.implode(' ', $this->autoplayDomains); |
|
143 | 143 | $policy .= ';'; |
144 | 144 | } |
145 | 145 | |
146 | 146 | if (empty($this->cameraDomains)) { |
147 | 147 | $policy .= "camera 'none';"; |
148 | 148 | } else { |
149 | - $policy .= 'camera ' . implode(' ', $this->cameraDomains); |
|
149 | + $policy .= 'camera '.implode(' ', $this->cameraDomains); |
|
150 | 150 | $policy .= ';'; |
151 | 151 | } |
152 | 152 | |
153 | 153 | if (empty($this->fullscreenDomains)) { |
154 | 154 | $policy .= "fullscreen 'none';"; |
155 | 155 | } else { |
156 | - $policy .= 'fullscreen ' . implode(' ', $this->fullscreenDomains); |
|
156 | + $policy .= 'fullscreen '.implode(' ', $this->fullscreenDomains); |
|
157 | 157 | $policy .= ';'; |
158 | 158 | } |
159 | 159 | |
160 | 160 | if (empty($this->geolocationDomains)) { |
161 | 161 | $policy .= "geolocation 'none';"; |
162 | 162 | } else { |
163 | - $policy .= 'geolocation ' . implode(' ', $this->geolocationDomains); |
|
163 | + $policy .= 'geolocation '.implode(' ', $this->geolocationDomains); |
|
164 | 164 | $policy .= ';'; |
165 | 165 | } |
166 | 166 | |
167 | 167 | if (empty($this->microphoneDomains)) { |
168 | 168 | $policy .= "microphone 'none';"; |
169 | 169 | } else { |
170 | - $policy .= 'microphone ' . implode(' ', $this->microphoneDomains); |
|
170 | + $policy .= 'microphone '.implode(' ', $this->microphoneDomains); |
|
171 | 171 | $policy .= ';'; |
172 | 172 | } |
173 | 173 | |
174 | 174 | if (empty($this->paymentDomains)) { |
175 | 175 | $policy .= "payment 'none';"; |
176 | 176 | } else { |
177 | - $policy .= 'payment ' . implode(' ', $this->paymentDomains); |
|
177 | + $policy .= 'payment '.implode(' ', $this->paymentDomains); |
|
178 | 178 | $policy .= ';'; |
179 | 179 | } |
180 | 180 |
@@ -37,23 +37,23 @@ |
||
37 | 37 | * @since 17.0.0 |
38 | 38 | */ |
39 | 39 | class FeaturePolicy extends EmptyFeaturePolicy { |
40 | - protected $autoplayDomains = [ |
|
41 | - '\'self\'', |
|
42 | - ]; |
|
40 | + protected $autoplayDomains = [ |
|
41 | + '\'self\'', |
|
42 | + ]; |
|
43 | 43 | |
44 | - /** @var string[] of allowed domains that can access the camera */ |
|
45 | - protected $cameraDomains = []; |
|
44 | + /** @var string[] of allowed domains that can access the camera */ |
|
45 | + protected $cameraDomains = []; |
|
46 | 46 | |
47 | - protected $fullscreenDomains = [ |
|
48 | - '\'self\'', |
|
49 | - ]; |
|
47 | + protected $fullscreenDomains = [ |
|
48 | + '\'self\'', |
|
49 | + ]; |
|
50 | 50 | |
51 | - /** @var string[] of allowed domains that can use the geolocation of the device */ |
|
52 | - protected $geolocationDomains = []; |
|
51 | + /** @var string[] of allowed domains that can use the geolocation of the device */ |
|
52 | + protected $geolocationDomains = []; |
|
53 | 53 | |
54 | - /** @var string[] of allowed domains that can use the microphone */ |
|
55 | - protected $microphoneDomains = []; |
|
54 | + /** @var string[] of allowed domains that can use the microphone */ |
|
55 | + protected $microphoneDomains = []; |
|
56 | 56 | |
57 | - /** @var string[] of allowed domains that can use the payment API */ |
|
58 | - protected $paymentDomains = []; |
|
57 | + /** @var string[] of allowed domains that can use the payment API */ |
|
58 | + protected $paymentDomains = []; |
|
59 | 59 | } |