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