PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.10.26
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.10.26
1.10.27 1.10.26 1.10.25 1.10.24 1.10.23 1.10.22 1.10.21 1.10.20 1.10.19 1.10.18 1.10.17 1.10.16 1.10.15 1.10.13 1.10.14 1.10.12 1.10.11 1.10.10 1.10.9 1.10.8 untagged-3d9b7ccddc54df87c672 1.10.7 1.10.6 1.10.5 1.10.3 All 171 releases
woocommerce-pos / vendor_prefixed / sentry / sentry / src / DataCollection / DataCollectionPolicy.php

DataCollectionPolicy.php in WCPOS – Point of Sale (POS) plugin for WooCommerce 1.10.26, at vendor_prefixed/sentry/sentry/src/DataCollection/DataCollectionPolicy.php

105 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare (strict_types=1);
4 namespace WCPOS\Vendor\Sentry\DataCollection;
5
6 use WCPOS\Vendor\Sentry\Options;
7 use WCPOS\Vendor\Sentry\State\HubInterface;
8 /**
9 * The policy acts as a container to deal with legacy and new data collection options.
10 * Checking both options is often tedious and very repetitive and will also make removal
11 * more difficult in the future.
12 *
13 * This class is meant to make it simpler to deal with both competing values and should make
14 * retiring the legacy option easier
15 */
16 final class DataCollectionPolicy
17 {
18 public const MAX_HTTP_BODY_LENGTH = 100000;
19 private const MAX_REQUEST_BODY_LENGTH = ['none' => 0, 'never' => 0, 'small' => 1000, 'medium' => 10000, 'always' => self::MAX_HTTP_BODY_LENGTH];
20 /**
21 * @var Options|null
22 */
23 private $options;
24 private function __construct(?Options $options)
25 {
26 $this->options = $options;
27 }
28 public static function fromHub(HubInterface $hub) : self
29 {
30 $client = $hub->getClient();
31 return new self($client === null ? null : $client->getOptions());
32 }
33 public static function fromOptions(?Options $options) : self
34 {
35 return new self($options);
36 }
37 public function getOptions() : ?Options
38 {
39 return $this->options;
40 }
41 public function getDataCollection() : ?DataCollectionOptions
42 {
43 return $this->options === null ? null : $this->options->getDataCollection();
44 }
45 public function isLegacyMode() : bool
46 {
47 return $this->getDataCollection() === null;
48 }
49 public function getHttpBodyLimit(HttpMessageType $messageType) : ?int
50 {
51 $collection = $this->getDataCollection();
52 if ($collection === null || !$collection->shouldCollectHttpBody($messageType)) {
53 return null;
54 }
55 return $this->calculateMaxHttpBodyLength($messageType) ?: null;
56 }
57 public function getLegacyRequestBodyLimit() : ?int
58 {
59 if (!$this->isLegacyMode()) {
60 return null;
61 }
62 return $this->calculateMaxHttpBodyLength(HttpMessageType::incomingRequest()) ?: null;
63 }
64 public function shouldCollectUserInfo() : bool
65 {
66 $dataCollection = $this->getDataCollection();
67 if ($dataCollection !== null) {
68 return $dataCollection->shouldCollectUserInfo();
69 }
70 return $this->options !== null && $this->options->shouldSendDefaultPii();
71 }
72 /**
73 * Returns the number of source code lines to include above and below each stack frame,
74 * or `null` if no source code context should be collected.
75 */
76 public function getFrameContextLines() : ?int
77 {
78 $dataCollection = $this->getDataCollection();
79 if ($dataCollection !== null) {
80 return $dataCollection->getFrameContextLines();
81 }
82 return $this->options === null ? null : $this->options->getContextLines();
83 }
84 public function shouldCollectDatabaseQueryData() : bool
85 {
86 $dataCollection = $this->getDataCollection();
87 return $dataCollection !== null && $dataCollection->shouldCollectDatabaseQueryData();
88 }
89 private function calculateMaxHttpBodyLength(HttpMessageType $messageType) : int
90 {
91 if ($this->options === null) {
92 return 0;
93 }
94 if ($messageType->isRequest()) {
95 $maxRequestBodySize = $this->options->getMaxRequestBodySize();
96 // Preserve legacy behaviour to capture request bodies unbounded
97 if ($this->isLegacyMode() && $maxRequestBodySize === 'always') {
98 return -1;
99 }
100 return self::MAX_REQUEST_BODY_LENGTH[$maxRequestBodySize] ?? 0;
101 }
102 return self::MAX_HTTP_BODY_LENGTH;
103 }
104 }
105