Skip to content

Commit 07c533f

Browse files
committed
Added: Set variable on Cpanel instance
1 parent a1718d5 commit 07c533f

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

CPanel.php

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,26 @@ class CPanel {
2222

2323
//-----------------------------------------------------
2424

25-
public function __construct()
25+
public function __construct($cpanel_domain=null, $cpanel_api_token=null, $cpanel_username=null, $protocol='https', $port=2083)
2626
{
27+
2728
$this->config = Config::get('cpanel');
2829

29-
$this->protocol = $this->config['protocol'];
30-
$this->domain = $this->config['domain'];
31-
$this->port = $this->config['port'];
32-
$this->username = $this->config['username'];
33-
$this->token = $this->config['api_token'];
30+
if(isset($this->config) && isset($this->config['domain']))
31+
{
32+
$this->protocol = $this->config['protocol'];
33+
$this->domain = $this->config['domain'];
34+
$this->port = $this->config['port'];
35+
$this->username = $this->config['username'];
36+
$this->token = $this->config['api_token'];
37+
} else{
38+
$this->protocol = $protocol;
39+
$this->port = $port;
40+
$this->domain = $cpanel_domain;
41+
$this->username = $cpanel_username;
42+
$this->token = $cpanel_api_token;
43+
}
44+
3445

3546
}
3647

@@ -137,7 +148,7 @@ public function call($module, $function, $args = array())
137148

138149
$url = $this->protocol.'://'.$this->domain . ':' . $this->port . '/execute/' . $module;
139150
$url .= "/".$function;
140-
151+
141152
if(count($args) > 0)
142153
{
143154
$url .= '?'. $parameters;
@@ -198,4 +209,4 @@ public function call($module, $function, $args = array())
198209

199210
//-----------------------------------------------------
200211

201-
}
212+
}

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ CPANEL_PORT=
6363
CPANEL_API_TOKEN=
6464
CPANEL_USERNAME=
6565
```
66+
or
67+
68+
```php
69+
$cpanel = new CPanel($cpanel_domain=null, $cpanel_api_token=null, $cpanel_username=null, $protocol='https', $port=2083);
70+
```
71+
6672
To generate `CPANEL_API_TOKEN`, login to the `CPanel >> SECURITY >> Manage API Tokens >> Create`.
6773

6874
## Usages & available methods
@@ -78,7 +84,7 @@ If your CPanel username is `foo` then your database name
7884
| should be `foo_website`.
7985

8086
```php
81-
$cpanel = new CPanel();
87+
$cpanel = new CPanel();
8288
$response = $cpanel->createDatabase('cpanelusername_databasename');
8389
```
8490
Find More Details at [CPanel UAPI - Mysql::create_database](https://documentation.cpanel.net/display/DD/UAPI+Functions+-+Mysql::create_database)

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"keywords": ["laravel", "cpanel", "cpanel api", "cpanel uapi"],
55
"homepage": "https://www.webreinvent.com",
66
"license": "MIT",
7-
"version": "1.1.0",
7+
"version": "1.2.0",
88
"authors": [
99
{
1010
"name": "WebReinvent",

0 commit comments

Comments
 (0)