-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathPlugin.php
127 lines (112 loc) · 2.95 KB
/
Plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
/*
* This file is part of the Passwords Evolved WordPress plugin.
*
* (c) Carl Alexander <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PasswordsEvolved;
use PasswordsEvolved\Configuration;
use PasswordsEvolved\DependencyInjection\Container;
use PasswordsEvolved\Password\Generator\PasswordGeneratorInterface;
use PasswordsEvolved\Password\Hasher\PasswordHasherInterface;
/**
* Passwords Evolved Plugin.
*
* @author Carl Alexander <[email protected]>
*/
class Plugin
{
/**
* Domain used for translating plugin strings.
*
* @var string
*/
const DOMAIN = 'passwords-evolved';
/**
* Passwords Evolved plugin version.
*
* @var string
*/
const VERSION = '1.3.0';
/**
* The plugin's dependency injection container.
*
* @var Container
*/
private $container;
/**
* Flag to track if the plugin is loaded.
*
* @var bool
*/
private $loaded;
/**
* Constructor.
*
* @param string $file
*/
public function __construct($file)
{
$this->container = new Container(array(
'plugin_basename' => plugin_basename($file),
'plugin_domain' => self::DOMAIN,
'plugin_path' => plugin_dir_path($file),
'plugin_relative_path' => basename(plugin_dir_path($file)),
'plugin_url' => plugin_dir_url($file),
'plugin_version' => self::VERSION,
));
$this->loaded = false;
}
/**
* Get the plugin password generator.
*
* @return PasswordGeneratorInterface
*/
public function get_password_generator()
{
return $this->container['password.generator'];
}
/**
* Get the plugin password hasher.
*
* @return PasswordHasherInterface
*/
public function get_password_hasher()
{
return $this->container['password.hasher'];
}
/**
* Checks if the plugin is loaded.
*
* @return bool
*/
public function is_loaded()
{
return $this->loaded;
}
/**
* Loads the plugin into WordPress.
*/
public function load()
{
if ($this->is_loaded()) {
return;
}
$this->container->configure(array(
Configuration\AdminConfiguration::class,
Configuration\APIClientConfiguration::class,
Configuration\EventManagementConfiguration::class,
Configuration\OptionsConfiguration::class,
Configuration\PasswordConfiguration::class,
Configuration\TranslatorConfiguration::class,
Configuration\WordPressConfiguration::class,
));
foreach ($this->container['subscribers'] as $subscriber) {
$this->container['event_manager']->add_subscriber($subscriber);
}
$this->loaded = true;
}
}