1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/** |
3
|
|
|
* LSX Search Main Class. |
4
|
|
|
* |
5
|
|
|
* @package lsx-search |
6
|
|
|
*/ |
7
|
|
|
class LSX_Search { |
|
|
|
|
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Holds class instance |
11
|
|
|
* |
12
|
|
|
* @since 1.0.0 |
13
|
|
|
* |
14
|
|
|
* @var object LSX_Search() |
15
|
|
|
*/ |
16
|
|
|
protected static $instance = null; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var LSX_Search_Admin() |
|
|
|
|
20
|
|
|
*/ |
21
|
|
|
public $admin; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var LSX_Search_Frontend() |
|
|
|
|
25
|
|
|
*/ |
26
|
|
|
public $frontend; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var LSX_Search_FacetWP() |
30
|
|
|
*/ |
31
|
|
|
public $facetwp; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var LSX_Search_Shortcode() |
35
|
|
|
*/ |
36
|
|
|
public $shortcode; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* LSX_Search constructor |
40
|
|
|
*/ |
41
|
|
|
public function __construct() { |
|
|
|
|
42
|
|
|
$this->load_vendors(); |
43
|
|
|
|
44
|
|
|
require_once LSX_SEARCH_PATH . '/classes/class-admin.php'; |
45
|
|
|
require_once LSX_SEARCH_PATH . '/classes/class-frontend.php'; |
46
|
|
|
require_once LSX_SEARCH_PATH . '/classes/class-lsx-search-facetwp.php'; |
47
|
|
|
require_once LSX_SEARCH_PATH . '/classes/class-lsx-search-shortcode.php'; |
48
|
|
|
|
49
|
|
|
$this->admin = \lsx\search\classes\Admin::get_instance(); |
50
|
|
|
$this->frontend = \lsx\search\classes\Frontend::get_instance(); |
51
|
|
|
$this->facetwp = new LSX_Search_FacetWP(); |
52
|
|
|
$this->shortcode = new LSX_Search_Shortcode(); |
53
|
|
|
} |
|
|
|
|
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Return an instance of this class. |
57
|
|
|
* |
58
|
|
|
* @since 1.0.0 |
59
|
|
|
* |
60
|
|
|
* @return object LSX_Search() A single instance of this class. |
61
|
|
|
*/ |
62
|
|
|
public static function get_instance() { |
|
|
|
|
63
|
|
|
// If the single instance hasn't been set, set it now. |
64
|
|
|
if ( null === self::$instance ) { |
|
|
|
|
65
|
|
|
self::$instance = new self(); |
66
|
|
|
} |
67
|
|
|
return self::$instance; |
68
|
|
|
} |
|
|
|
|
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Loads the plugin functions. |
72
|
|
|
*/ |
73
|
|
|
private function load_vendors() { |
|
|
|
|
74
|
|
|
// Configure custom fields. |
75
|
|
|
if ( ! class_exists( 'CMB2' ) ) { |
|
|
|
|
76
|
|
|
require_once LSX_SEARCH_PATH . 'vendor/CMB2/init.php'; |
77
|
|
|
} |
78
|
|
|
} |
|
|
|
|
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Initiates the LSX Search Plugin |
83
|
|
|
* |
84
|
|
|
* @return object LSX_Search(); |
85
|
|
|
*/ |
86
|
|
|
function lsx_search() { |
|
|
|
|
87
|
|
|
global $lsx_search; |
88
|
|
|
$lsx_search = LSX_Search::get_instance(); |
89
|
|
|
return $lsx_search; |
90
|
|
|
} |
|
|
|
|
91
|
|
|
lsx_search(); |
92
|
|
|
|
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.