Skip to content

Commit 7f157cc

Browse files
first commit
0 parents  commit 7f157cc

File tree

9 files changed

+226
-0
lines changed

9 files changed

+226
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/vendor/
2+
composer.lock

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# MIT License
2+
3+
Copyright (c) 2016 solitweb.be
4+
5+
>Permission is hereby granted, free of charge, to any person obtaining a copy
6+
>of this software and associated documentation files (the "Software"), to deal
7+
>in the Software without restriction, including without limitation the rights
8+
>to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
>copies of the Software, and to permit persons to whom the Software is
10+
>furnished to do so, subject to the following conditions:
11+
>
12+
>The above copyright notice and this permission notice shall be included in all
13+
>copies or substantial portions of the Software.
14+
>
15+
>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
>IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
>FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
>AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
>LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
>OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
>SOFTWARE.

README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Laravel 5 DirectAdmin API wrapper
2+
[![Latest Version](https://img.shields.io/github/release/solitweb/laravel-directadmin.svg?style=flat-square)](https://github.com/laravel-solitweb/directadmin/releases)
3+
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)
4+
[![Build Status](https://img.shields.io/travis/solitweb/laravel-directadmin/master.svg?style=flat-square)](https://travis-ci.org/solitweb/laravel-directadmin)
5+
[![Total Downloads](https://img.shields.io/packagist/dt/solitweb/laravel-directadmin.svg?style=flat-square)](https://packagist.org/packages/solitweb/laravel-directadmin)
6+
7+
## Installation
8+
9+
You can install this package via Composer using:
10+
11+
```bash
12+
composer require solitweb/laravel-directadmin
13+
```
14+
15+
You must also install this service provider:
16+
17+
```php
18+
// config/app.php
19+
'providers' => [
20+
...
21+
Solitweb\LaravelDirectAdmin\DirectAdminServiceProvider::class,
22+
];
23+
```
24+
25+
Optionally, register the facade:
26+
27+
```php
28+
// config/app.php
29+
'aliases' => [
30+
...
31+
'DirectAdmin' => Solitweb\LaravelDirectAdmin\DirectAdminFacade::class,
32+
];
33+
```
34+
35+
To publish the config file to app/config/laravel-directadmin.php run:
36+
37+
```bash
38+
php artisan vendor:publish --provider="Solitweb\LaravelDirectAdmin\DirectAdminServiceProvider"
39+
```
40+
41+
## Usage
42+
43+
Import the facade at the top of your file.
44+
45+
```php
46+
use DirectAdmin;
47+
```
48+
49+
### Examples
50+
51+
This will return an array of all users currently owned the reseller:
52+
53+
```php
54+
return DirectAdmin::request('GET', 'SHOW_USERS');
55+
```
56+
57+
This will return an array of the user's usages:
58+
59+
```php
60+
return DirectAdmin::request('GET', 'SHOW_USER_USAGE', ['user' => 'john']);
61+
```
62+
63+
For more commands check the [DirectAdmin API docs](https://www.directadmin.com/api.php).
64+
You have to copy the command without the `CMD_API_`.
65+
66+
## Credits
67+
- [Phi1 'l0rdphi1' Stier](mailto:[email protected])
68+
69+
## License
70+
71+
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

composer.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"name": "solitweb/laravel-directadmin",
3+
"description": "Laravel 5 DirectAdmin API wrapper",
4+
"keywords": [
5+
"solitweb",
6+
"laravel",
7+
"directadmin"
8+
],
9+
"homepage": "https://github.com/solitweb/laravel-directadmin",
10+
"license": "MIT",
11+
"authors": [
12+
{
13+
"name": "Stijn Vanouplines",
14+
"email": "[email protected]",
15+
"homepage": "https://solitweb.be",
16+
"role": "Developer"
17+
}
18+
],
19+
"require": {
20+
"php": "~5.6|~7.0",
21+
"illuminate/support": "~5.1.0|~5.2.0|~5.3.0",
22+
"solitweb/directadmin": "^3.0.1"
23+
},
24+
"require-dev": {
25+
"phpunit/phpunit": "^4.8",
26+
"mockery/mockery": "^0.9.4"
27+
},
28+
"autoload": {
29+
"psr-4": {
30+
"Solitweb\\LaravelDirectAdmin\\": "src"
31+
}
32+
},
33+
"autoload-dev": {
34+
"psr-4": {
35+
"Solitweb\\LaravelDirectAdmin\\Test\\": "tests"
36+
}
37+
}
38+
}

config/laravel-directadmin.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
return [
4+
'domain' => env('DIRECTADMIN_DOMAIN'),
5+
'port' => env('DIRECTADMIN_PORT', 2222),
6+
'username' => env('DIRECTADMIN_USERNAME'),
7+
'password' => env('DIRECTADMIN_PASSWORD'),
8+
];

phpunit.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
stopOnFailure="false"
11+
syntaxCheck="false">
12+
<testsuites>
13+
<testsuite name="Package Test Suite">
14+
<directory suffix=".php">./tests/</directory>
15+
</testsuite>
16+
</testsuites>
17+
</phpunit>

src/DirectAdmin.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Solitweb\LaravelDirectAdmin;
4+
5+
use Solitweb\DirectAdmin\DirectAdmin;
6+
7+
class LaravelDirectAdmin
8+
{
9+
protected $connection;
10+
11+
public function __construct(DirectAdmin $connection)
12+
{
13+
$this->connection = $connection;
14+
}
15+
16+
public function request($method, $command, $options = [])
17+
{
18+
$this->connection->set_method($method);
19+
$this->connection->query('/CMD_API_'.$command, $options);
20+
return $this->connection->fetch_parsed_body();
21+
}
22+
}

src/DirectAdminFacade.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Solitweb\LaravelDirectAdmin;
4+
5+
use Illuminate\Support\Facades\Facade;
6+
7+
class DirectAdminFacade extends Facade
8+
{
9+
/**
10+
* Get the registered name of the component.
11+
*
12+
* @return string
13+
*/
14+
public static function getFacadeAccessor()
15+
{
16+
return 'laravel-directadmin';
17+
}
18+
}

src/DirectAdminServiceProvider.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Solitweb\LaravelDirectAdmin;
4+
5+
use Solitweb\DirectAdmin\DirectAdmin;
6+
use Illuminate\Support\ServiceProvider;
7+
8+
class DirectAdminServiceProvider extends ServiceProvider
9+
{
10+
public function boot()
11+
{
12+
$this->mergeConfigFrom(__DIR__.'/../config/laravel-directadmin.php', 'laravel-directadmin');
13+
14+
$this->publishes([
15+
__DIR__.'/../config/laravel-directadmin.php' => config_path('laravel-directadmin.php'),
16+
]);
17+
}
18+
19+
public function register()
20+
{
21+
$this->app->singleton(LaravelDirectAdmin::class, function () {
22+
$api = new DirectAdmin();
23+
$api->connect(config('laravel-directadmin.domain'), config('laravel-directadmin.port'));
24+
$api->set_login(config('laravel-directadmin.username'), config('laravel-directadmin.password'));
25+
return new LaravelDirectAdmin($api);
26+
});
27+
$this->app->alias(LaravelDirectAdmin::class, 'laravel-directadmin');
28+
}
29+
}

0 commit comments

Comments
 (0)