All Projects → multitheftauto → mtasa-php-sdk

multitheftauto / mtasa-php-sdk

Licence: MIT license
The official PHP SDK for the Multi Theft Auto Web Interface.

Programming Languages

PHP
23972 projects - #3 most used programming language
Dockerfile
14818 projects

Projects that are alternatives of or similar to mtasa-php-sdk

Client
Bitbucket API 2.0 client for PHP
Stars: ✭ 85 (+347.37%)
Mutual labels:  httplug
hedit
Handling Editor - to get the resource, press the "releases" link below
Stars: ✭ 17 (-10.53%)
Mutual labels:  multi-theft-auto
mtasa-resources
This project maintains a list of up-to-date resources that come with Multi Theft Auto.
Stars: ✭ 116 (+510.53%)
Mutual labels:  multi-theft-auto
mta-paradise
Roleplay mode for Multi Theft Auto: San Andreas; built for MTA 1.0.x
Stars: ✭ 31 (+63.16%)
Mutual labels:  multi-theft-auto
MTATD
MTA:SA debugger and unit testing framework
Stars: ✭ 18 (-5.26%)
Mutual labels:  multi-theft-auto
ml pathfind
Pathfind module for MTA:SA-Server
Stars: ✭ 25 (+31.58%)
Mutual labels:  multi-theft-auto

MTA:SA PHP SDK

PHP Composer

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.

See the official wiki page for further information.

Installation

Prerequisites

This SDK requires PHP 7.4 or greater.

HTTPlug client abstraction

As this SDK uses HTTPlug, you will have to require some libraries for get it working. See "HTTPlug for library users" for more info.

Quick installation (Fixed from HTTPlug documentation)

composer require php-http/curl-client guzzlehttp/psr7 php-http/message http-interop/http-factory-guzzle

⚠️ Note: If you don't follow this requirement before require the SDK, composer will throw you an error.

Setup

The only supported installation method is via Composer. Run the following command to require this SDK in your project:

composer require multitheftauto/mtasa-php-sdk

A simple example

There 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);

Development environment setup

Prerequisites:

First, we need to build the local docker image. To do this, run the following command:

$ docker-compose build

We will be using an alias for executing the development commands.

$ alias dcli='docker-compose -f docker-compose.cli.yml run --rm'

Install dependencies:

$ dcli composer install

Running tests

To run the project tests and validate the coding standards:

$ dcli composer test

To run all unit tests you can use:

$ dcli phpunit

To run specific unit test you can use --filter option:

$ dcli phpunit --filter=ClassName::MethodName
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].