Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/google-site-kit/includes/Core/Modules/Datapoint.php

Keine Baseline-Datei – Diff nur gegen leer.
Zur Liste
1 -
1 + <?php
2 + /**
3 + * Class Google\Site_Kit\Core\Modules\Datapoint
4 + *
5 + * @package Google\Site_Kit\Core\Modules
6 + * @copyright 2022 Google LLC
7 + * @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
8 + * @link https://sitekit.withgoogle.com
9 + */
10 +
11 + namespace Google\Site_Kit\Core\Modules;
12 +
13 + /**
14 + * Class representing a datapoint definition.
15 + *
16 + * @since 1.77.0
17 + * @access private
18 + * @ignore
19 + */
20 + class Datapoint {
21 +
22 + /**
23 + * Service identifier.
24 + *
25 + * @since 1.77.0
26 + * @since 1.160.0 Updated to allow a function to return the service identifier.
27 + * @var string|callable
28 + */
29 + private $service = '';
30 +
31 + /**
32 + * Required scopes.
33 + *
34 + * @since 1.77.0
35 + * @var string[]
36 + */
37 + private $scopes = array();
38 +
39 + /**
40 + * Shareable status.
41 + *
42 + * @since 1.77.0
43 + * @var bool
44 + */
45 + private $shareable;
46 +
47 + /**
48 + * Request scopes message.
49 + *
50 + * @since 1.77.0
51 + * @var string
52 + */
53 + private $request_scopes_message;
54 +
55 + /**
56 + * Constructor.
57 + *
58 + * @since 1.77.0
59 + *
60 + * @param array $definition Definition fields.
61 + */
62 + public function __construct( array $definition ) {
63 + $this->shareable = ! empty( $definition['shareable'] );
64 +
65 + if (
66 + isset( $definition['service'] ) &&
67 + (
68 + is_string( $definition['service'] ) ||
69 + is_callable( $definition['service'] )
70 + )
71 + ) {
72 + $this->service = $definition['service'];
73 + }
74 +
75 + if ( isset( $definition['scopes'] ) && is_array( $definition['scopes'] ) ) {
76 + $this->scopes = $definition['scopes'];
77 + }
78 +
79 + if ( isset( $definition['request_scopes_message'] ) && is_string( $definition['request_scopes_message'] ) ) {
80 + $this->request_scopes_message = $definition['request_scopes_message'];
81 + }
82 + }
83 +
84 + /**
85 + * Checks if the datapoint is shareable.
86 + *
87 + * @since 1.77.0
88 + *
89 + * @return bool
90 + */
91 + public function is_shareable() {
92 + return $this->shareable;
93 + }
94 +
95 + /**
96 + * Gets the service identifier.
97 + *
98 + * @since 1.77.0
99 + *
100 + * @return string
101 + */
102 + protected function get_service() {
103 + $service = $this->service;
104 +
105 + if ( is_callable( $this->service ) ) {
106 + $service = call_user_func( $this->service );
107 + }
108 +
109 + return $service;
110 + }
111 +
112 + /**
113 + * Gets the list of required scopes.
114 + *
115 + * @since 1.77.0
116 + *
117 + * @return string[]
118 + */
119 + public function get_required_scopes() {
120 + return $this->scopes;
121 + }
122 +
123 + /**
124 + * Gets the request scopes message.
125 + *
126 + * @since 1.77.0
127 + *
128 + * @return string
129 + */
130 + public function get_request_scopes_message() {
131 + if ( $this->request_scopes_message ) {
132 + return $this->request_scopes_message;
133 + }
134 +
135 + return __( 'You’ll need to grant Site Kit permission to do this.', 'google-site-kit' );
136 + }
137 + }
138 +