Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
80.00% |
4 / 5 |
CRAP | |
80.00% |
20 / 25 |
Plugin | |
0.00% |
0 / 1 |
|
80.00% |
4 / 5 |
6.08 | |
86.96% |
20 / 23 |
__construct | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 3 |
|||
run | |
100.00% |
1 / 1 |
1 | |
100.00% |
10 / 10 |
|||
load_translations | |
100.00% |
1 / 1 |
1 | |
100.00% |
3 / 3 |
|||
container | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
activate_modules | |
100.00% |
1 / 1 |
2 | |
100.00% |
5 / 5 |
1 | <?php |
2 | /** |
3 | * Main plugin class. |
4 | * |
5 | * Setup and bootstrap everything from here. |
6 | * |
7 | * @package RtCamp\GoogleLogin |
8 | * @since 1.0.0 |
9 | */ |
10 | |
11 | declare(strict_types=1); |
12 | |
13 | namespace RtCamp\GoogleLogin; |
14 | |
15 | use RtCamp\GoogleLogin\Interfaces\Container as ContainerInterface; |
16 | |
17 | /** |
18 | * Class Plugin. |
19 | * |
20 | * @package RtCamp\GoogleLogin |
21 | */ |
22 | class Plugin { |
23 | |
24 | /** |
25 | * Plugin version. |
26 | * |
27 | * @var string |
28 | */ |
29 | public $version = '1.0.0'; |
30 | |
31 | /** |
32 | * Plugin directory path. |
33 | * |
34 | * @var string |
35 | */ |
36 | public $path; |
37 | |
38 | /** |
39 | * Plugin's url. |
40 | * |
41 | * @var string |
42 | */ |
43 | public $url; |
44 | |
45 | /** |
46 | * Template directory path. |
47 | * |
48 | * @var string |
49 | */ |
50 | public $template_dir; |
51 | |
52 | /** |
53 | * Assets directory path. |
54 | * |
55 | * @var string |
56 | */ |
57 | public $assets_dir; |
58 | |
59 | /** |
60 | * DI Container. |
61 | * |
62 | * @var Container |
63 | */ |
64 | private $container; |
65 | |
66 | /** |
67 | * List of active modules. |
68 | * |
69 | * @var string[] |
70 | */ |
71 | public $active_modules = [ |
72 | 'settings', |
73 | 'login_flow', |
74 | 'assets', |
75 | 'shortcode', |
76 | ]; |
77 | |
78 | /** |
79 | * Plugin constructor. |
80 | * |
81 | * @param ContainerInterface $container Container instance. |
82 | */ |
83 | public function __construct( ContainerInterface $container ) { |
84 | $this->container = $container; |
85 | } |
86 | |
87 | /** |
88 | * Run the plugin |
89 | * |
90 | * @return void |
91 | */ |
92 | public function run(): void { |
93 | $this->path = dirname( __FILE__, 2 ); |
94 | $this->url = plugin_dir_url( trailingslashit( dirname( __FILE__, 2 ) ) . 'login-with-google.php' ); |
95 | $this->template_dir = trailingslashit( $this->path ) . 'templates/'; |
96 | $this->assets_dir = trailingslashit( $this->path ) . 'assets/'; |
97 | |
98 | /** |
99 | * Filter out active modules before modules are initialized. |
100 | * |
101 | * @param array $active_modules Active modules list. |
102 | * |
103 | * @since 1.0.0 |
104 | */ |
105 | $this->active_modules = apply_filters( 'rtcamp.google_login_modules', $this->active_modules ); |
106 | |
107 | $this->container()->define_services(); |
108 | $this->activate_modules(); |
109 | |
110 | add_action( 'init', [ $this, 'load_translations' ] ); |
111 | } |
112 | |
113 | /** |
114 | * Load the plugin translation if available. |
115 | * |
116 | * @return void |
117 | */ |
118 | public function load_translations(): void { |
119 | load_plugin_textdomain( 'login-with-google', false, basename( plugin()->path ) . '/languages/' . get_locale() ); |
120 | } |
121 | |
122 | /** |
123 | * Return container object |
124 | * |
125 | * @return ContainerInterface |
126 | */ |
127 | public function container(): ContainerInterface { |
128 | return $this->container; |
129 | } |
130 | |
131 | /** |
132 | * Activate individual modules. |
133 | * |
134 | * @return void |
135 | */ |
136 | private function activate_modules(): void { |
137 | foreach ( $this->active_modules as $module ) { |
138 | $module_instance = $this->container()->get( $module ); |
139 | $module_instance->init(); |
140 | } |
141 | } |
142 | } |