Skip to content

Commit 0b6a38c

Browse files
authored
Merge pull request #2 from ecastro98/feature/refactor
Some refactor to make the code cleaner
2 parents 33c8685 + a5a73c3 commit 0b6a38c

36 files changed

+5751
-301
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.idea/
2+
vendor/
3+
.php_cs.cache

.php_cs.dist

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
$finder = PhpCsFixer\Finder::create()
4+
->in(__DIR__ . '/src')
5+
->in(__DIR__ . '/tests');
6+
7+
return PhpCsFixer\Config::create()
8+
->setRules([
9+
'array_indentation' => true,
10+
'array_syntax' => ['syntax' => 'short'],
11+
'blank_line_after_opening_tag' => true,
12+
'concat_space' => ['spacing' => 'one'],
13+
'declare_strict_types' => true,
14+
'increment_style' => ['style' => 'post'],
15+
'is_null' => ['use_yoda_style' => false],
16+
'list_syntax' => ['syntax' => 'short'],
17+
'method_argument_space' => ['ensure_fully_multiline' => true],
18+
'method_chaining_indentation' => true,
19+
'modernize_types_casting' => true,
20+
'no_multiline_whitespace_before_semicolons' => true,
21+
'no_superfluous_elseif' => true,
22+
'no_superfluous_phpdoc_tags' => true,
23+
'no_unused_imports' => true,
24+
'no_useless_else' => true,
25+
'no_useless_return' => true,
26+
'ordered_imports' => true,
27+
'phpdoc_align' => false,
28+
'phpdoc_order' => true,
29+
'php_unit_construct' => true,
30+
'php_unit_dedicate_assert' => true,
31+
'return_assignment' => true,
32+
'single_blank_line_at_eof' => true,
33+
'single_line_comment_style' => true,
34+
'ternary_to_null_coalescing' => true,
35+
'yoda_style' => ['equal' => false, 'identical' => false, 'less_and_greater' => false],
36+
])
37+
->setFinder($finder)
38+
->setUsingCache(true)
39+
->setRiskyAllowed(true);

LICENSE

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) 2019 Multi Theft Auto
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: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,48 @@
1-
# MTA:SA PHP SDK
2-
1+
# MTA:SA PHP SDK [![Build Status](https://dev.azure.com/multitheftauto/mtasa-php-sdk/_apis/build/status/multitheftauto.mtasa-php-sdk?branchName=master)](https://dev.azure.com/multitheftauto/mtasa-php-sdk/_build/latest?definitionId=1&branchName=master)
32
You can access the MTA Web Interface from almost any programming language that can request web pages. PHP can do this very easily.
43

54
This SDK provides one function call that will allow you to call any exported script functions on any server that you have access to.
65

76
See the [official wiki page](https://wiki.multitheftauto.com/wiki/PHP_SDK) for further information.
7+
8+
## Installation
9+
10+
### Prerequisites
11+
12+
This SDK requires PHP 7.3 or greater.
13+
14+
### Setup
15+
16+
The only supported installation method is via [Composer](https://getcomposer.org). Run the following command to require this SDK in your project:
17+
18+
```
19+
composer require multitheftauto/mtasa-php-sdk
20+
```
21+
22+
### HTTPlug client abstraction
23+
24+
As this SDK uses HTTPlug, you will have to require some libraries for get it working. See ["HTTPlug for library users"](http://docs.php-http.org/en/latest/httplug/users.html) for more info.
25+
26+
## A simple example
27+
28+
There are three ways to call an MTA server's exported functions, as shown in the following example:
29+
30+
```php
31+
<?php
32+
33+
require_once('vendor/autoload.php');
34+
35+
use MultiTheftAuto\Sdk\Mta;
36+
use MultiTheftAuto\Sdk\Model\Server;
37+
use MultiTheftAuto\Sdk\Model\Authentication;
38+
39+
$server = new Server('127.0.0.1', 22005);
40+
$auth = new Authentication('myUser', 'myPassword');
41+
$mta = new Mta($server, $auth);
42+
43+
$response = $mta->getResource('someResource')->call('callableFunction', $arg1, $arg2, $arg3, ...);
44+
// or
45+
$response = $mta->getResource('someResource')->call->callableFunction($arg1, $arg2, $arg3, ...);
46+
47+
var_dump($response);
48+
```

ajax_interface.php

Lines changed: 0 additions & 40 deletions
This file was deleted.

azure-pipelines.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# https://docs.microsoft.com/azure/devops/pipelines/ecosystems/php
2+
pool:
3+
vmImage: 'ubuntu-latest'
4+
5+
variables:
6+
phpVersion: 7.3
7+
8+
steps:
9+
- script: |
10+
sudo update-alternatives --set php /usr/bin/php$(phpVersion)
11+
sudo update-alternatives --set phar /usr/bin/phar$(phpVersion)
12+
sudo update-alternatives --set phpdbg /usr/bin/phpdbg$(phpVersion)
13+
sudo update-alternatives --set php-cgi /usr/bin/php-cgi$(phpVersion)
14+
sudo update-alternatives --set phar.phar /usr/bin/phar.phar$(phpVersion)
15+
php -version
16+
displayName: 'Use PHP version $(phpVersion)'
17+
- script: composer install --no-interaction --prefer-dist
18+
displayName: 'composer install'
19+
- script: composer test
20+
displayName: 'Run tests'

composer.json

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"name": "multitheftauto/mtasa-php-sdk",
3+
"description": "PHP Sdk to interact with MTA's server. See more at https://wiki.multitheftauto.com/wiki/PHP_SDK",
4+
"type": "project",
5+
"license": "GPL-3.0",
6+
"minimum-stability": "dev",
7+
"prefer-stable": true,
8+
"require": {
9+
"php": "^7.3",
10+
"ext-json": "^1.5",
11+
"php-http/client-implementation": "^1.0",
12+
"php-http/httplug": "^2.0",
13+
"psr/http-factory": "^1.0"
14+
},
15+
"require-dev": {
16+
"friendsofphp/php-cs-fixer": "^2.13",
17+
"guzzlehttp/psr7": "^1.5",
18+
"http-interop/http-factory-guzzle": "^1.0",
19+
"php-http/mock-client": "^1.1",
20+
"phpspec/prophecy": "~1.0",
21+
"phpstan/phpstan": "^0.10.7",
22+
"phpunit/phpunit": "^7"
23+
},
24+
"config": {
25+
"preferred-install": {
26+
"*": "dist"
27+
},
28+
"sort-packages": true
29+
},
30+
"autoload": {
31+
"psr-4": {
32+
"MultiTheftAuto\\Sdk\\": "src/"
33+
}
34+
},
35+
"scripts": {
36+
"lint": "php-cs-fixer fix --verbose --show-progress=estimating",
37+
"lint:check": [
38+
"php-cs-fixer fix --dry-run --verbose --show-progress=estimating"
39+
],
40+
"phpunit": "phpunit tests",
41+
"phpstan": "phpstan analyse",
42+
"test": [
43+
"@lint:check",
44+
"@phpunit",
45+
"@phpstan"
46+
]
47+
}
48+
}

0 commit comments

Comments
 (0)