Skip to content

Commit

Permalink
Updated README (#54)
Browse files Browse the repository at this point in the history
- Updated text in installation section
- Added getting started section
  • Loading branch information
Sebbo94BY authored and ronindesign committed Mar 21, 2018
1 parent 6af8373 commit 02ed3a1
Showing 1 changed file with 102 additions and 1 deletion.
103 changes: 102 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,114 @@ You can either install the TS3 PHP Framework by manually downloading it or using
```
composer require planetteamspeak/ts3-php-framework
```
The above command will install the latest stable release version.
The above command will install the latest available release.

If you want to install the TS3 PHP Framework's `master` branch instead (which may not be released / tagged yet), you need to run:
```
composer require planetteamspeak/ts3-php-framework:dev-master
```

### Getting Started
#### Connection URI (Options + IPv4 vs IPv6)
Before you can run commands like "get version of server instance" or "update some settings", you need to specify to which instance you want to connect to. This is done using the URI in `TeamSpeak3::factory("$uri")`.

The base `$uri` looks always like this:
```
$uri = "serverquery://username:[email protected]:10011/";
```
You also can add some options behind the last `/`. Tell the URI, that you want to connect to a specific virtual TeamSpeak 3 server using it's `virtualserver_port`:
```
$uri = "serverquery://username:[email protected]:10011/?server_port=9987";
```
Additional options can be added using a simple `&` like in GET-URLs:
```
$uri = "serverquery://username:[email protected]:10011/?server_port=9987&blocking=0";
```
The list of available options can be found in the documentation: [TeamSpeak3 > factory](https://docs.planetteamspeak.com/ts3/php/framework/class_team_speak3.html#aa0f699eba7225b3a95a99f80b14e73b3)

The TS3 PHP Framework does also support connections to IPv6 TeamSpeak hosts. An IPv6 address must be written within
square brackets:
```
$uri = "serverquery://username:password@[fe80::250:56ff:fe16:1447]:10011/";
```

In your PHP code, you can use this simple trick to always get the correct URI based on the type of your provided IP address `$ip`:
```
if(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
$uri = "serverquery://username:password@${ip}:10011/";
} elseif(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
$uri = "serverquery://username:password@[${ip}]:10011/";
} else {
echo "${ip} is no valid IPv4 or IPv6 address!";
}
```

#### Usual PHP Code (`require` solution)
Usual PHP code means a simple created `file.php`, where you start writing your code like this:
```
<?php
echo "Hello World!";
```
When you use this solution, you'll probably start using the TS3 PHP Framework like this:
```
<?php
// load framework files
require_once("libraries/TeamSpeak3/TeamSpeak3.php");
try
{
// IPv4 connection URI
$uri = "serverquery://username:[email protected]:10011/?server_port=9987";
// connect to above specified server, authenticate and spawn an object for the virtual server on port 9987
$ts3_VirtualServer = TeamSpeak3::factory("$uri");
// spawn an object for the channel using a specified name
$ts3_Channel = $ts3_VirtualServer->channelGetByName("I do not exist");
}
catch(TeamSpeak3_Exception $e)
{
// print the error message returned by the server
echo "Error " . $e->getCode() . ": " . $e->getMessage();
}
```

#### PHP Code in [MVC](https://en.wikipedia.org/wiki/Model–view–controller) (`use` solution)
When you use a MVC based software like Symfony, CakePHP, Laravel or something similar, you'll probably use something like this:
```
<?php
use TeamSpeak3;
use TeamSpeak3_Exception;
class TeamspeakController extends Controller
{
public function doSomething()
{
try
{
// IPv4 connection URI
$uri = "serverquery://username:[email protected]:10011/?server_port=9987";
// Create new object of TS3 PHP Framework class
$TS3PHPFramework = new TeamSpeak3();
// connect to above specified server, authenticate and spawn an object for the virtual server on port 9987
$ts3_VirtualServer = $TS3PHPFramework->factory("$uri");
// spawn an object for the channel using a specified name
$ts3_Channel = $ts3_VirtualServer->channelGetByName("I do not exist");
}
catch(TeamSpeak3_Exception $e)
{
// print the error message returned by the server
return "Error " . $e->getCode() . ": " . $e->getMessage();
}
}
}
```
For further information please visit the documentation (see [Useful Links](#useful-links)).

### Features

Features of the TS3 PHP Framework include:
Expand Down

0 comments on commit 02ed3a1

Please sign in to comment.