Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
92.86% |
13 / 14 |
|
80.00% |
4 / 5 |
CRAP | |
0.00% |
0 / 1 |
Plugin | |
92.86% |
13 / 14 |
|
80.00% |
4 / 5 |
6.01 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
run | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
1 | |||
load_translations | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
container | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
activate_modules | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 |
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 | 'one_tap_login', |
77 | 'google_login_block', |
78 | ]; |
79 | |
80 | /** |
81 | * Plugin constructor. |
82 | * |
83 | * @param ContainerInterface $container Container instance. |
84 | */ |
85 | public function __construct( ContainerInterface $container ) { |
86 | $this->container = $container; |
87 | } |
88 | |
89 | /** |
90 | * Run the plugin |
91 | * |
92 | * @return void |
93 | */ |
94 | public function run(): void { |
95 | $this->path = dirname( __FILE__, 2 ); |
96 | $this->url = plugin_dir_url( trailingslashit( dirname( __FILE__, 2 ) ) . 'login-with-google.php' ); |
97 | $this->template_dir = trailingslashit( $this->path ) . 'templates/'; |
98 | $this->assets_dir = trailingslashit( $this->path ) . 'assets/'; |
99 | |
100 | /** |
101 | * Filter out active modules before modules are initialized. |
102 | * |
103 | * @param array $active_modules Active modules list. |
104 | * |
105 | * @since 1.0.0 |
106 | */ |
107 | $this->active_modules = apply_filters( 'rtcamp.google_login_modules', $this->active_modules ); |
108 | |
109 | $this->container()->define_services(); |
110 | $this->activate_modules(); |
111 | |
112 | add_action( 'init', [ $this, 'load_translations' ] ); |
113 | } |
114 | |
115 | /** |
116 | * Load the plugin translation if available. |
117 | * |
118 | * @return void |
119 | */ |
120 | public function load_translations(): void { |
121 | load_plugin_textdomain( 'login-with-google', false, basename( plugin()->path ) . '/languages/' . get_locale() ); |
122 | } |
123 | |
124 | /** |
125 | * Return container object |
126 | * |
127 | * @return ContainerInterface |
128 | */ |
129 | public function container(): ContainerInterface { |
130 | return $this->container; |
131 | } |
132 | |
133 | /** |
134 | * Activate individual modules. |
135 | * |
136 | * @return void |
137 | */ |
138 | private function activate_modules(): void { |
139 | foreach ( $this->active_modules as $module ) { |
140 | $module_instance = $this->container()->get( $module ); |
141 | $module_instance->init(); |
142 | } |
143 | } |
144 | } |