Completed
Push — develop ( 0f41f0...4939cc )
by Zack
25:11 queued 19:29
created

Core   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 251
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 6

Test Coverage

Coverage 8.64%

Importance

Changes 0
Metric Value
dl 0
loc 251
ccs 9
cts 104
cp 0.0864
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 157 3
A __get() 0 11 3
A __set() 0 2 1
1
<?php
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\Admin_Request|\GV\Frontend_Request|\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 205
	public static function get() {
52 205
		if ( ! self::$__instance instanceof self ) {
53
			self::$__instance = new self;
54
		}
55 205
		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');
117
		require_once $this->plugin->dir( 'includes/connector-functions.php');
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');
123
		require_once $this->plugin->dir( 'includes/class-cache.php');
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( 'init', array( '\GV\View', 'add_rewrite_endpoint' ) );
149
		add_filter( 'map_meta_cap', array( '\GV\View', 'restrict' ), 11, 4 );
150
		add_action( 'template_redirect', array( '\GV\View', 'template_redirect' ) );
151
		add_action( 'the_content', array( '\GV\View', 'content' ) );
152
153
		/** Add rewrite endpoint for single-entry URLs. */
154
		require_once $this->plugin->dir( 'future/includes/class-gv-entry.php' );
155
		add_action( 'init', array( '\GV\Entry', 'add_rewrite_endpoint' ) );
156
157
		/** REST API */
158
		require_once $this->plugin->dir( 'future/includes/rest/class-gv-rest-core.php' );
159
		add_action( 'rest_api_init', array( '\GV\REST\Core', 'init' ) );
160
161
		/** Generate custom slugs on entry save. @todo Deprecate. */
162
		add_action( 'gform_entry_created', array( '\GravityView_API', 'entry_create_custom_slug' ), 10, 2 );
163
164
		/** Shortcodes */
165
		require_once $this->plugin->dir( 'future/includes/class-gv-shortcode.php' );
166
		require_once $this->plugin->dir( 'future/includes/class-gv-shortcode-gravityview.php' );
167
		require_once $this->plugin->dir( 'future/includes/class-gv-shortcode-gventry.php' );
168
		require_once $this->plugin->dir( 'future/includes/class-gv-shortcode-gvfield.php' );
169
		require_once $this->plugin->dir( 'future/includes/class-gv-shortcode-gvlogic.php' );
170
		add_action( 'init', array( '\GV\Shortcodes\gravityview', 'add' ) );
171
		add_action( 'init', array( '\GV\Shortcodes\gventry', 'add' ) );
172
		add_action( 'init', array( '\GV\Shortcodes\gvfield', 'add' ) );
173
		add_action( 'init', array( '\GV\Shortcodes\gvlogic', 'add' ) );
174
175
		/** oEmbed */
176
		require_once $this->plugin->dir( 'future/includes/class-gv-oembed.php' );
177
		add_action( 'init', array( '\GV\oEmbed', 'init' ), 11 );
178
179
		/** Our Source generic and beloved source and form backend implementations. */
180
		require_once $this->plugin->dir( 'future/includes/class-gv-source.php' );
181
		require_once $this->plugin->dir( 'future/includes/class-gv-source-internal.php' );
182
		require_once $this->plugin->dir( 'future/includes/class-gv-form.php' );
183
		require_once $this->plugin->dir( 'future/includes/class-gv-form-gravityforms.php' );
184
185
		/** Joins */
186
		require_once $this->plugin->dir( 'future/includes/class-gv-form-join.php' );
187
188
		/** Our Entry generic and beloved entry backend implementations. */
189
		require_once $this->plugin->dir( 'future/includes/class-gv-entry-gravityforms.php' );
190
		require_once $this->plugin->dir( 'future/includes/class-gv-entry-multi.php' );
191
192
		/** Context is everything. */
193
		require_once $this->plugin->dir( 'future/includes/class-gv-context.php' );
194
		require_once $this->plugin->dir( 'future/includes/class-gv-context-template.php' );
195
196
		/** Our Field generic and implementations. */
197
		require_once $this->plugin->dir( 'future/includes/class-gv-field.php' );
198
		require_once $this->plugin->dir( 'future/includes/class-gv-field-gravityforms.php' );
199
		require_once $this->plugin->dir( 'future/includes/class-gv-field-internal.php' );
200
201
		/** Get the collections ready. */
202
		require_once $this->plugin->dir( 'future/includes/class-gv-collection.php' );
203
		require_once $this->plugin->dir( 'future/includes/class-gv-collection-form.php' );
204
		require_once $this->plugin->dir( 'future/includes/class-gv-collection-field.php' );
205
		require_once $this->plugin->dir( 'future/includes/class-gv-collection-entry.php' );
206
		require_once $this->plugin->dir( 'future/includes/class-gv-collection-widget.php' );
207
		require_once $this->plugin->dir( 'future/includes/class-gv-collection-view.php' );
208
209
		/** The sorting, filtering and paging classes. */
210
		require_once $this->plugin->dir( 'future/includes/class-gv-collection-entry-filter.php' );
211
		require_once $this->plugin->dir( 'future/includes/class-gv-collection-entry-sort.php' );
212
		require_once $this->plugin->dir( 'future/includes/class-gv-collection-entry-offset.php' );
213
214
		/** The Renderers. */
215
		require_once $this->plugin->dir( 'future/includes/class-gv-renderer.php' );
216
		require_once $this->plugin->dir( 'future/includes/class-gv-renderer-view.php' );
217
		require_once $this->plugin->dir( 'future/includes/class-gv-renderer-entry.php' );
218
		require_once $this->plugin->dir( 'future/includes/class-gv-renderer-entry-edit.php' );
219
		require_once $this->plugin->dir( 'future/includes/class-gv-renderer-field.php' );
220
221
		/** Templating. */
222
		require_once $this->plugin->dir( 'future/includes/class-gv-template.php' );
223
		require_once $this->plugin->dir( 'future/includes/class-gv-template-view.php' );
224
		require_once $this->plugin->dir( 'future/includes/class-gv-template-entry.php' );
225
		require_once $this->plugin->dir( 'future/includes/class-gv-template-field.php' );
226
		require_once $this->plugin->dir( 'future/includes/class-gv-template-legacy-override.php' );
227
228
		/** Magic. */
229
		require_once $this->plugin->dir( 'future/includes/class-gv-wrappers.php' );
230
231
		/** Cache busting. */
232
		add_action( 'clean_post_cache', '\GV\View::_flush_cache' );
233
234
		/**
235
		 * @action `gravityview/loaded` The core has been loaded.
236
		 *
237
		 * Note: this is a very early load hook, not all of WordPress core has been loaded here.
238
		 *  `init` hasn't been called yet.
239
		 */
240
		do_action( 'gravityview/loaded' );
241
	}
242
243
	private function __clone() { }
244
245
	private function __wakeup() { }
246
247
	/**
248
	 * Wrapper magic.
249
	 *
250
	 * Making developers happy, since 2017.
251
	 */
252 16
	public function __get( $key ) {
253 16
		static $views;
254
255
		switch ( $key ) {
256 16
			case 'views':
257 16
				if ( is_null( $views ) ) {
258 1
					$views = new \GV\Wrappers\views();
259
				}
260 16
				return $views;
261
		}
262
	}
263
264
	public function __set( $key, $value ) {
265
	}
266
}
267