PHP SDK
You can access the MTA Web Interface from almost any programming language that can request web pages. PHP can do this very easily.
This SDK provides one function call that will allow you to call any exported script functions on any server that you have access to.
Installation
Section InstallationPrerequisites
Section PrerequisitesThis SDK requires PHP 7.1 or greater.
HTTPlug client abstraction
Section HTTPlug client abstractionIf you don’t follow this requirement before require the SDK, composer will throw you an error.
As this SDK uses HTTPlug, you will have to require some libraries for get it working. See HTTPlug for library users for more info.
Setup
Section SetupThe only supported installation method is via Composer. Run the following command to require this SDK in your project:
composer require multitheftauto/mtasa-php-sdkExamples
Section ExamplesThere are three ways to call an MTA server’s exported functions, as shown in the following example:
<?php
require_once('vendor/autoload.php');
use MultiTheftAuto\Sdk\Mta;use MultiTheftAuto\Sdk\Model\Server;use MultiTheftAuto\Sdk\Model\Authentication;
$server = new Server('127.0.0.1', 22005);$auth = new Authentication('myUser', 'myPassword');$mta = new Mta($server, $auth);
$response = $mta->getResource('someResource')->call('callableFunction', $arg1, $arg2, $arg3, ...);// or$response = $mta->getResource('someResource')->call->callableFunction($arg1, $arg2, $arg3, ...);
var_dump($response);A page that can be called by callRemote
Section A page that can be called by callRemoteThis example just adds two numbers passed to it by a Lua script.
PHP: (for the page that Lua expects to be at http://www.example.com/page.php)
<?php
require_once('vendor/autoload.php');
use MultiTheftAuto\Sdk\Mta;
$input = Mta::getInput();Mta::doReturn($input[0] + $input[1]);-- result is called when the function returnsfunction result(sum) outputChatBox(sum)endfunction addNumbers(number1, number2) callRemote ( "http://www.example.com/page.php", result, number1, number2 )endaddNumbers ( 123, 456 ) -- call the functionReleases
Section ReleasesVisit the releases page on GitHub to download the SDK.