Completed
Push — master ( 71718d...90a3d2 )
by Rain
04:31
created

CpanelChangePasswordPlugin::configMapping()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 19
nc 1
nop 0
dl 0
loc 22
rs 9.2
c 0
b 0
f 0
1
<?php
2
3
class CpanelChangePasswordPlugin extends \RainLoop\Plugins\AbstractPlugin
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
{
5
	public function Init()
6
	{
7
		$this->addHook('main.fabrica', 'MainFabrica');
8
	}
9
10
	/**
11
	 * @param string $sName
12
	 * @param mixed $oProvider
13
	 */
14
	public function MainFabrica($sName, &$oProvider)
15
	{
16
		switch ($sName)
17
		{
18
			case 'change-password':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
19
20
				$sHost = \trim($this->Config()->Get('plugin', 'host', ''));
21
				$iPost = (int) $this->Config()->Get('plugin', 'port', 2087);
22
				$sUser = (string) $this->Config()->Get('plugin', 'user', '');
23
				$sPassword = (string) $this->Config()->Get('plugin', 'password', '');
24
				$bSsl = (bool) $this->Config()->Get('plugin', 'ssl', false);
25
26
				if (!empty($sHost) && 0 < $iPost && 0 < \strlen($sUser) && 0 < \strlen($sPassword))
27
				{
28
					include_once __DIR__.'/CpanelChangePasswordDriver.php';
29
30
					$oProvider = new CpanelChangePasswordDriver();
31
					$oProvider->SetLogger($this->Manager()->Actions()->Logger());
32
					$oProvider->SetConfig($sHost, $iPost, $bSsl, $sUser, $sPassword);
33
					$oProvider->SetAllowedEmails(\strtolower(\trim($this->Config()->Get('plugin', 'allowed_emails', ''))));
34
				}
35
36
				break;
37
		}
38
	}
39
40
	/**
41
	 * @return array
42
	 */
43
	public function configMapping()
44
	{
45
		return array(
46
			\RainLoop\Plugins\Property::NewInstance('host')->SetLabel('cPanel Host')
47
				->SetDefaultValue(''),
48
			\RainLoop\Plugins\Property::NewInstance('port')->SetLabel('cPanel Port')
49
				->SetType(\RainLoop\Enumerations\PluginPropertyType::INT)
50
				->SetDefaultValue(2087),
51
			\RainLoop\Plugins\Property::NewInstance('ssl')->SetLabel('Use SSL')
52
				->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
53
				->SetDefaultValue(false),
54
			\RainLoop\Plugins\Property::NewInstance('user')->SetLabel('cPanel User')
55
				->SetDefaultValue(''),
56
			\RainLoop\Plugins\Property::NewInstance('password')->SetLabel('cPanel Password')
57
				->SetType(\RainLoop\Enumerations\PluginPropertyType::PASSWORD)
58
				->SetDefaultValue(''),
59
			\RainLoop\Plugins\Property::NewInstance('allowed_emails')->SetLabel('Allowed emails')
60
				->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING_TEXT)
61
				->SetDescription('Allowed emails, space as delimiter, wildcard supported. Example: [email protected] [email protected] *@domain2.net')
62
				->SetDefaultValue('*')
63
		);
64
	}
65
}