Completed
Push — develop ( e63648...3edd81 )
by Zack
19:54 queued 12:35
created

Core::__get()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3.0261

Importance

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