Completed
Push — master ( 14e1a2...154914 )
by Zack
18:57 queued 01:08
created

Core   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 246
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 6

Test Coverage

Coverage 9.09%

Importance

Changes 0
Metric Value
dl 0
loc 246
ccs 9
cts 99
cp 0.0909
rs 10
c 0
b 0
f 0
wmc 13
lcom 2
cbo 6

8 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 6 2
A bootstrap() 0 4 1
A __construct() 0 4 1
A __clone() 0 1 1
A __wakeup() 0 1 1
B init() 0 152 3
A __get() 0 11 3
A __set() 0 2 1
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 16 and the first side effect is on line 6.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
namespace GV;
3
4
/** If this file is called directly, abort. */
5
if ( ! defined( 'GRAVITYVIEW_DIR' ) ) {
6
	die();
7
}
8
9
/**
10
 * The core GravityView API.
11
 *
12
 * Returned by the wrapper gravityview() global function, exposes
13
 * all the required public functionality and classes, sets up global
14
 * state depending on current request context, etc.
15
 */
16
final class Core {
17
	/**
18
	 * @var \GV\Core The \GV\Core static instance.
19
	 */
20
	private static $__instance = null;
21
22
	/**
23
	 * @var \GV\Plugin The WordPress plugin context.
24
	 *
25
	 * @api
26
	 * @since 2.0
27
	 */
28
	public $plugin;
29
30
	/**
31
	 * @var \GV\Request The global request.
32
	 *
33
	 * @api
34
	 * @since 2.0
35
	 */
36
	public $request;
37
38
	/**
39
	 * @var \GV\Logger
40
	 *
41
	 * @api
42
	 * @since 2.0
43
	 */
44
	public $log;
45
46
	/**
47
	 * Get the global instance of \GV\Core.
48
	 *
49
	 * @return \GV\Core The global instance of GravityView Core.
50
	 */
51 95
	public static function get() {
52 95
		if ( ! self::$__instance instanceof self ) {
53
			self::$__instance = new self;
54
		}
55 95
		return self::$__instance;
56
	}
57
58
	/**
59
	 * Very early initialization.
60
	 *
61
	 * Activation handlers, rewrites, post type registration.
62
	 */
63
	public static function bootstrap() {
64
		require_once dirname( __FILE__ ) . '/class-gv-plugin.php';
65
		Plugin::get()->register_activation_hooks();
66
	}
67
68
	/**
69
	 * Bootstrap.
70
	 *
71
	 * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
72
	 */
73
	private function __construct() {
74
		self::$__instance = $this;
75
		$this->init();
76
	}
77
78
	/**
79
	 * Early initialization.
80
	 *
81
	 * Loads dependencies, sets up the object, adds hooks, etc.
82
	 *
83
	 * @return void
84
	 */
85
	private function init() {
86
		$this->plugin = Plugin::get();
87
88
		/** Enable logging. */
89
		require_once $this->plugin->dir( 'future/includes/class-gv-logger.php' );
90
		/**
91
		 * @filter `gravityview/logger` Filter the logger instance being used for logging.
92
		 * @param \GV\Logger $logger The logger instance.
93
		 */
94
		$this->log = apply_filters( 'gravityview/logger', new WP_Action_Logger() );
95
96
		/**
97
		 * Utilities.
98
		 */
99
		require_once $this->plugin->dir( 'future/includes/class-gv-utils.php' );
100
101
		/** The Settings. */
102
		require_once $this->plugin->dir( 'future/includes/class-gv-settings.php' );
103
		require_once $this->plugin->dir( 'future/includes/class-gv-settings-view.php' );
104
105
		/** Request. */
106
		require_once $this->plugin->dir( 'future/includes/class-gv-request.php' );
107
108
		if ( Request::is_admin() ) {
109
			$this->request = new Admin_Request();
110
		} else {
111
			$this->request = new Frontend_Request();
112
		}
113
114
		/** Require critical legacy core files. @todo Deprecate */
115
		require_once $this->plugin->dir( 'includes/helper-functions.php' );
116
		require_once $this->plugin->dir( 'includes/class-common.php');
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
117
		require_once $this->plugin->dir( 'includes/connector-functions.php');
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
118
		require_once $this->plugin->dir( 'includes/class-gravityview-compatibility.php' );
119
		require_once $this->plugin->dir( 'includes/class-gravityview-roles-capabilities.php' );
120
		require_once $this->plugin->dir( 'includes/class-gravityview-admin-notices.php' );
121
		require_once $this->plugin->dir( 'includes/class-admin.php' );
122
		require_once $this->plugin->dir( 'includes/class-post-types.php');
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
123
		require_once $this->plugin->dir( 'includes/class-cache.php');
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
124
125
		/**
126
		 * GravityView extensions and widgets.
127
		 */
128
		require_once $this->plugin->dir( 'future/includes/class-gv-extension.php' );
129
		require_once $this->plugin->dir( 'future/includes/class-gv-widget.php' );
130
131
		/** More legacy core. @todo Deprecate */
132
		$this->plugin->include_legacy_core();
133
134
		/**
135
		 * Stop all further functionality from loading if the WordPress
136
		 * plugin is incompatible with the current environment.
137
		 *
138
		 * Saves some time and memory.
139
		 */
140
		if ( ! $this->plugin->is_compatible() ) {
141
			$this->log->error( 'GravityView 2.0 is not compatible with this environment. Stopped loading.' );
142
			return;
143
		}
144
145
		/** Register the gravityview post type upon WordPress core init. */
146
		require_once $this->plugin->dir( 'future/includes/class-gv-view.php' );
147
		add_action( 'init', array( '\GV\View', 'register_post_type' ) );
148
		add_action( 'the_content', array( '\GV\View', 'content' ) );
149
150
		/** Add rewrite endpoint for single-entry URLs. */
151
		require_once $this->plugin->dir( 'future/includes/class-gv-entry.php' );
152
		add_action( 'init', array( '\GV\Entry', 'add_rewrite_endpoint' ) );
153
154
		/** REST API */
155
		require_once $this->plugin->dir( 'future/includes/rest/class-gv-rest-core.php' );
156
		add_action( 'rest_api_init', array( '\GV\REST\Core', 'init' ) );
157
158
		/** Generate custom slugs on entry save. @todo Deprecate. */
159
		add_action( 'gform_entry_created', array( '\GravityView_API', 'entry_create_custom_slug' ), 10, 2 );
160
161
		/** Shortcodes */
162
		require_once $this->plugin->dir( 'future/includes/class-gv-shortcode.php' );
163
		require_once $this->plugin->dir( 'future/includes/class-gv-shortcode-gravityview.php' );
164
		require_once $this->plugin->dir( 'future/includes/class-gv-shortcode-gventry.php' );
165
		require_once $this->plugin->dir( 'future/includes/class-gv-shortcode-gvfield.php' );
166
		add_action( 'init', array( '\GV\Shortcodes\gravityview', 'add' ) );
167
		add_action( 'init', array( '\GV\Shortcodes\gventry', 'add' ) );
168
		add_action( 'init', array( '\GV\Shortcodes\gvfield', 'add' ) );
169
		
170
		/** oEmbed */
171
		require_once $this->plugin->dir( 'future/includes/class-gv-oembed.php' );
172
		add_action( 'init', array( '\GV\oEmbed', 'init' ), 11 );
173
174
		/** Our Source generic and beloved source and form backend implementations. */
175
		require_once $this->plugin->dir( 'future/includes/class-gv-source.php' );
176
		require_once $this->plugin->dir( 'future/includes/class-gv-source-internal.php' );
177
		require_once $this->plugin->dir( 'future/includes/class-gv-form.php' );
178
		require_once $this->plugin->dir( 'future/includes/class-gv-form-gravityforms.php' );
179
180
		/** Joins */
181
		require_once $this->plugin->dir( 'future/includes/class-gv-form-join.php' );
182
183
		/** Our Entry generic and beloved entry backend implementations. */
184
		require_once $this->plugin->dir( 'future/includes/class-gv-entry-gravityforms.php' );
185
		require_once $this->plugin->dir( 'future/includes/class-gv-entry-multi.php' );
186
187
		/** Context is everything. */
188
		require_once $this->plugin->dir( 'future/includes/class-gv-context.php' );
189
		require_once $this->plugin->dir( 'future/includes/class-gv-context-template.php' );
190
191
		/** Our Field generic and implementations. */
192
		require_once $this->plugin->dir( 'future/includes/class-gv-field.php' );
193
		require_once $this->plugin->dir( 'future/includes/class-gv-field-gravityforms.php' );
194
		require_once $this->plugin->dir( 'future/includes/class-gv-field-internal.php' );
195
196
		/** Get the collections ready. */
197
		require_once $this->plugin->dir( 'future/includes/class-gv-collection.php' );
198
		require_once $this->plugin->dir( 'future/includes/class-gv-collection-form.php' );
199
		require_once $this->plugin->dir( 'future/includes/class-gv-collection-field.php' );
200
		require_once $this->plugin->dir( 'future/includes/class-gv-collection-entry.php' );
201
		require_once $this->plugin->dir( 'future/includes/class-gv-collection-widget.php' );
202
		require_once $this->plugin->dir( 'future/includes/class-gv-collection-view.php' );
203
204
		/** The sorting, filtering and paging classes. */
205
		require_once $this->plugin->dir( 'future/includes/class-gv-collection-entry-filter.php' );
206
		require_once $this->plugin->dir( 'future/includes/class-gv-collection-entry-sort.php' );
207
		require_once $this->plugin->dir( 'future/includes/class-gv-collection-entry-offset.php' );
208
209
		/** The Renderers. */
210
		require_once $this->plugin->dir( 'future/includes/class-gv-renderer.php' );
211
		require_once $this->plugin->dir( 'future/includes/class-gv-renderer-view.php' );
212
		require_once $this->plugin->dir( 'future/includes/class-gv-renderer-entry.php' );
213
		require_once $this->plugin->dir( 'future/includes/class-gv-renderer-entry-edit.php' );
214
		require_once $this->plugin->dir( 'future/includes/class-gv-renderer-field.php' );
215
216
		/** Templating. */
217
		require_once $this->plugin->dir( 'future/includes/class-gv-template.php' );
218
		require_once $this->plugin->dir( 'future/includes/class-gv-template-view.php' );
219
		require_once $this->plugin->dir( 'future/includes/class-gv-template-entry.php' );
220
		require_once $this->plugin->dir( 'future/includes/class-gv-template-field.php' );
221
		require_once $this->plugin->dir( 'future/includes/class-gv-template-legacy-override.php' );
222
223
		/** Magic. */
224
		require_once $this->plugin->dir( 'future/includes/class-gv-wrappers.php' );
225
226
		/** Cache busting. */
227
		add_action( 'clean_post_cache', '\GV\View::_flush_cache' );
228
229
		/**
230
		 * @action `gravityview/loaded` The core has been loaded.
231
		 *
232
		 * Note: this is a very early load hook, not all of WordPress core has been loaded here.
233
		 *  `init` hasn't been called yet.
234
		 */
235
		do_action( 'gravityview/loaded' );
236
	}
237
238
	private function __clone() { }
239
240
	private function __wakeup() { }
241
242
	/**
243
	 * Wrapper magic.
244
	 *
245
	 * Making developers happy, since 2017.
246
	 */
247 9
	public function __get( $key ) {
248 9
		static $views;
249
250
		switch ( $key ) {
251 9
			case 'views':
252 9
				if ( is_null( $views ) ) {
253 1
					$views = new \GV\Wrappers\views();
254
				}
255 9
				return $views;
256
		}
257
	}
258
259
	public function __set( $key, $value ) {
260
	}
261
}
262