Completed
Push — develop ( 507546...65eb42 )
by Zack
05:37
created

future/includes/class-gv-core.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
namespace GV;
3
4
/** If this file is called directly, abort. */
5
if ( ! defined( 'GRAVITYVIEW_DIR' ) )
6
	die();
7
8
/**
9
 * The core GravityView API.
10
 *
11
 * Returned by the wrapper gravityview() global function, exposes
12
 * all the required public functionality and classes, sets up global
13
 * state depending on current request context, etc.
14
 */
15
final class Core {
16
	/**
17
	 * @var \GV\Core The \GV\Core static instance.
18
	 */
19
	private static $__instance = null;
20
21
	/**
22
	 * @var \GV\Plugin The WordPress plugin context.
23
	 *
24
	 * @api
25
	 * @since future
26
	 */
27
	public $plugin;
28
29
	/**
30
	 * @var \GV\Request The current request.
31
	 *
32
	 * @api
33
	 * @since future
34
	 */
35
	public $request;
36
37
	/**
38
	 * @var \GV\View_Collection The views attached to the current request.
39
	 *
40
	 * @see \GV\Request::$views A shortcut alias.
41
	 * @api
42
	 * @since future
43
	 */
44
	public $views;
45
46
	/**
47
	 * Get the global instance of \GV\Core.
48
	 *
49
	 * @return \GV\Core The global instance of GravityView Core.
50
	 */
51
	public static function get() {
52
		if ( ! self::$__instance instanceof self )
53
			self::$__instance = new self;
54
		return self::$__instance;
55
	}
56
57
	/**
58
	 * Bootstrap.
59
	 *
60
	 * @return void
61
	 */
62
	private function __construct() {
63
		self::$__instance = $this;
64
		$this->init();
65
	}
66
67
	/**
68
	 * Early initialization.
69
	 *
70
	 * Loads dependencies, sets up the object, adds hooks, etc.
71
	 *
72
	 * @return void
73
	 */
74
	private function init() {
75
		require_once dirname( __FILE__ ) . '/class-gv-plugin.php';
76
		$this->plugin = Plugin::get();
77
78
		/**
79
		 * Stop all further functionality from loading if the WordPress
80
		 * plugin is incompatible with the current environment.
81
		 *
82
		 * @todo Output incompatibility notices.
83
		 */
84
		if ( ! $this->plugin->is_compatible() ) {
85
			return;
86
		}
87
88
		/** Register the gravityview post type upon WordPress core init. */
89
		require_once $this->plugin->dir( 'future/includes/class-gv-view.php' );
90
		add_action( 'init', array( '\GV\View', 'register_post_type' ) );
91
92
		/** Add rewrite endpoint for single-entry URLs. */
93
		require_once $this->plugin->dir( 'future/includes/class-gv-entry.php' );
94
		add_action( 'init', array( '\GV\Entry', 'add_rewrite_endpoint' ) );
95
96
		/** Generics */
97
		require_once $this->plugin->dir( 'future/includes/class-gv-collection.php' );
98
		require_once $this->plugin->dir( 'future/includes/class-gv-shortcode.php' );
99
100
		/** Shortcodes */
101
		require_once $this->plugin->dir( 'future/includes/class-gv-shortcode-gravityview.php' );
102
		// add_action( 'init', array( '\GV\Shortcodes\gravityview', 'add' ) ); // @todo uncomment when original is stubbed
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
103
104
		/** Get the View_Collection ready. */
105
		require_once $this->plugin->dir( 'future/includes/class-gv-collection-view.php' );
106
107
		/** Initialize the current request. For now we assume a default WordPress frontent context. */
108
		require_once $this->plugin->dir( 'future/includes/class-gv-request.php' );
109
		$this->request = new Frontend_Request();
110
		$this->views = &$this->request->views;
111
	}
112
113
	private function __clone() { }
114
115
	private function __wakeup() { }
116
}
117