Completed
Branch fix-caching-loader-test (60c3ed)
by
unknown
13:01 queued 04:28
created
core/services/request/middleware/RecommendedVersions.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -32,18 +32,18 @@  discard block
 block discarded – undo
32 32
         $this->request = $request;
33 33
         $this->response = $response;
34 34
         // check required WP version
35
-        if (! $this->minimumWordPressVersionRequired()) {
35
+        if ( ! $this->minimumWordPressVersionRequired()) {
36 36
             $this->request->unSetRequestParam('activate', true);
37 37
             add_action('admin_notices', array($this, 'minimumWpVersionError'), 1);
38 38
             $this->response->terminateRequest();
39 39
             $this->response->deactivatePlugin();
40 40
         }
41 41
         // check recommended PHP version
42
-        if (! $this->minimumPhpVersionRecommended()) {
42
+        if ( ! $this->minimumPhpVersionRecommended()) {
43 43
             $this->displayMinimumRecommendedPhpVersionNotice();
44 44
         }
45 45
         // upcoming required version
46
-        if (! $this->upcomingRequiredPhpVersion()) {
46
+        if ( ! $this->upcomingRequiredPhpVersion()) {
47 47
             $this->displayUpcomingRequiredVersion();
48 48
         }
49 49
         $this->response = $this->processRequestStack($this->request, $this->response);
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
     {
143 143
         if ($this->request->isAdmin()) {
144 144
             new PersistentAdminNotice(
145
-                'php_version_' . str_replace('.', '-', EE_MIN_PHP_VER_RECOMMENDED) . '_recommended',
145
+                'php_version_'.str_replace('.', '-', EE_MIN_PHP_VER_RECOMMENDED).'_recommended',
146 146
                 sprintf(
147 147
                     esc_html__(
148 148
                         'Event Espresso recommends PHP version %1$s or greater for optimal performance. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
             && apply_filters('FHEE__EE_Recommended_Versions__displayUpcomingRequiredVersion', true, $this->request)
181 181
             && current_user_can('update_plugins')
182 182
         ) {
183
-            add_action('admin_notices', function () {
183
+            add_action('admin_notices', function() {
184 184
                 echo '<div class="notice event-espresso-admin-notice notice-warning"><p>'
185 185
                      . sprintf(
186 186
                          esc_html__(
Please login to merge, or discard this patch.
Indentation   +173 added lines, -173 removed lines patch added patch discarded remove patch
@@ -18,183 +18,183 @@
 block discarded – undo
18 18
  */
19 19
 class RecommendedVersions extends Middleware
20 20
 {
21
-    /**
22
-     * converts a Request to a Response
23
-     *
24
-     * @param RequestInterface  $request
25
-     * @param ResponseInterface $response
26
-     * @return ResponseInterface
27
-     * @throws InvalidDataTypeException
28
-     */
29
-    public function handleRequest(RequestInterface $request, ResponseInterface $response)
30
-    {
31
-        $this->request = $request;
32
-        $this->response = $response;
33
-        // check required WP version
34
-        if (! $this->minimumWordPressVersionRequired()) {
35
-            $this->request->unSetRequestParam('activate', true);
36
-            add_action('admin_notices', array($this, 'minimumWpVersionError'), 1);
37
-            $this->response->terminateRequest();
38
-            $this->response->deactivatePlugin();
39
-        }
40
-        // check recommended PHP version
41
-        if (! $this->minimumPhpVersionRecommended()) {
42
-            $this->displayMinimumRecommendedPhpVersionNotice();
43
-        }
44
-        // upcoming required version
45
-        if (! $this->upcomingRequiredPhpVersion()) {
46
-            $this->displayUpcomingRequiredVersion();
47
-        }
48
-        $this->response = $this->processRequestStack($this->request, $this->response);
49
-        return $this->response;
50
-    }
51
-
52
-
53
-    /**
54
-     * Helper method to assess installed wp version against given values.
55
-     * By default this compares the required minimum version of WP for EE against the installed version of WP
56
-     * Note, $wp_version is the first parameter sent into the PHP version_compare function (what is being checked
57
-     * against) so consider that when sending in your values.
58
-     *
59
-     * @param string $version_to_check
60
-     * @param string $operator
61
-     * @return bool
62
-     */
63
-    public static function compareWordPressVersion($version_to_check = EE_MIN_WP_VER_REQUIRED, $operator = '>=')
64
-    {
65
-        global $wp_version;
66
-        return version_compare(
67
-            // first account for wp_version being pre-release
68
-            // (like RC, beta etc) which are usually in the format like 4.7-RC3-39519
69
-            strpos($wp_version, '-') > 0
70
-                ? substr($wp_version, 0, strpos($wp_version, '-'))
71
-                : $wp_version,
72
-            $version_to_check,
73
-            $operator
74
-        );
75
-    }
76
-
77
-
78
-    /**
79
-     * @return boolean
80
-     */
81
-    private function minimumWordPressVersionRequired()
82
-    {
83
-        return RecommendedVersions::compareWordPressVersion();
84
-    }
85
-
86
-
87
-    /**
88
-     * @param string $min_version
89
-     * @return boolean
90
-     */
91
-    private function checkPhpVersion($min_version = EE_MIN_PHP_VER_RECOMMENDED)
92
-    {
93
-        return version_compare(PHP_VERSION, $min_version, '>=') ? true : false;
94
-    }
95
-
96
-
97
-    /**
98
-     * @return boolean
99
-     */
100
-    private function minimumPhpVersionRecommended()
101
-    {
102
-        return $this->checkPhpVersion();
103
-    }
104
-
105
-
106
-    /**
107
-     * @return void
108
-     */
109
-    public function minimumWpVersionError()
110
-    {
111
-        global $wp_version;
112
-        ?>
21
+	/**
22
+	 * converts a Request to a Response
23
+	 *
24
+	 * @param RequestInterface  $request
25
+	 * @param ResponseInterface $response
26
+	 * @return ResponseInterface
27
+	 * @throws InvalidDataTypeException
28
+	 */
29
+	public function handleRequest(RequestInterface $request, ResponseInterface $response)
30
+	{
31
+		$this->request = $request;
32
+		$this->response = $response;
33
+		// check required WP version
34
+		if (! $this->minimumWordPressVersionRequired()) {
35
+			$this->request->unSetRequestParam('activate', true);
36
+			add_action('admin_notices', array($this, 'minimumWpVersionError'), 1);
37
+			$this->response->terminateRequest();
38
+			$this->response->deactivatePlugin();
39
+		}
40
+		// check recommended PHP version
41
+		if (! $this->minimumPhpVersionRecommended()) {
42
+			$this->displayMinimumRecommendedPhpVersionNotice();
43
+		}
44
+		// upcoming required version
45
+		if (! $this->upcomingRequiredPhpVersion()) {
46
+			$this->displayUpcomingRequiredVersion();
47
+		}
48
+		$this->response = $this->processRequestStack($this->request, $this->response);
49
+		return $this->response;
50
+	}
51
+
52
+
53
+	/**
54
+	 * Helper method to assess installed wp version against given values.
55
+	 * By default this compares the required minimum version of WP for EE against the installed version of WP
56
+	 * Note, $wp_version is the first parameter sent into the PHP version_compare function (what is being checked
57
+	 * against) so consider that when sending in your values.
58
+	 *
59
+	 * @param string $version_to_check
60
+	 * @param string $operator
61
+	 * @return bool
62
+	 */
63
+	public static function compareWordPressVersion($version_to_check = EE_MIN_WP_VER_REQUIRED, $operator = '>=')
64
+	{
65
+		global $wp_version;
66
+		return version_compare(
67
+			// first account for wp_version being pre-release
68
+			// (like RC, beta etc) which are usually in the format like 4.7-RC3-39519
69
+			strpos($wp_version, '-') > 0
70
+				? substr($wp_version, 0, strpos($wp_version, '-'))
71
+				: $wp_version,
72
+			$version_to_check,
73
+			$operator
74
+		);
75
+	}
76
+
77
+
78
+	/**
79
+	 * @return boolean
80
+	 */
81
+	private function minimumWordPressVersionRequired()
82
+	{
83
+		return RecommendedVersions::compareWordPressVersion();
84
+	}
85
+
86
+
87
+	/**
88
+	 * @param string $min_version
89
+	 * @return boolean
90
+	 */
91
+	private function checkPhpVersion($min_version = EE_MIN_PHP_VER_RECOMMENDED)
92
+	{
93
+		return version_compare(PHP_VERSION, $min_version, '>=') ? true : false;
94
+	}
95
+
96
+
97
+	/**
98
+	 * @return boolean
99
+	 */
100
+	private function minimumPhpVersionRecommended()
101
+	{
102
+		return $this->checkPhpVersion();
103
+	}
104
+
105
+
106
+	/**
107
+	 * @return void
108
+	 */
109
+	public function minimumWpVersionError()
110
+	{
111
+		global $wp_version;
112
+		?>
113 113
         <div class="error">
114 114
             <p>
115 115
                 <?php
116
-                printf(
117
-                    esc_html__(
118
-                        'We\'re sorry, but Event Espresso requires WordPress version %1$s or greater in order to operate. You are currently running version %2$s.%3$sFor information on how to update your version of WordPress, please go to %4$s.',
119
-                        'event_espresso'
120
-                    ),
121
-                    EE_MIN_WP_VER_REQUIRED,
122
-                    $wp_version,
123
-                    '<br/>',
124
-                    '<a href="http://codex.wordpress.org/Updating_WordPress">http://codex.wordpress.org/Updating_WordPress</a>'
125
-                );
126
-                ?>
116
+				printf(
117
+					esc_html__(
118
+						'We\'re sorry, but Event Espresso requires WordPress version %1$s or greater in order to operate. You are currently running version %2$s.%3$sFor information on how to update your version of WordPress, please go to %4$s.',
119
+						'event_espresso'
120
+					),
121
+					EE_MIN_WP_VER_REQUIRED,
122
+					$wp_version,
123
+					'<br/>',
124
+					'<a href="http://codex.wordpress.org/Updating_WordPress">http://codex.wordpress.org/Updating_WordPress</a>'
125
+				);
126
+				?>
127 127
             </p>
128 128
         </div>
129 129
         <?php
130
-    }
131
-
132
-
133
-    /**
134
-     *    _display_minimum_recommended_php_version_notice
135
-     *
136
-     * @access private
137
-     * @return void
138
-     * @throws InvalidDataTypeException
139
-     */
140
-    private function displayMinimumRecommendedPhpVersionNotice()
141
-    {
142
-        if ($this->request->isAdmin()) {
143
-            new PersistentAdminNotice(
144
-                'php_version_' . str_replace('.', '-', EE_MIN_PHP_VER_RECOMMENDED) . '_recommended',
145
-                sprintf(
146
-                    esc_html__(
147
-                        'Event Espresso recommends PHP version %1$s or greater for optimal performance. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
148
-                        'event_espresso'
149
-                    ),
150
-                    EE_MIN_PHP_VER_RECOMMENDED,
151
-                    PHP_VERSION,
152
-                    '<br/>',
153
-                    '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
154
-                )
155
-            );
156
-        }
157
-    }
158
-
159
-
160
-    /**
161
-     * Returns whether the provided php version number is less than the current version of php installed on the server.
162
-     *
163
-     * @param string $version_required
164
-     * @return bool
165
-     */
166
-    private function upcomingRequiredPhpVersion($version_required = '5.5')
167
-    {
168
-        return true;
169
-        // return $this->checkPhpVersion($version_required);
170
-    }
171
-
172
-
173
-    /**
174
-     *  Sets a notice for an upcoming required version of PHP in the next update of EE core.
175
-     */
176
-    private function displayUpcomingRequiredVersion()
177
-    {
178
-        if (
179
-            $this->request->isAdmin()
180
-            && apply_filters('FHEE__EE_Recommended_Versions__displayUpcomingRequiredVersion', true, $this->request)
181
-            && current_user_can('update_plugins')
182
-        ) {
183
-            add_action('admin_notices', function () {
184
-                echo '<div class="notice event-espresso-admin-notice notice-warning"><p>'
185
-                     . sprintf(
186
-                         esc_html__(
187
-                             'Please note: The next update of Event Espresso 4 will %1$srequire%2$s PHP 5.4.45 or greater.  Your web server\'s PHP version is %3$s.  You can contact your host and ask them to update your PHP version to at least PHP 5.6.  Please do not update to the new version of Event Espresso 4 until the PHP update is completed. Read about why keeping your server on the latest version of PHP is a good idea %4$shere%5$s',
188
-                             'event_espresso'
189
-                         ),
190
-                         '<strong>',
191
-                         '</strong>',
192
-                         PHP_VERSION,
193
-                         '<a href="https://wordpress.org/support/upgrade-php/">',
194
-                         '</a>'
195
-                     )
196
-                     . '</p></div>';
197
-            });
198
-        }
199
-    }
130
+	}
131
+
132
+
133
+	/**
134
+	 *    _display_minimum_recommended_php_version_notice
135
+	 *
136
+	 * @access private
137
+	 * @return void
138
+	 * @throws InvalidDataTypeException
139
+	 */
140
+	private function displayMinimumRecommendedPhpVersionNotice()
141
+	{
142
+		if ($this->request->isAdmin()) {
143
+			new PersistentAdminNotice(
144
+				'php_version_' . str_replace('.', '-', EE_MIN_PHP_VER_RECOMMENDED) . '_recommended',
145
+				sprintf(
146
+					esc_html__(
147
+						'Event Espresso recommends PHP version %1$s or greater for optimal performance. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
148
+						'event_espresso'
149
+					),
150
+					EE_MIN_PHP_VER_RECOMMENDED,
151
+					PHP_VERSION,
152
+					'<br/>',
153
+					'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
154
+				)
155
+			);
156
+		}
157
+	}
158
+
159
+
160
+	/**
161
+	 * Returns whether the provided php version number is less than the current version of php installed on the server.
162
+	 *
163
+	 * @param string $version_required
164
+	 * @return bool
165
+	 */
166
+	private function upcomingRequiredPhpVersion($version_required = '5.5')
167
+	{
168
+		return true;
169
+		// return $this->checkPhpVersion($version_required);
170
+	}
171
+
172
+
173
+	/**
174
+	 *  Sets a notice for an upcoming required version of PHP in the next update of EE core.
175
+	 */
176
+	private function displayUpcomingRequiredVersion()
177
+	{
178
+		if (
179
+			$this->request->isAdmin()
180
+			&& apply_filters('FHEE__EE_Recommended_Versions__displayUpcomingRequiredVersion', true, $this->request)
181
+			&& current_user_can('update_plugins')
182
+		) {
183
+			add_action('admin_notices', function () {
184
+				echo '<div class="notice event-espresso-admin-notice notice-warning"><p>'
185
+					 . sprintf(
186
+						 esc_html__(
187
+							 'Please note: The next update of Event Espresso 4 will %1$srequire%2$s PHP 5.4.45 or greater.  Your web server\'s PHP version is %3$s.  You can contact your host and ask them to update your PHP version to at least PHP 5.6.  Please do not update to the new version of Event Espresso 4 until the PHP update is completed. Read about why keeping your server on the latest version of PHP is a good idea %4$shere%5$s',
188
+							 'event_espresso'
189
+						 ),
190
+						 '<strong>',
191
+						 '</strong>',
192
+						 PHP_VERSION,
193
+						 '<a href="https://wordpress.org/support/upgrade-php/">',
194
+						 '</a>'
195
+					 )
196
+					 . '</p></div>';
197
+			});
198
+		}
199
+	}
200 200
 }
Please login to merge, or discard this patch.
core/services/assets/AssetCollection.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
             /** @var Asset $asset */
76 76
             $asset = $this->current();
77 77
             if ($asset->type() === $type) {
78
-                $files[ $asset->handle() ] = $asset;
78
+                $files[$asset->handle()] = $asset;
79 79
             }
80 80
             $this->next();
81 81
         }
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
             /** @var JavascriptAsset $asset */
97 97
             $asset = $this->current();
98 98
             if ($asset->type() === Asset::TYPE_JS && $asset->hasInlineData()) {
99
-                $files[ $asset->handle() ] = $asset;
99
+                $files[$asset->handle()] = $asset;
100 100
             }
101 101
             $this->next();
102 102
         }
Please login to merge, or discard this patch.
Indentation   +188 added lines, -188 removed lines patch added patch discarded remove patch
@@ -21,192 +21,192 @@
 block discarded – undo
21 21
 {
22 22
 
23 23
 
24
-    /**
25
-     * AssetCollection constructor
26
-     *
27
-     * @throws InvalidInterfaceException
28
-     */
29
-    public function __construct()
30
-    {
31
-        parent::__construct('EventEspresso\core\domain\values\assets\Asset');
32
-    }
33
-
34
-
35
-    /**
36
-     * @return StylesheetAsset[]
37
-     * @since 4.9.62.p
38
-     */
39
-    public function getStylesheetAssets()
40
-    {
41
-        return $this->getAssetsOfType(Asset::TYPE_CSS);
42
-    }
43
-
44
-
45
-    /**
46
-     * @return JavascriptAsset[]
47
-     * @since 4.9.62.p
48
-     */
49
-    public function getJavascriptAssets()
50
-    {
51
-        return $this->getAssetsOfType(Asset::TYPE_JS);
52
-    }
53
-
54
-
55
-    /**
56
-     * @return ManifestFile[]
57
-     * @since 4.9.62.p
58
-     */
59
-    public function getManifestFiles()
60
-    {
61
-        return $this->getAssetsOfType(Asset::TYPE_MANIFEST);
62
-    }
63
-
64
-
65
-    /**
66
-     * @param $type
67
-     * @return JavascriptAsset[]|StylesheetAsset[]|ManifestFile[]
68
-     * @since 4.9.62.p
69
-     */
70
-    protected function getAssetsOfType($type)
71
-    {
72
-        $files = array();
73
-        $this->rewind();
74
-        while ($this->valid()) {
75
-            /** @var Asset $asset */
76
-            $asset = $this->current();
77
-            if ($asset->type() === $type) {
78
-                $files[ $asset->handle() ] = $asset;
79
-            }
80
-            $this->next();
81
-        }
82
-        $this->rewind();
83
-        return $files;
84
-    }
85
-
86
-
87
-    /**
88
-     * @return JavascriptAsset[]
89
-     * @since 4.9.62.p
90
-     */
91
-    public function getJavascriptAssetsWithData()
92
-    {
93
-        $files = array();
94
-        $this->rewind();
95
-        while ($this->valid()) {
96
-            /** @var JavascriptAsset $asset */
97
-            $asset = $this->current();
98
-            if ($asset->type() === Asset::TYPE_JS && $asset->hasInlineData()) {
99
-                $files[ $asset->handle() ] = $asset;
100
-            }
101
-            $this->next();
102
-        }
103
-        $this->rewind();
104
-        return $files;
105
-    }
106
-
107
-
108
-    /**
109
-     * returns TRUE or FALSE
110
-     * depending on whether the object is within the Collection
111
-     * based on the supplied $identifier and type
112
-     *
113
-     * @param  mixed $identifier
114
-     * @param string $type
115
-     * @return bool
116
-     * @since 4.9.63.p
117
-     */
118
-    public function hasAssetOfType($identifier, $type = Asset::TYPE_JS)
119
-    {
120
-        $this->rewind();
121
-        while ($this->valid()) {
122
-            if ($this->getInfo() === $identifier && $this->current()->type() === $type) {
123
-                $this->rewind();
124
-                return true;
125
-            }
126
-            $this->next();
127
-        }
128
-        return false;
129
-    }
130
-
131
-
132
-    /**
133
-     * returns TRUE or FALSE
134
-     * depending on whether the Javascript Asset is within the Collection
135
-     * based on the supplied $identifier
136
-     *
137
-     * @param  mixed $identifier
138
-     * @return bool
139
-     * @since 4.9.63.p
140
-     */
141
-    public function hasJavascriptAsset($identifier)
142
-    {
143
-        return $this->hasAssetOfType($identifier, Asset::TYPE_JS);
144
-    }
145
-
146
-
147
-    /**
148
-     * returns TRUE or FALSE
149
-     * depending on whether the Stylesheet Asset is within the Collection
150
-     * based on the supplied $identifier
151
-     *
152
-     * @param  mixed $identifier
153
-     * @return bool
154
-     * @since 4.9.63.p
155
-     */
156
-    public function hasStylesheetAsset($identifier)
157
-    {
158
-        return $this->hasAssetOfType($identifier, Asset::TYPE_CSS);
159
-    }
160
-
161
-    /**
162
-     * returns the object from the Collection
163
-     * based on the supplied $identifier and type
164
-     *
165
-     * @param  mixed $identifier
166
-     * @param string $type
167
-     * @return JavascriptAsset|StylesheetAsset
168
-     * @since 4.9.63.p
169
-     */
170
-    public function getAssetOfType($identifier, $type = Asset::TYPE_JS)
171
-    {
172
-        $this->rewind();
173
-        while ($this->valid()) {
174
-            if ($this->getInfo() === $identifier && $this->current()->type() === $type) {
175
-                /** @var JavascriptAsset|StylesheetAsset $object */
176
-                $object = $this->current();
177
-                $this->rewind();
178
-                return $object;
179
-            }
180
-            $this->next();
181
-        }
182
-        return null;
183
-    }
184
-
185
-
186
-    /**
187
-     * returns the Stylesheet Asset from the Collection
188
-     * based on the supplied $identifier
189
-     *
190
-     * @param  mixed $identifier
191
-     * @return StylesheetAsset
192
-     * @since 4.9.63.p
193
-     */
194
-    public function getStylesheetAsset($identifier)
195
-    {
196
-        return $this->getAssetOfType($identifier, Asset::TYPE_CSS);
197
-    }
198
-
199
-
200
-    /**
201
-     * returns the Javascript Asset from the Collection
202
-     * based on the supplied $identifier
203
-     *
204
-     * @param  mixed $identifier
205
-     * @return JavascriptAsset
206
-     * @since 4.9.63.p
207
-     */
208
-    public function getJavascriptAsset($identifier)
209
-    {
210
-        return $this->getAssetOfType($identifier, Asset::TYPE_JS);
211
-    }
24
+	/**
25
+	 * AssetCollection constructor
26
+	 *
27
+	 * @throws InvalidInterfaceException
28
+	 */
29
+	public function __construct()
30
+	{
31
+		parent::__construct('EventEspresso\core\domain\values\assets\Asset');
32
+	}
33
+
34
+
35
+	/**
36
+	 * @return StylesheetAsset[]
37
+	 * @since 4.9.62.p
38
+	 */
39
+	public function getStylesheetAssets()
40
+	{
41
+		return $this->getAssetsOfType(Asset::TYPE_CSS);
42
+	}
43
+
44
+
45
+	/**
46
+	 * @return JavascriptAsset[]
47
+	 * @since 4.9.62.p
48
+	 */
49
+	public function getJavascriptAssets()
50
+	{
51
+		return $this->getAssetsOfType(Asset::TYPE_JS);
52
+	}
53
+
54
+
55
+	/**
56
+	 * @return ManifestFile[]
57
+	 * @since 4.9.62.p
58
+	 */
59
+	public function getManifestFiles()
60
+	{
61
+		return $this->getAssetsOfType(Asset::TYPE_MANIFEST);
62
+	}
63
+
64
+
65
+	/**
66
+	 * @param $type
67
+	 * @return JavascriptAsset[]|StylesheetAsset[]|ManifestFile[]
68
+	 * @since 4.9.62.p
69
+	 */
70
+	protected function getAssetsOfType($type)
71
+	{
72
+		$files = array();
73
+		$this->rewind();
74
+		while ($this->valid()) {
75
+			/** @var Asset $asset */
76
+			$asset = $this->current();
77
+			if ($asset->type() === $type) {
78
+				$files[ $asset->handle() ] = $asset;
79
+			}
80
+			$this->next();
81
+		}
82
+		$this->rewind();
83
+		return $files;
84
+	}
85
+
86
+
87
+	/**
88
+	 * @return JavascriptAsset[]
89
+	 * @since 4.9.62.p
90
+	 */
91
+	public function getJavascriptAssetsWithData()
92
+	{
93
+		$files = array();
94
+		$this->rewind();
95
+		while ($this->valid()) {
96
+			/** @var JavascriptAsset $asset */
97
+			$asset = $this->current();
98
+			if ($asset->type() === Asset::TYPE_JS && $asset->hasInlineData()) {
99
+				$files[ $asset->handle() ] = $asset;
100
+			}
101
+			$this->next();
102
+		}
103
+		$this->rewind();
104
+		return $files;
105
+	}
106
+
107
+
108
+	/**
109
+	 * returns TRUE or FALSE
110
+	 * depending on whether the object is within the Collection
111
+	 * based on the supplied $identifier and type
112
+	 *
113
+	 * @param  mixed $identifier
114
+	 * @param string $type
115
+	 * @return bool
116
+	 * @since 4.9.63.p
117
+	 */
118
+	public function hasAssetOfType($identifier, $type = Asset::TYPE_JS)
119
+	{
120
+		$this->rewind();
121
+		while ($this->valid()) {
122
+			if ($this->getInfo() === $identifier && $this->current()->type() === $type) {
123
+				$this->rewind();
124
+				return true;
125
+			}
126
+			$this->next();
127
+		}
128
+		return false;
129
+	}
130
+
131
+
132
+	/**
133
+	 * returns TRUE or FALSE
134
+	 * depending on whether the Javascript Asset is within the Collection
135
+	 * based on the supplied $identifier
136
+	 *
137
+	 * @param  mixed $identifier
138
+	 * @return bool
139
+	 * @since 4.9.63.p
140
+	 */
141
+	public function hasJavascriptAsset($identifier)
142
+	{
143
+		return $this->hasAssetOfType($identifier, Asset::TYPE_JS);
144
+	}
145
+
146
+
147
+	/**
148
+	 * returns TRUE or FALSE
149
+	 * depending on whether the Stylesheet Asset is within the Collection
150
+	 * based on the supplied $identifier
151
+	 *
152
+	 * @param  mixed $identifier
153
+	 * @return bool
154
+	 * @since 4.9.63.p
155
+	 */
156
+	public function hasStylesheetAsset($identifier)
157
+	{
158
+		return $this->hasAssetOfType($identifier, Asset::TYPE_CSS);
159
+	}
160
+
161
+	/**
162
+	 * returns the object from the Collection
163
+	 * based on the supplied $identifier and type
164
+	 *
165
+	 * @param  mixed $identifier
166
+	 * @param string $type
167
+	 * @return JavascriptAsset|StylesheetAsset
168
+	 * @since 4.9.63.p
169
+	 */
170
+	public function getAssetOfType($identifier, $type = Asset::TYPE_JS)
171
+	{
172
+		$this->rewind();
173
+		while ($this->valid()) {
174
+			if ($this->getInfo() === $identifier && $this->current()->type() === $type) {
175
+				/** @var JavascriptAsset|StylesheetAsset $object */
176
+				$object = $this->current();
177
+				$this->rewind();
178
+				return $object;
179
+			}
180
+			$this->next();
181
+		}
182
+		return null;
183
+	}
184
+
185
+
186
+	/**
187
+	 * returns the Stylesheet Asset from the Collection
188
+	 * based on the supplied $identifier
189
+	 *
190
+	 * @param  mixed $identifier
191
+	 * @return StylesheetAsset
192
+	 * @since 4.9.63.p
193
+	 */
194
+	public function getStylesheetAsset($identifier)
195
+	{
196
+		return $this->getAssetOfType($identifier, Asset::TYPE_CSS);
197
+	}
198
+
199
+
200
+	/**
201
+	 * returns the Javascript Asset from the Collection
202
+	 * based on the supplied $identifier
203
+	 *
204
+	 * @param  mixed $identifier
205
+	 * @return JavascriptAsset
206
+	 * @since 4.9.63.p
207
+	 */
208
+	public function getJavascriptAsset($identifier)
209
+	{
210
+		return $this->getAssetOfType($identifier, Asset::TYPE_JS);
211
+	}
212 212
 }
Please login to merge, or discard this patch.
strategies/display/EE_Radio_Button_Display_Strategy.strategy.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -32,10 +32,10 @@  discard block
 block discarded – undo
32 32
             $html .= $this->_attributes_string(
33 33
                 array(
34 34
                     'for' => $html_id,
35
-                    'id' => $html_id . '-lbl',
35
+                    'id' => $html_id.'-lbl',
36 36
                     'class' => apply_filters(
37 37
                         'FHEE__EE_Radio_Button_Display_Strategy__display__option_label_class',
38
-                        'ee-radio-label-after' . $label_size_class,
38
+                        'ee-radio-label-after'.$label_size_class,
39 39
                         $this,
40 40
                         $input,
41 41
                         $value
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 
63 63
             $html .= '>&nbsp;';
64 64
             $html .= $display_text;
65
-            $html .= EEH_HTML::nl(-1, 'radio') . '</label>';
65
+            $html .= EEH_HTML::nl(-1, 'radio').'</label>';
66 66
         }
67 67
         $html .= EEH_HTML::div('', '', 'clear-float');
68 68
         $html .= EEH_HTML::divx();
Please login to merge, or discard this patch.
Indentation   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -11,61 +11,61 @@
 block discarded – undo
11 11
  */
12 12
 class EE_Radio_Button_Display_Strategy extends EE_Compound_Input_Display_Strategy
13 13
 {
14
-    /**
15
-     *
16
-     * @throws EE_Error
17
-     * @return string of html to display the field
18
-     */
19
-    public function display()
20
-    {
21
-        $input = $this->get_input();
22
-        $input->set_label_sizes();
23
-        $label_size_class = $input->get_label_size_class();
24
-        $html = '';
25
-        foreach ($input->options() as $value => $display_text) {
26
-            $value = $input->get_normalization_strategy()->unnormalize($value);
14
+	/**
15
+	 *
16
+	 * @throws EE_Error
17
+	 * @return string of html to display the field
18
+	 */
19
+	public function display()
20
+	{
21
+		$input = $this->get_input();
22
+		$input->set_label_sizes();
23
+		$label_size_class = $input->get_label_size_class();
24
+		$html = '';
25
+		foreach ($input->options() as $value => $display_text) {
26
+			$value = $input->get_normalization_strategy()->unnormalize($value);
27 27
 
28
-            $html_id = $this->get_sub_input_id($value);
29
-            $html .= EEH_HTML::nl(0, 'radio');
28
+			$html_id = $this->get_sub_input_id($value);
29
+			$html .= EEH_HTML::nl(0, 'radio');
30 30
 
31
-            $html .= $this->_opening_tag('label');
32
-            $html .= $this->_attributes_string(
33
-                array(
34
-                    'for' => $html_id,
35
-                    'id' => $html_id . '-lbl',
36
-                    'class' => apply_filters(
37
-                        'FHEE__EE_Radio_Button_Display_Strategy__display__option_label_class',
38
-                        'ee-radio-label-after' . $label_size_class,
39
-                        $this,
40
-                        $input,
41
-                        $value
42
-                    )
43
-                )
44
-            );
45
-            $html .= '>';
46
-            $html .= EEH_HTML::nl(1, 'radio');
47
-            $html .= $this->_opening_tag('input');
48
-            $attributes = array(
49
-                'id' => $html_id,
50
-                'name' => $input->html_name(),
51
-                'class' => $input->html_class(),
52
-                'style' => $input->html_style(),
53
-                'type' => 'radio',
54
-                'value' => $value,
55
-                0 => $input->other_html_attributes(),
56
-                'data-question_label' => $input->html_label_id()
57
-            );
58
-            if ($input->raw_value() === $value) {
59
-                $attributes['checked'] = 'checked';
60
-            }
61
-            $html .= $this->_attributes_string($attributes);
31
+			$html .= $this->_opening_tag('label');
32
+			$html .= $this->_attributes_string(
33
+				array(
34
+					'for' => $html_id,
35
+					'id' => $html_id . '-lbl',
36
+					'class' => apply_filters(
37
+						'FHEE__EE_Radio_Button_Display_Strategy__display__option_label_class',
38
+						'ee-radio-label-after' . $label_size_class,
39
+						$this,
40
+						$input,
41
+						$value
42
+					)
43
+				)
44
+			);
45
+			$html .= '>';
46
+			$html .= EEH_HTML::nl(1, 'radio');
47
+			$html .= $this->_opening_tag('input');
48
+			$attributes = array(
49
+				'id' => $html_id,
50
+				'name' => $input->html_name(),
51
+				'class' => $input->html_class(),
52
+				'style' => $input->html_style(),
53
+				'type' => 'radio',
54
+				'value' => $value,
55
+				0 => $input->other_html_attributes(),
56
+				'data-question_label' => $input->html_label_id()
57
+			);
58
+			if ($input->raw_value() === $value) {
59
+				$attributes['checked'] = 'checked';
60
+			}
61
+			$html .= $this->_attributes_string($attributes);
62 62
 
63
-            $html .= '>&nbsp;';
64
-            $html .= $display_text;
65
-            $html .= EEH_HTML::nl(-1, 'radio') . '</label>';
66
-        }
67
-        $html .= EEH_HTML::div('', '', 'clear-float');
68
-        $html .= EEH_HTML::divx();
69
-        return apply_filters('FHEE__EE_Radio_Button_Display_Strategy__display', $html, $this, $this->_input);
70
-    }
63
+			$html .= '>&nbsp;';
64
+			$html .= $display_text;
65
+			$html .= EEH_HTML::nl(-1, 'radio') . '</label>';
66
+		}
67
+		$html .= EEH_HTML::div('', '', 'clear-float');
68
+		$html .= EEH_HTML::divx();
69
+		return apply_filters('FHEE__EE_Radio_Button_Display_Strategy__display', $html, $this, $this->_input);
70
+	}
71 71
 }
Please login to merge, or discard this patch.
core/services/session/SessionStartHandler.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
         }
100 100
         // If not, then attempt to deal with any errors,
101 101
         // otherwise, try to hobble along without the session
102
-        if (! $this->handleSessionSaveHandlerErrors()) {
102
+        if ( ! $this->handleSessionSaveHandlerErrors()) {
103 103
             return;
104 104
         }
105 105
         // there is no record of a fatal error while trying to start the session
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
                     ),
250 250
                     '<a href="https://wordpress.org/plugins/wp-native-php-sessions/">',
251 251
                     '</a>',
252
-                    '<a href="' . $retry_session_url . '">'
252
+                    '<a href="'.$retry_session_url.'">'
253 253
                 ),
254 254
                 __FILE__,
255 255
                 __FUNCTION__,
Please login to merge, or discard this patch.
Indentation   +242 added lines, -242 removed lines patch added patch discarded remove patch
@@ -27,246 +27,246 @@
 block discarded – undo
27 27
  */
28 28
 class SessionStartHandler
29 29
 {
30
-    const OPTION_NAME_SESSION_SAVE_HANDLER_STATUS = 'ee_session_save_handler_status';
31
-
32
-    const REQUEST_PARAM_RETRY_SESSION             = 'ee_retry_session';
33
-
34
-    const SESSION_SAVE_HANDLER_STATUS_FAILED      = 'session_save_handler_failed';
35
-
36
-    const SESSION_SAVE_HANDLER_STATUS_SUCCESS     = 'session_save_handler_success';
37
-
38
-    const SESSION_SAVE_HANDLER_STATUS_UNKNOWN     = 'session_save_handler_untested';
39
-
40
-    /**
41
-     * @var RequestInterface $request
42
-     */
43
-    protected $request;
44
-
45
-
46
-    /**
47
-     * StartSession constructor.
48
-     *
49
-     * @param RequestInterface $request
50
-     */
51
-    public function __construct(RequestInterface $request)
52
-    {
53
-        $this->request = $request;
54
-    }
55
-
56
-
57
-    /**
58
-     * Check if a custom session save handler is in play
59
-     * and attempt to start the PHP session
60
-     *
61
-     * @since 4.9.68.p
62
-     */
63
-    public function startSession()
64
-    {
65
-        // check that session has started
66
-        if (session_id() === '') {
67
-            // starts a new session if one doesn't already exist, or re-initiates an existing one
68
-            if ($this->hasKnownCustomSessionSaveHandler()) {
69
-                $this->checkCustomSessionSaveHandler();
70
-            } else {
71
-                session_start();
72
-                session_write_close();
73
-            }
74
-        }
75
-    }
76
-
77
-
78
-    /**
79
-     * Returns `true` if the 'session.save_handler' ini setting matches a known custom handler
80
-     *
81
-     * @return bool
82
-     * @since 4.9.68.p
83
-     */
84
-    private function hasKnownCustomSessionSaveHandler(): bool
85
-    {
86
-        return ini_get('session.save_handler') === 'user';
87
-    }
88
-
89
-
90
-    /**
91
-     * Attempt to start the PHP session when a custom Session Save Handler is known to be set.
92
-     *
93
-     * @since 4.9.68.p
94
-     */
95
-    private function checkCustomSessionSaveHandler()
96
-    {
97
-        // If we've already successfully tested the session save handler
98
-        // on a previous request then just start the session
99
-        if ($this->sessionSaveHandlerIsValid()) {
100
-            session_start();
101
-            session_write_close();
102
-            return;
103
-        }
104
-        // If not, then attempt to deal with any errors,
105
-        // otherwise, try to hobble along without the session
106
-        if (! $this->handleSessionSaveHandlerErrors()) {
107
-            return;
108
-        }
109
-        // there is no record of a fatal error while trying to start the session
110
-        // so let's see if there's a custom session save handler. Proceed with caution
111
-        $this->initializeSessionSaveHandlerStatus();
112
-        // hold your breath, the custom session save handler might cause a fatal here...
113
-        session_start();
114
-        session_write_close();
115
-        // phew! we made it! the custom session handler is a-ok
116
-        $this->setSessionSaveHandlerStatusToValid();
117
-    }
118
-
119
-
120
-    /**
121
-     * retrieves the value for the 'ee_session_save_handler_status' WP option.
122
-     * default value = 'session_save_handler_untested'
123
-     *
124
-     * @return string
125
-     * @since 4.9.68.p
126
-     */
127
-    private function getSessionSaveHandlerStatus(): string
128
-    {
129
-        return get_option(
130
-            SessionStartHandler::OPTION_NAME_SESSION_SAVE_HANDLER_STATUS,
131
-            SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_UNKNOWN
132
-        );
133
-    }
134
-
135
-
136
-    /**
137
-     * Sets the 'ee_session_save_handler_status' WP option value to 'session_save_handler_failed'
138
-     * which can then be upgraded is everything works correctly
139
-     *
140
-     * @return void
141
-     * @since 4.9.68.p
142
-     */
143
-    private function initializeSessionSaveHandlerStatus(): void
144
-    {
145
-        update_option(
146
-            SessionStartHandler::OPTION_NAME_SESSION_SAVE_HANDLER_STATUS,
147
-            SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_FAILED
148
-        );
149
-    }
150
-
151
-
152
-    /**
153
-     * Sets the 'ee_session_save_handler_status' WP option value to 'session_save_handler_success'
154
-     *
155
-     * @return void
156
-     * @since 4.9.68.p
157
-     */
158
-    private function setSessionSaveHandlerStatusToValid(): void
159
-    {
160
-        update_option(
161
-            SessionStartHandler::OPTION_NAME_SESSION_SAVE_HANDLER_STATUS,
162
-            SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_SUCCESS
163
-        );
164
-    }
165
-
166
-
167
-    /**
168
-     * Sets the 'ee_session_save_handler_status' WP option value to 'session_save_handler_untested'
169
-     *
170
-     * @return void
171
-     * @since 4.9.68.p
172
-     */
173
-    private function resetSessionSaveHandlerStatus(): void
174
-    {
175
-        update_option(
176
-            SessionStartHandler::OPTION_NAME_SESSION_SAVE_HANDLER_STATUS,
177
-            SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_UNKNOWN
178
-        );
179
-    }
180
-
181
-
182
-    /**
183
-     * Returns `true` if the 'ee_session_save_handler_status' WP option value
184
-     * is equal to 'session_save_handler_success'
185
-     *
186
-     * @return bool
187
-     * @since 4.9.68.p
188
-     */
189
-    private function sessionSaveHandlerIsValid(): bool
190
-    {
191
-        return $this->getSessionSaveHandlerStatus() === SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_SUCCESS;
192
-    }
193
-
194
-
195
-    /**
196
-     * Returns `true` if the 'ee_session_save_handler_status' WP option value
197
-     * is equal to 'session_save_handler_failed'
198
-     *
199
-     * @return bool
200
-     * @since 4.9.68.p
201
-     */
202
-    private function sessionSaveHandlerFailed(): bool
203
-    {
204
-        return $this->getSessionSaveHandlerStatus() === SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_FAILED;
205
-    }
206
-
207
-
208
-    /**
209
-     * Returns `true` if no errors were detected with the session save handler,
210
-     * otherwise attempts to work notify the appropriate authorities
211
-     * with a suggestion for how to fix the issue, and returns `false`.
212
-     *
213
-     *
214
-     * @return bool
215
-     * @since 4.9.68.p
216
-     */
217
-    private function handleSessionSaveHandlerErrors(): bool
218
-    {
219
-        // Check if we had a fatal error last time while trying to start the session
220
-        if ($this->sessionSaveHandlerFailed()) {
221
-            // apparently, last time we tried using the custom session save handler there was a fatal
222
-            if ($this->request->requestParamIsSet(SessionStartHandler::REQUEST_PARAM_RETRY_SESSION)) {
223
-                $this->resetSessionSaveHandlerStatus();
224
-                // remove "ee_retry_session", otherwise if the problem still isn't fixed,
225
-                // we'll just keep getting the fatal error over and over.
226
-                // Better to remove it and redirect, and try on the next request
227
-                EEH_URL::safeRedirectAndExit(
228
-                    remove_query_arg(
229
-                        [SessionStartHandler::REQUEST_PARAM_RETRY_SESSION],
230
-                        EEH_URL::current_url()
231
-                    )
232
-                );
233
-            }
234
-            // so the session is broken, don't try it again,
235
-            // just show a message to users that can fix it
236
-            $this->displaySessionSaveHandlerErrorNotice();
237
-            return false;
238
-        }
239
-        return true;
240
-    }
241
-
242
-
243
-    /**
244
-     * Generates an EE_Error notice regarding the current session woes
245
-     * but only if the current user is an admin with permission to 'install_plugins'.
246
-     *
247
-     * @since 4.9.68.p
248
-     */
249
-    private function displaySessionSaveHandlerErrorNotice()
250
-    {
251
-        if (current_user_can('install_plugins')) {
252
-            $retry_session_url = add_query_arg(
253
-                [SessionStartHandler::REQUEST_PARAM_RETRY_SESSION => true],
254
-                EEH_URL::current_url()
255
-            );
256
-            EE_Error::add_error(
257
-                sprintf(
258
-                    esc_html__(
259
-                        'It appears there was a fatal error while starting the session, so Event Espresso is not able to process registrations normally. Some hosting companies, like Pantheon, require an extra plugin for Event Espresso to work. Please install the %1$sWordPress Native PHP Sessions plugin%2$s, then %3$sclick here to check if the problem is resolved.%2$s',
260
-                        'event_espresso'
261
-                    ),
262
-                    '<a href="https://wordpress.org/plugins/wp-native-php-sessions/">',
263
-                    '</a>',
264
-                    '<a href="' . $retry_session_url . '">'
265
-                ),
266
-                __FILE__,
267
-                __FUNCTION__,
268
-                __LINE__
269
-            );
270
-        }
271
-    }
30
+	const OPTION_NAME_SESSION_SAVE_HANDLER_STATUS = 'ee_session_save_handler_status';
31
+
32
+	const REQUEST_PARAM_RETRY_SESSION             = 'ee_retry_session';
33
+
34
+	const SESSION_SAVE_HANDLER_STATUS_FAILED      = 'session_save_handler_failed';
35
+
36
+	const SESSION_SAVE_HANDLER_STATUS_SUCCESS     = 'session_save_handler_success';
37
+
38
+	const SESSION_SAVE_HANDLER_STATUS_UNKNOWN     = 'session_save_handler_untested';
39
+
40
+	/**
41
+	 * @var RequestInterface $request
42
+	 */
43
+	protected $request;
44
+
45
+
46
+	/**
47
+	 * StartSession constructor.
48
+	 *
49
+	 * @param RequestInterface $request
50
+	 */
51
+	public function __construct(RequestInterface $request)
52
+	{
53
+		$this->request = $request;
54
+	}
55
+
56
+
57
+	/**
58
+	 * Check if a custom session save handler is in play
59
+	 * and attempt to start the PHP session
60
+	 *
61
+	 * @since 4.9.68.p
62
+	 */
63
+	public function startSession()
64
+	{
65
+		// check that session has started
66
+		if (session_id() === '') {
67
+			// starts a new session if one doesn't already exist, or re-initiates an existing one
68
+			if ($this->hasKnownCustomSessionSaveHandler()) {
69
+				$this->checkCustomSessionSaveHandler();
70
+			} else {
71
+				session_start();
72
+				session_write_close();
73
+			}
74
+		}
75
+	}
76
+
77
+
78
+	/**
79
+	 * Returns `true` if the 'session.save_handler' ini setting matches a known custom handler
80
+	 *
81
+	 * @return bool
82
+	 * @since 4.9.68.p
83
+	 */
84
+	private function hasKnownCustomSessionSaveHandler(): bool
85
+	{
86
+		return ini_get('session.save_handler') === 'user';
87
+	}
88
+
89
+
90
+	/**
91
+	 * Attempt to start the PHP session when a custom Session Save Handler is known to be set.
92
+	 *
93
+	 * @since 4.9.68.p
94
+	 */
95
+	private function checkCustomSessionSaveHandler()
96
+	{
97
+		// If we've already successfully tested the session save handler
98
+		// on a previous request then just start the session
99
+		if ($this->sessionSaveHandlerIsValid()) {
100
+			session_start();
101
+			session_write_close();
102
+			return;
103
+		}
104
+		// If not, then attempt to deal with any errors,
105
+		// otherwise, try to hobble along without the session
106
+		if (! $this->handleSessionSaveHandlerErrors()) {
107
+			return;
108
+		}
109
+		// there is no record of a fatal error while trying to start the session
110
+		// so let's see if there's a custom session save handler. Proceed with caution
111
+		$this->initializeSessionSaveHandlerStatus();
112
+		// hold your breath, the custom session save handler might cause a fatal here...
113
+		session_start();
114
+		session_write_close();
115
+		// phew! we made it! the custom session handler is a-ok
116
+		$this->setSessionSaveHandlerStatusToValid();
117
+	}
118
+
119
+
120
+	/**
121
+	 * retrieves the value for the 'ee_session_save_handler_status' WP option.
122
+	 * default value = 'session_save_handler_untested'
123
+	 *
124
+	 * @return string
125
+	 * @since 4.9.68.p
126
+	 */
127
+	private function getSessionSaveHandlerStatus(): string
128
+	{
129
+		return get_option(
130
+			SessionStartHandler::OPTION_NAME_SESSION_SAVE_HANDLER_STATUS,
131
+			SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_UNKNOWN
132
+		);
133
+	}
134
+
135
+
136
+	/**
137
+	 * Sets the 'ee_session_save_handler_status' WP option value to 'session_save_handler_failed'
138
+	 * which can then be upgraded is everything works correctly
139
+	 *
140
+	 * @return void
141
+	 * @since 4.9.68.p
142
+	 */
143
+	private function initializeSessionSaveHandlerStatus(): void
144
+	{
145
+		update_option(
146
+			SessionStartHandler::OPTION_NAME_SESSION_SAVE_HANDLER_STATUS,
147
+			SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_FAILED
148
+		);
149
+	}
150
+
151
+
152
+	/**
153
+	 * Sets the 'ee_session_save_handler_status' WP option value to 'session_save_handler_success'
154
+	 *
155
+	 * @return void
156
+	 * @since 4.9.68.p
157
+	 */
158
+	private function setSessionSaveHandlerStatusToValid(): void
159
+	{
160
+		update_option(
161
+			SessionStartHandler::OPTION_NAME_SESSION_SAVE_HANDLER_STATUS,
162
+			SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_SUCCESS
163
+		);
164
+	}
165
+
166
+
167
+	/**
168
+	 * Sets the 'ee_session_save_handler_status' WP option value to 'session_save_handler_untested'
169
+	 *
170
+	 * @return void
171
+	 * @since 4.9.68.p
172
+	 */
173
+	private function resetSessionSaveHandlerStatus(): void
174
+	{
175
+		update_option(
176
+			SessionStartHandler::OPTION_NAME_SESSION_SAVE_HANDLER_STATUS,
177
+			SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_UNKNOWN
178
+		);
179
+	}
180
+
181
+
182
+	/**
183
+	 * Returns `true` if the 'ee_session_save_handler_status' WP option value
184
+	 * is equal to 'session_save_handler_success'
185
+	 *
186
+	 * @return bool
187
+	 * @since 4.9.68.p
188
+	 */
189
+	private function sessionSaveHandlerIsValid(): bool
190
+	{
191
+		return $this->getSessionSaveHandlerStatus() === SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_SUCCESS;
192
+	}
193
+
194
+
195
+	/**
196
+	 * Returns `true` if the 'ee_session_save_handler_status' WP option value
197
+	 * is equal to 'session_save_handler_failed'
198
+	 *
199
+	 * @return bool
200
+	 * @since 4.9.68.p
201
+	 */
202
+	private function sessionSaveHandlerFailed(): bool
203
+	{
204
+		return $this->getSessionSaveHandlerStatus() === SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_FAILED;
205
+	}
206
+
207
+
208
+	/**
209
+	 * Returns `true` if no errors were detected with the session save handler,
210
+	 * otherwise attempts to work notify the appropriate authorities
211
+	 * with a suggestion for how to fix the issue, and returns `false`.
212
+	 *
213
+	 *
214
+	 * @return bool
215
+	 * @since 4.9.68.p
216
+	 */
217
+	private function handleSessionSaveHandlerErrors(): bool
218
+	{
219
+		// Check if we had a fatal error last time while trying to start the session
220
+		if ($this->sessionSaveHandlerFailed()) {
221
+			// apparently, last time we tried using the custom session save handler there was a fatal
222
+			if ($this->request->requestParamIsSet(SessionStartHandler::REQUEST_PARAM_RETRY_SESSION)) {
223
+				$this->resetSessionSaveHandlerStatus();
224
+				// remove "ee_retry_session", otherwise if the problem still isn't fixed,
225
+				// we'll just keep getting the fatal error over and over.
226
+				// Better to remove it and redirect, and try on the next request
227
+				EEH_URL::safeRedirectAndExit(
228
+					remove_query_arg(
229
+						[SessionStartHandler::REQUEST_PARAM_RETRY_SESSION],
230
+						EEH_URL::current_url()
231
+					)
232
+				);
233
+			}
234
+			// so the session is broken, don't try it again,
235
+			// just show a message to users that can fix it
236
+			$this->displaySessionSaveHandlerErrorNotice();
237
+			return false;
238
+		}
239
+		return true;
240
+	}
241
+
242
+
243
+	/**
244
+	 * Generates an EE_Error notice regarding the current session woes
245
+	 * but only if the current user is an admin with permission to 'install_plugins'.
246
+	 *
247
+	 * @since 4.9.68.p
248
+	 */
249
+	private function displaySessionSaveHandlerErrorNotice()
250
+	{
251
+		if (current_user_can('install_plugins')) {
252
+			$retry_session_url = add_query_arg(
253
+				[SessionStartHandler::REQUEST_PARAM_RETRY_SESSION => true],
254
+				EEH_URL::current_url()
255
+			);
256
+			EE_Error::add_error(
257
+				sprintf(
258
+					esc_html__(
259
+						'It appears there was a fatal error while starting the session, so Event Espresso is not able to process registrations normally. Some hosting companies, like Pantheon, require an extra plugin for Event Espresso to work. Please install the %1$sWordPress Native PHP Sessions plugin%2$s, then %3$sclick here to check if the problem is resolved.%2$s',
260
+						'event_espresso'
261
+					),
262
+					'<a href="https://wordpress.org/plugins/wp-native-php-sessions/">',
263
+					'</a>',
264
+					'<a href="' . $retry_session_url . '">'
265
+				),
266
+				__FILE__,
267
+				__FUNCTION__,
268
+				__LINE__
269
+			);
270
+		}
271
+	}
272 272
 }
Please login to merge, or discard this patch.
core/services/dependencies/ClassAlias.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@
 block discarded – undo
34 34
      */
35 35
     public function __construct($alias, $fqcn)
36 36
     {
37
-        if (! is_subclass_of($fqcn, $alias)) {
37
+        if ( ! is_subclass_of($fqcn, $alias)) {
38 38
             throw new InvalidAliasException($fqcn, $alias);
39 39
         }
40 40
         $this->alias = $alias;
Please login to merge, or discard this patch.
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -16,46 +16,46 @@
 block discarded – undo
16 16
  */
17 17
 class ClassAlias
18 18
 {
19
-    /**
20
-     * @var string $alias   an interface or base class representing what object
21
-     *                      can be utilized by another object and/or function
22
-     */
23
-    private $alias;
19
+	/**
20
+	 * @var string $alias   an interface or base class representing what object
21
+	 *                      can be utilized by another object and/or function
22
+	 */
23
+	private $alias;
24 24
 
25
-    /**
26
-     * @var string $fqcn the actual class that should be substituted for the alias above
27
-     */
28
-    private $fqcn;
25
+	/**
26
+	 * @var string $fqcn the actual class that should be substituted for the alias above
27
+	 */
28
+	private $fqcn;
29 29
 
30
-    /**
31
-     * ClassAlias constructor.
32
-     *
33
-     * @param string $alias Interface specified by implementing class
34
-     * @param string $fqcn  Concrete class that satisfies interface
35
-     * @throws InvalidAliasException
36
-     */
37
-    public function __construct($alias, $fqcn)
38
-    {
39
-        if (! is_subclass_of($fqcn, $alias)) {
40
-            throw new InvalidAliasException($fqcn, $alias);
41
-        }
42
-        $this->alias = $alias;
43
-        $this->fqcn = $fqcn;
44
-    }
30
+	/**
31
+	 * ClassAlias constructor.
32
+	 *
33
+	 * @param string $alias Interface specified by implementing class
34
+	 * @param string $fqcn  Concrete class that satisfies interface
35
+	 * @throws InvalidAliasException
36
+	 */
37
+	public function __construct($alias, $fqcn)
38
+	{
39
+		if (! is_subclass_of($fqcn, $alias)) {
40
+			throw new InvalidAliasException($fqcn, $alias);
41
+		}
42
+		$this->alias = $alias;
43
+		$this->fqcn = $fqcn;
44
+	}
45 45
 
46
-    /**
47
-     * @return string
48
-     */
49
-    public function alias()
50
-    {
51
-        return $this->alias;
52
-    }
46
+	/**
47
+	 * @return string
48
+	 */
49
+	public function alias()
50
+	{
51
+		return $this->alias;
52
+	}
53 53
 
54
-    /**
55
-     * @return string
56
-     */
57
-    public function fqcn()
58
-    {
59
-        return $this->fqcn;
60
-    }
54
+	/**
55
+	 * @return string
56
+	 */
57
+	public function fqcn()
58
+	{
59
+		return $this->fqcn;
60
+	}
61 61
 }
Please login to merge, or discard this patch.
core/services/factory/FactoryWithDependencyResolver.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -18,41 +18,41 @@
 block discarded – undo
18 18
  */
19 19
 abstract class FactoryWithDependencyResolver implements FactoryInterface
20 20
 {
21
-    /**
22
-     * @var DependencyResolverInterface $dependency_resolver
23
-     */
24
-    private $dependency_resolver;
21
+	/**
22
+	 * @var DependencyResolverInterface $dependency_resolver
23
+	 */
24
+	private $dependency_resolver;
25 25
 
26
-    /**
27
-     * @var LoaderInterface $loader
28
-     */
29
-    private $loader;
26
+	/**
27
+	 * @var LoaderInterface $loader
28
+	 */
29
+	private $loader;
30 30
 
31
-    /**
32
-     * FactoryWithDependencyResolver constructor.
33
-     *
34
-     * @param DependencyResolverInterface $dependency_resolver
35
-     * @param LoaderInterface             $loader
36
-     */
37
-    public function __construct(DependencyResolverInterface $dependency_resolver, LoaderInterface $loader)
38
-    {
39
-        $this->dependency_resolver = $dependency_resolver;
40
-        $this->loader = $loader;
41
-    }
31
+	/**
32
+	 * FactoryWithDependencyResolver constructor.
33
+	 *
34
+	 * @param DependencyResolverInterface $dependency_resolver
35
+	 * @param LoaderInterface             $loader
36
+	 */
37
+	public function __construct(DependencyResolverInterface $dependency_resolver, LoaderInterface $loader)
38
+	{
39
+		$this->dependency_resolver = $dependency_resolver;
40
+		$this->loader = $loader;
41
+	}
42 42
 
43
-    /**
44
-     * @return DependencyResolverInterface
45
-     */
46
-    public function dependencyResolver()
47
-    {
48
-        return $this->dependency_resolver;
49
-    }
43
+	/**
44
+	 * @return DependencyResolverInterface
45
+	 */
46
+	public function dependencyResolver()
47
+	{
48
+		return $this->dependency_resolver;
49
+	}
50 50
 
51
-    /**
52
-     * @return LoaderInterface
53
-     */
54
-    public function loader()
55
-    {
56
-        return $this->loader;
57
-    }
51
+	/**
52
+	 * @return LoaderInterface
53
+	 */
54
+	public function loader()
55
+	{
56
+		return $this->loader;
57
+	}
58 58
 }
Please login to merge, or discard this patch.
core/domain/services/pue/Config.php 1 patch
Indentation   +127 added lines, -127 removed lines patch added patch discarded remove patch
@@ -16,131 +16,131 @@
 block discarded – undo
16 16
  */
17 17
 class Config
18 18
 {
19
-    /**
20
-     * @var EE_Network_Config
21
-     */
22
-    private $network_config;
23
-
24
-
25
-    /**
26
-     * @var EE_Config
27
-     */
28
-    private $ee_config;
29
-
30
-
31
-    public function __construct(EE_Network_Config $network_config, EE_Config $ee_config)
32
-    {
33
-        $this->network_config = $network_config;
34
-        $this->ee_config = $ee_config;
35
-    }
36
-
37
-
38
-    /**
39
-     * Get the site license key for the site.
40
-     */
41
-    public function siteLicenseKey()
42
-    {
43
-        return $this->network_config->core->site_license_key;
44
-    }
45
-
46
-
47
-    public function i18nDomain()
48
-    {
49
-        return 'event_espresso';
50
-    }
51
-
52
-
53
-    public function checkPeriod()
54
-    {
55
-        return 24;
56
-    }
57
-
58
-
59
-    public function optionKey()
60
-    {
61
-        return 'ee_site_license_key';
62
-    }
63
-
64
-
65
-    public function optionsPageSlug()
66
-    {
67
-        return 'espresso_general_settings';
68
-    }
69
-
70
-
71
-    public function hostServerUrl()
72
-    {
73
-        return defined('PUE_UPDATES_ENDPOINT')
74
-            ? PUE_UPDATES_ENDPOINT
75
-            : 'https://eventespresso.com';
76
-    }
77
-
78
-
79
-    public function pluginSlug()
80
-    {
81
-        // Note: PUE uses a simple preg_match to determine what type is currently installed based on version number.
82
-        //  So it's important that you use a key for the version type that is unique and not found in another key.
83
-        // For example:
84
-        // $plugin_slug['premium']['p'] = 'some-premium-slug';
85
-        // $plugin_slug['prerelease']['pr'] = 'some-pre-release-slug';
86
-        // The above would not work because "p" is found in both keys for the version type. ( i.e 1.0.p vs 1.0.pr )
87
-        // so doing something like:
88
-        // $plugin_slug['premium']['p'] = 'some-premium-slug';
89
-        // $plugin_slug['prerelease']['b'] = 'some-pre-release-slug';
90
-        // ..WOULD work!
91
-        return array(
92
-            'free'       => array('decaf' => 'event-espresso-core-decaf'),
93
-            'premium'    => array('p' => 'event-espresso-core-reg'),
94
-            'prerelease' => array('beta' => 'event-espresso-core-pr'),
95
-        );
96
-    }
97
-
98
-
99
-    /**
100
-     * Return whether the site is opted in for UXIP or not.
101
-     *
102
-     * @return bool
103
-     */
104
-    public function isOptedInForUxip()
105
-    {
106
-        return filter_var($this->ee_config->core->ee_ueip_optin, FILTER_VALIDATE_BOOLEAN);
107
-    }
108
-
109
-
110
-    /**
111
-     * Return whether the site has been notified about UXIP or not.
112
-     *
113
-     * @return bool
114
-     */
115
-    public function hasNotifiedForUxip()
116
-    {
117
-        return filter_var($this->ee_config->core->ee_ueip_has_notified, FILTER_VALIDATE_BOOLEAN);
118
-    }
119
-
120
-
121
-    /**
122
-     * Set the site opted in for UXIP.
123
-     */
124
-    public function setHasOptedInForUxip()
125
-    {
126
-        $this->ee_config->core->ee_ueip_optin = true;
127
-        $this->ee_config->update_espresso_config(false, false);
128
-    }
129
-
130
-
131
-    /**
132
-     * Set the site opted out for UXIP
133
-     */
134
-    public function setHasOptedOutForUxip()
135
-    {
136
-        $this->ee_config->core->ee_ueip_optin = false;
137
-        $this->ee_config->update_espresso_config(false, false);
138
-    }
139
-
140
-
141
-    public function setHasNotifiedAboutUxip()
142
-    {
143
-        $this->ee_config->core->ee_ueip_has_notified = true;
144
-        $this->ee_config->update_espresso_config(false, false);
145
-    }
19
+	/**
20
+	 * @var EE_Network_Config
21
+	 */
22
+	private $network_config;
23
+
24
+
25
+	/**
26
+	 * @var EE_Config
27
+	 */
28
+	private $ee_config;
29
+
30
+
31
+	public function __construct(EE_Network_Config $network_config, EE_Config $ee_config)
32
+	{
33
+		$this->network_config = $network_config;
34
+		$this->ee_config = $ee_config;
35
+	}
36
+
37
+
38
+	/**
39
+	 * Get the site license key for the site.
40
+	 */
41
+	public function siteLicenseKey()
42
+	{
43
+		return $this->network_config->core->site_license_key;
44
+	}
45
+
46
+
47
+	public function i18nDomain()
48
+	{
49
+		return 'event_espresso';
50
+	}
51
+
52
+
53
+	public function checkPeriod()
54
+	{
55
+		return 24;
56
+	}
57
+
58
+
59
+	public function optionKey()
60
+	{
61
+		return 'ee_site_license_key';
62
+	}
63
+
64
+
65
+	public function optionsPageSlug()
66
+	{
67
+		return 'espresso_general_settings';
68
+	}
69
+
70
+
71
+	public function hostServerUrl()
72
+	{
73
+		return defined('PUE_UPDATES_ENDPOINT')
74
+			? PUE_UPDATES_ENDPOINT
75
+			: 'https://eventespresso.com';
76
+	}
77
+
78
+
79
+	public function pluginSlug()
80
+	{
81
+		// Note: PUE uses a simple preg_match to determine what type is currently installed based on version number.
82
+		//  So it's important that you use a key for the version type that is unique and not found in another key.
83
+		// For example:
84
+		// $plugin_slug['premium']['p'] = 'some-premium-slug';
85
+		// $plugin_slug['prerelease']['pr'] = 'some-pre-release-slug';
86
+		// The above would not work because "p" is found in both keys for the version type. ( i.e 1.0.p vs 1.0.pr )
87
+		// so doing something like:
88
+		// $plugin_slug['premium']['p'] = 'some-premium-slug';
89
+		// $plugin_slug['prerelease']['b'] = 'some-pre-release-slug';
90
+		// ..WOULD work!
91
+		return array(
92
+			'free'       => array('decaf' => 'event-espresso-core-decaf'),
93
+			'premium'    => array('p' => 'event-espresso-core-reg'),
94
+			'prerelease' => array('beta' => 'event-espresso-core-pr'),
95
+		);
96
+	}
97
+
98
+
99
+	/**
100
+	 * Return whether the site is opted in for UXIP or not.
101
+	 *
102
+	 * @return bool
103
+	 */
104
+	public function isOptedInForUxip()
105
+	{
106
+		return filter_var($this->ee_config->core->ee_ueip_optin, FILTER_VALIDATE_BOOLEAN);
107
+	}
108
+
109
+
110
+	/**
111
+	 * Return whether the site has been notified about UXIP or not.
112
+	 *
113
+	 * @return bool
114
+	 */
115
+	public function hasNotifiedForUxip()
116
+	{
117
+		return filter_var($this->ee_config->core->ee_ueip_has_notified, FILTER_VALIDATE_BOOLEAN);
118
+	}
119
+
120
+
121
+	/**
122
+	 * Set the site opted in for UXIP.
123
+	 */
124
+	public function setHasOptedInForUxip()
125
+	{
126
+		$this->ee_config->core->ee_ueip_optin = true;
127
+		$this->ee_config->update_espresso_config(false, false);
128
+	}
129
+
130
+
131
+	/**
132
+	 * Set the site opted out for UXIP
133
+	 */
134
+	public function setHasOptedOutForUxip()
135
+	{
136
+		$this->ee_config->core->ee_ueip_optin = false;
137
+		$this->ee_config->update_espresso_config(false, false);
138
+	}
139
+
140
+
141
+	public function setHasNotifiedAboutUxip()
142
+	{
143
+		$this->ee_config->core->ee_ueip_has_notified = true;
144
+		$this->ee_config->update_espresso_config(false, false);
145
+	}
146 146
 }
Please login to merge, or discard this patch.
core/entities/models/JsonModelSchema.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -76,22 +76,22 @@  discard block
 block discarded – undo
76 76
     public function getModelSchemaForFields(array $model_fields, array $schema)
77 77
     {
78 78
         foreach ($model_fields as $field => $model_field) {
79
-            if (! $model_field instanceof EE_Model_Field_Base) {
79
+            if ( ! $model_field instanceof EE_Model_Field_Base) {
80 80
                 continue;
81 81
             }
82
-            $schema['properties'][ $field ] = $model_field->getSchema();
82
+            $schema['properties'][$field] = $model_field->getSchema();
83 83
 
84 84
             // if this is a primary key field add the primary key item
85 85
             if ($model_field instanceof EE_Primary_Key_Field_Base) {
86
-                $schema['properties'][ $field ]['primary_key'] = true;
86
+                $schema['properties'][$field]['primary_key'] = true;
87 87
                 if ($model_field instanceof EE_Primary_Key_Int_Field) {
88
-                    $schema['properties'][ $field ]['readonly'] = true;
88
+                    $schema['properties'][$field]['readonly'] = true;
89 89
                 }
90 90
             }
91 91
 
92 92
             // if this is a foreign key field add the foreign key item
93 93
             if ($model_field instanceof EE_Foreign_Key_Field_Base) {
94
-                $schema['properties'][ $field ]['foreign_key'] = array(
94
+                $schema['properties'][$field]['foreign_key'] = array(
95 95
                     'description' => esc_html__(
96 96
                         'This is a foreign key the points to the given models.',
97 97
                         'event_espresso'
@@ -115,18 +115,18 @@  discard block
 block discarded – undo
115 115
     public function getModelSchemaForRelations(array $relations_on_model, array $schema)
116 116
     {
117 117
         foreach ($relations_on_model as $model_name => $relation) {
118
-            if (! $relation instanceof EE_Model_Relation_Base) {
118
+            if ( ! $relation instanceof EE_Model_Relation_Base) {
119 119
                 continue;
120 120
             }
121 121
             $model_name_for_schema = $relation instanceof EE_Belongs_To_Relation
122 122
                 ? strtolower($model_name)
123 123
                 : EEH_Inflector::pluralize_and_lower($model_name);
124
-            $schema['properties'][ $model_name_for_schema ] = $relation->getSchema();
125
-            $schema['properties'][ $model_name_for_schema ]['relation_model'] = $model_name;
124
+            $schema['properties'][$model_name_for_schema] = $relation->getSchema();
125
+            $schema['properties'][$model_name_for_schema]['relation_model'] = $model_name;
126 126
 
127 127
             // links schema
128
-            $links_key = 'https://api.eventespresso.com/' . strtolower($model_name);
129
-            $schema['properties']['_links']['properties'][ $links_key ] = array(
128
+            $links_key = 'https://api.eventespresso.com/'.strtolower($model_name);
129
+            $schema['properties']['_links']['properties'][$links_key] = array(
130 130
                 'description' => esc_html__(
131 131
                     'Array of objects describing the link(s) for this relation resource.',
132 132
                     'event_espresso'
Please login to merge, or discard this patch.
Indentation   +235 added lines, -235 removed lines patch added patch discarded remove patch
@@ -24,256 +24,256 @@
 block discarded – undo
24 24
  */
25 25
 class JsonModelSchema
26 26
 {
27
-    /**
28
-     * @var EEM_Base
29
-     */
30
-    protected $model;
27
+	/**
28
+	 * @var EEM_Base
29
+	 */
30
+	protected $model;
31 31
 
32
-    /**
33
-     * @var CalculatedModelFields
34
-     */
35
-    protected $fields_calculator;
32
+	/**
33
+	 * @var CalculatedModelFields
34
+	 */
35
+	protected $fields_calculator;
36 36
 
37 37
 
38
-    /**
39
-     * JsonModelSchema constructor.
40
-     *
41
-     * @param EEM_Base              $model
42
-     * @param CalculatedModelFields $fields_calculator
43
-     */
44
-    public function __construct(EEM_Base $model, CalculatedModelFields $fields_calculator)
45
-    {
46
-        $this->model = $model;
47
-        $this->fields_calculator = $fields_calculator;
48
-    }
38
+	/**
39
+	 * JsonModelSchema constructor.
40
+	 *
41
+	 * @param EEM_Base              $model
42
+	 * @param CalculatedModelFields $fields_calculator
43
+	 */
44
+	public function __construct(EEM_Base $model, CalculatedModelFields $fields_calculator)
45
+	{
46
+		$this->model = $model;
47
+		$this->fields_calculator = $fields_calculator;
48
+	}
49 49
 
50 50
 
51
-    /**
52
-     * Return the schema for a given model from a given model.
53
-     *
54
-     * @return array
55
-     */
56
-    public function getModelSchema()
57
-    {
58
-        return $this->getModelSchemaForRelations(
59
-            $this->model->relation_settings(),
60
-            $this->getModelSchemaForFields(
61
-                $this->model->field_settings(),
62
-                $this->getInitialSchemaStructure()
63
-            )
64
-        );
65
-    }
51
+	/**
52
+	 * Return the schema for a given model from a given model.
53
+	 *
54
+	 * @return array
55
+	 */
56
+	public function getModelSchema()
57
+	{
58
+		return $this->getModelSchemaForRelations(
59
+			$this->model->relation_settings(),
60
+			$this->getModelSchemaForFields(
61
+				$this->model->field_settings(),
62
+				$this->getInitialSchemaStructure()
63
+			)
64
+		);
65
+	}
66 66
 
67 67
 
68
-    /**
69
-     * Get the schema for a given set of model fields.
70
-     *
71
-     * @param EE_Model_Field_Base[] $model_fields
72
-     * @param array                  $schema
73
-     * @return array
74
-     */
75
-    public function getModelSchemaForFields(array $model_fields, array $schema)
76
-    {
77
-        foreach ($model_fields as $field => $model_field) {
78
-            if (! $model_field instanceof EE_Model_Field_Base) {
79
-                continue;
80
-            }
81
-            $schema['properties'][ $field ] = $model_field->getSchema();
68
+	/**
69
+	 * Get the schema for a given set of model fields.
70
+	 *
71
+	 * @param EE_Model_Field_Base[] $model_fields
72
+	 * @param array                  $schema
73
+	 * @return array
74
+	 */
75
+	public function getModelSchemaForFields(array $model_fields, array $schema)
76
+	{
77
+		foreach ($model_fields as $field => $model_field) {
78
+			if (! $model_field instanceof EE_Model_Field_Base) {
79
+				continue;
80
+			}
81
+			$schema['properties'][ $field ] = $model_field->getSchema();
82 82
 
83
-            // if this is a primary key field add the primary key item
84
-            if ($model_field instanceof EE_Primary_Key_Field_Base) {
85
-                $schema['properties'][ $field ]['primary_key'] = true;
86
-                if ($model_field instanceof EE_Primary_Key_Int_Field) {
87
-                    $schema['properties'][ $field ]['readonly'] = true;
88
-                }
89
-            }
83
+			// if this is a primary key field add the primary key item
84
+			if ($model_field instanceof EE_Primary_Key_Field_Base) {
85
+				$schema['properties'][ $field ]['primary_key'] = true;
86
+				if ($model_field instanceof EE_Primary_Key_Int_Field) {
87
+					$schema['properties'][ $field ]['readonly'] = true;
88
+				}
89
+			}
90 90
 
91
-            // if this is a foreign key field add the foreign key item
92
-            if ($model_field instanceof EE_Foreign_Key_Field_Base) {
93
-                $schema['properties'][ $field ]['foreign_key'] = array(
94
-                    'description' => esc_html__(
95
-                        'This is a foreign key the points to the given models.',
96
-                        'event_espresso'
97
-                    ),
98
-                    'type'        => 'array',
99
-                    'enum'        => $model_field->get_model_class_names_pointed_to(),
100
-                );
101
-            }
102
-        }
103
-        return $schema;
104
-    }
91
+			// if this is a foreign key field add the foreign key item
92
+			if ($model_field instanceof EE_Foreign_Key_Field_Base) {
93
+				$schema['properties'][ $field ]['foreign_key'] = array(
94
+					'description' => esc_html__(
95
+						'This is a foreign key the points to the given models.',
96
+						'event_espresso'
97
+					),
98
+					'type'        => 'array',
99
+					'enum'        => $model_field->get_model_class_names_pointed_to(),
100
+				);
101
+			}
102
+		}
103
+		return $schema;
104
+	}
105 105
 
106 106
 
107
-    /**
108
-     * Get the schema for a given set of model relations
109
-     *
110
-     * @param EE_Model_Relation_Base[] $relations_on_model
111
-     * @param array                    $schema
112
-     * @return array
113
-     */
114
-    public function getModelSchemaForRelations(array $relations_on_model, array $schema)
115
-    {
116
-        foreach ($relations_on_model as $model_name => $relation) {
117
-            if (! $relation instanceof EE_Model_Relation_Base) {
118
-                continue;
119
-            }
120
-            $model_name_for_schema = $relation instanceof EE_Belongs_To_Relation
121
-                ? strtolower($model_name)
122
-                : EEH_Inflector::pluralize_and_lower($model_name);
123
-            $schema['properties'][ $model_name_for_schema ] = $relation->getSchema();
124
-            $schema['properties'][ $model_name_for_schema ]['relation_model'] = $model_name;
107
+	/**
108
+	 * Get the schema for a given set of model relations
109
+	 *
110
+	 * @param EE_Model_Relation_Base[] $relations_on_model
111
+	 * @param array                    $schema
112
+	 * @return array
113
+	 */
114
+	public function getModelSchemaForRelations(array $relations_on_model, array $schema)
115
+	{
116
+		foreach ($relations_on_model as $model_name => $relation) {
117
+			if (! $relation instanceof EE_Model_Relation_Base) {
118
+				continue;
119
+			}
120
+			$model_name_for_schema = $relation instanceof EE_Belongs_To_Relation
121
+				? strtolower($model_name)
122
+				: EEH_Inflector::pluralize_and_lower($model_name);
123
+			$schema['properties'][ $model_name_for_schema ] = $relation->getSchema();
124
+			$schema['properties'][ $model_name_for_schema ]['relation_model'] = $model_name;
125 125
 
126
-            // links schema
127
-            $links_key = 'https://api.eventespresso.com/' . strtolower($model_name);
128
-            $schema['properties']['_links']['properties'][ $links_key ] = array(
129
-                'description' => esc_html__(
130
-                    'Array of objects describing the link(s) for this relation resource.',
131
-                    'event_espresso'
132
-                ),
133
-                'type' => 'array',
134
-                'readonly' => true,
135
-                'items' => array(
136
-                    'type' => 'object',
137
-                    'properties' => array(
138
-                        'href' => array(
139
-                            'type' => 'string',
140
-                            'description' => sprintf(
141
-                                // translators: placeholder is the model name for the relation.
142
-                                esc_html__(
143
-                                    'The link to the resource for the %s relation(s) to this entity',
144
-                                    'event_espresso'
145
-                                ),
146
-                                $model_name
147
-                            ),
148
-                        ),
149
-                        'single' => array(
150
-                            'type' => 'boolean',
151
-                            'description' => sprintf(
152
-                                // translators: placeholder is the model name for the relation.
153
-                                esc_html__(
154
-                                    'Whether or not there is only a single %s relation to this entity',
155
-                                    'event_espresso'
156
-                                ),
157
-                                $model_name
158
-                            ),
159
-                        ),
160
-                    ),
161
-                    'additionalProperties' => false
162
-                ),
163
-            );
164
-        }
165
-        return $schema;
166
-    }
126
+			// links schema
127
+			$links_key = 'https://api.eventespresso.com/' . strtolower($model_name);
128
+			$schema['properties']['_links']['properties'][ $links_key ] = array(
129
+				'description' => esc_html__(
130
+					'Array of objects describing the link(s) for this relation resource.',
131
+					'event_espresso'
132
+				),
133
+				'type' => 'array',
134
+				'readonly' => true,
135
+				'items' => array(
136
+					'type' => 'object',
137
+					'properties' => array(
138
+						'href' => array(
139
+							'type' => 'string',
140
+							'description' => sprintf(
141
+								// translators: placeholder is the model name for the relation.
142
+								esc_html__(
143
+									'The link to the resource for the %s relation(s) to this entity',
144
+									'event_espresso'
145
+								),
146
+								$model_name
147
+							),
148
+						),
149
+						'single' => array(
150
+							'type' => 'boolean',
151
+							'description' => sprintf(
152
+								// translators: placeholder is the model name for the relation.
153
+								esc_html__(
154
+									'Whether or not there is only a single %s relation to this entity',
155
+									'event_espresso'
156
+								),
157
+								$model_name
158
+							),
159
+						),
160
+					),
161
+					'additionalProperties' => false
162
+				),
163
+			);
164
+		}
165
+		return $schema;
166
+	}
167 167
 
168 168
 
169
-    /**
170
-     * Outputs the schema header for a model.
171
-     *
172
-     * @return array
173
-     */
174
-    public function getInitialSchemaStructure()
175
-    {
176
-        return array(
177
-            '$schema'    => 'http://json-schema.org/draft-04/schema#',
178
-            'title'      => $this->model->get_this_model_name(),
179
-            'type'       => 'object',
180
-            'properties' => array(
181
-                'link' => array(
182
-                    'description' => esc_html__(
183
-                        'Link to event on WordPress site hosting events.',
184
-                        'event_espresso'
185
-                    ),
186
-                    'type' => 'string',
187
-                    'readonly' => true,
188
-                ),
189
-                '_links' => array(
190
-                    'description' => esc_html__(
191
-                        'Various links for resources related to the entity.',
192
-                        'event_espresso'
193
-                    ),
194
-                    'type' => 'object',
195
-                    'readonly' => true,
196
-                    'properties' => array(
197
-                        'self' => array(
198
-                            'description' => esc_html__(
199
-                                'Link to this entities resource.',
200
-                                'event_espresso'
201
-                            ),
202
-                            'type' => 'array',
203
-                            'items' => array(
204
-                                'type' => 'object',
205
-                                'properties' => array(
206
-                                    'href' => array(
207
-                                        'type' => 'string',
208
-                                    ),
209
-                                ),
210
-                                'additionalProperties' => false
211
-                            ),
212
-                            'readonly' => true
213
-                        ),
214
-                        'collection' => array(
215
-                            'description' => esc_html__(
216
-                                'Link to this entities collection resource.',
217
-                                'event_espresso'
218
-                            ),
219
-                            'type' => 'array',
220
-                            'items' => array(
221
-                                'type' => 'object',
222
-                                'properties' => array(
223
-                                    'href' => array(
224
-                                        'type' => 'string'
225
-                                    ),
226
-                                ),
227
-                                'additionalProperties' => false
228
-                            ),
229
-                            'readonly' => true
230
-                        ),
231
-                    ),
232
-                    'additionalProperties' => false,
233
-                ),
234
-                '_calculated_fields' => array_merge(
235
-                    $this->fields_calculator->getJsonSchemaForModel($this->model),
236
-                    array(
237
-                        '_protected' => $this->getProtectedFieldsSchema()
238
-                    )
239
-                ),
240
-                '_protected' => $this->getProtectedFieldsSchema()
241
-            ),
242
-            'additionalProperties' => false,
243
-        );
244
-    }
169
+	/**
170
+	 * Outputs the schema header for a model.
171
+	 *
172
+	 * @return array
173
+	 */
174
+	public function getInitialSchemaStructure()
175
+	{
176
+		return array(
177
+			'$schema'    => 'http://json-schema.org/draft-04/schema#',
178
+			'title'      => $this->model->get_this_model_name(),
179
+			'type'       => 'object',
180
+			'properties' => array(
181
+				'link' => array(
182
+					'description' => esc_html__(
183
+						'Link to event on WordPress site hosting events.',
184
+						'event_espresso'
185
+					),
186
+					'type' => 'string',
187
+					'readonly' => true,
188
+				),
189
+				'_links' => array(
190
+					'description' => esc_html__(
191
+						'Various links for resources related to the entity.',
192
+						'event_espresso'
193
+					),
194
+					'type' => 'object',
195
+					'readonly' => true,
196
+					'properties' => array(
197
+						'self' => array(
198
+							'description' => esc_html__(
199
+								'Link to this entities resource.',
200
+								'event_espresso'
201
+							),
202
+							'type' => 'array',
203
+							'items' => array(
204
+								'type' => 'object',
205
+								'properties' => array(
206
+									'href' => array(
207
+										'type' => 'string',
208
+									),
209
+								),
210
+								'additionalProperties' => false
211
+							),
212
+							'readonly' => true
213
+						),
214
+						'collection' => array(
215
+							'description' => esc_html__(
216
+								'Link to this entities collection resource.',
217
+								'event_espresso'
218
+							),
219
+							'type' => 'array',
220
+							'items' => array(
221
+								'type' => 'object',
222
+								'properties' => array(
223
+									'href' => array(
224
+										'type' => 'string'
225
+									),
226
+								),
227
+								'additionalProperties' => false
228
+							),
229
+							'readonly' => true
230
+						),
231
+					),
232
+					'additionalProperties' => false,
233
+				),
234
+				'_calculated_fields' => array_merge(
235
+					$this->fields_calculator->getJsonSchemaForModel($this->model),
236
+					array(
237
+						'_protected' => $this->getProtectedFieldsSchema()
238
+					)
239
+				),
240
+				'_protected' => $this->getProtectedFieldsSchema()
241
+			),
242
+			'additionalProperties' => false,
243
+		);
244
+	}
245 245
 
246
-    /**
247
-     * Returns an array of JSON schema to describe the _protected property on responses
248
-     * @since 4.9.74.p
249
-     * @return array
250
-     */
251
-    protected function getProtectedFieldsSchema()
252
-    {
253
-        return array(
254
-            'description' => esc_html__('Array of property names whose values were replaced with their default (because they are related to a password-protected entity.)', 'event_espresso'),
255
-            'type' => 'array',
256
-            'items' => array(
257
-                'description' => esc_html__('Each name corresponds to a property that is protected by password for this entity and has its default value returned in the response.', 'event_espresso'),
258
-                'type' => 'string',
259
-                'readonly' => true,
260
-            ),
261
-            'readonly' => true
262
-        );
263
-    }
246
+	/**
247
+	 * Returns an array of JSON schema to describe the _protected property on responses
248
+	 * @since 4.9.74.p
249
+	 * @return array
250
+	 */
251
+	protected function getProtectedFieldsSchema()
252
+	{
253
+		return array(
254
+			'description' => esc_html__('Array of property names whose values were replaced with their default (because they are related to a password-protected entity.)', 'event_espresso'),
255
+			'type' => 'array',
256
+			'items' => array(
257
+				'description' => esc_html__('Each name corresponds to a property that is protected by password for this entity and has its default value returned in the response.', 'event_espresso'),
258
+				'type' => 'string',
259
+				'readonly' => true,
260
+			),
261
+			'readonly' => true
262
+		);
263
+	}
264 264
 
265 265
 
266
-    /**
267
-     * Allows one to just use the object as a string to get the json.
268
-     * eg.
269
-     * $json_schema = new JsonModelSchema(EEM_Event::instance(), new CalculatedModelFields);
270
-     * // if echoed, would convert schema to a json formatted string.
271
-     *
272
-     * @return string
273
-     */
274
-    public function __toString()
275
-    {
276
-        $schema = wp_json_encode($this->getModelSchema());
277
-        return is_string($schema) ? $schema : '';
278
-    }
266
+	/**
267
+	 * Allows one to just use the object as a string to get the json.
268
+	 * eg.
269
+	 * $json_schema = new JsonModelSchema(EEM_Event::instance(), new CalculatedModelFields);
270
+	 * // if echoed, would convert schema to a json formatted string.
271
+	 *
272
+	 * @return string
273
+	 */
274
+	public function __toString()
275
+	{
276
+		$schema = wp_json_encode($this->getModelSchema());
277
+		return is_string($schema) ? $schema : '';
278
+	}
279 279
 }
Please login to merge, or discard this patch.
core/libraries/rest_api/calculations/CalculatedModelFieldsFactory.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
      */
41 41
     public function createFromModel($model_name)
42 42
     {
43
-        return $this->createFromClassname('EventEspresso\core\libraries\rest_api\calculations\\' . $model_name);
43
+        return $this->createFromClassname('EventEspresso\core\libraries\rest_api\calculations\\'.$model_name);
44 44
     }
45 45
 
46 46
     /**
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
     public function createFromClassname($calculator_classname)
52 52
     {
53 53
         $calculator = $this->loader->getShared($calculator_classname);
54
-        if (!$calculator instanceof Base) {
54
+        if ( ! $calculator instanceof Base) {
55 55
             throw new UnexpectedEntityException(
56 56
                 $calculator_classname,
57 57
                 'EventEspresso\core\libraries\rest_api\calculations\Base'
Please login to merge, or discard this patch.
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -18,46 +18,46 @@
 block discarded – undo
18 18
  */
19 19
 class CalculatedModelFieldsFactory
20 20
 {
21
-    private $loader;
21
+	private $loader;
22 22
 
23
-    /**
24
-     * CalculatedModelFieldsFactory constructor.
25
-     * @param LoaderInterface $loader
26
-     */
27
-    public function __construct(LoaderInterface $loader)
28
-    {
29
-        $this->loader = $loader;
30
-    }
23
+	/**
24
+	 * CalculatedModelFieldsFactory constructor.
25
+	 * @param LoaderInterface $loader
26
+	 */
27
+	public function __construct(LoaderInterface $loader)
28
+	{
29
+		$this->loader = $loader;
30
+	}
31 31
 
32
-    /**
33
-     * Creates the calculator class that corresponds to that particular model
34
-     * @since 4.9.68.p
35
-     * @param string $model_name
36
-     * @return Base
37
-     * @throws UnexpectedEntityException
38
-     */
39
-    public function createFromModel($model_name)
40
-    {
41
-        return $this->createFromClassname('EventEspresso\core\libraries\rest_api\calculations\\' . $model_name);
42
-    }
32
+	/**
33
+	 * Creates the calculator class that corresponds to that particular model
34
+	 * @since 4.9.68.p
35
+	 * @param string $model_name
36
+	 * @return Base
37
+	 * @throws UnexpectedEntityException
38
+	 */
39
+	public function createFromModel($model_name)
40
+	{
41
+		return $this->createFromClassname('EventEspresso\core\libraries\rest_api\calculations\\' . $model_name);
42
+	}
43 43
 
44
-    /**
45
-     * Creates the calculator class that corresponds to that classname and verifies it's of the correct type
46
-     * @param string $calculator_classname
47
-     * @return Base
48
-     * @throws UnexpectedEntityException
49
-     */
50
-    public function createFromClassname($calculator_classname)
51
-    {
52
-        $calculator = $this->loader->getShared($calculator_classname);
53
-        if (!$calculator instanceof Base) {
54
-            throw new UnexpectedEntityException(
55
-                $calculator_classname,
56
-                'EventEspresso\core\libraries\rest_api\calculations\Base'
57
-            );
58
-        }
59
-        return $calculator;
60
-    }
44
+	/**
45
+	 * Creates the calculator class that corresponds to that classname and verifies it's of the correct type
46
+	 * @param string $calculator_classname
47
+	 * @return Base
48
+	 * @throws UnexpectedEntityException
49
+	 */
50
+	public function createFromClassname($calculator_classname)
51
+	{
52
+		$calculator = $this->loader->getShared($calculator_classname);
53
+		if (!$calculator instanceof Base) {
54
+			throw new UnexpectedEntityException(
55
+				$calculator_classname,
56
+				'EventEspresso\core\libraries\rest_api\calculations\Base'
57
+			);
58
+		}
59
+		return $calculator;
60
+	}
61 61
 }
62 62
 // End of file CalculationsFactory.php
63 63
 // Location: EventEspresso\core\libraries\rest_api\calculations/CalculationsFactory.php
Please login to merge, or discard this patch.