PHP code example of gnello / php-openfire-restapi

1. Go to this page and download the library: Download gnello/php-openfire-restapi library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

gnello / php-openfire-restapi example snippets


use Gnello\OpenFireRestAPI\Client;

$client = new Client([
    'client' => [
        'username' => 'ironman',
        'password' => 'romanoff',
    ]
]);

use Gnello\OpenFireRestAPI\Client;

$client = new Client([
    'client' => [
        'secretKey' => 'hulkstink',
    ]
]);

use Gnello\OpenFireRestAPI\Client;

$client = new Client([
    'client' => [
        'secretKey' => 'hulkstink',
        'scheme' => 'https',
        'basePath' => '/plugins/restapi/v1/',
        'host' => 'localhost',
        'port' => '9090',
    ],
    'guzzle'    => [
         //put here any options for Guzzle
    ]
]);

if ($response->getStatusCode() == 200) {
    echo "Oh, great.";
    var_dump(json_decode($response->getBody()));
} else {
    echo "HTTP ERROR " . $response->getStatusCode();
}

//Create a new user
$response = $client->getUserModel()->createUser([
    "username" => "admin",
    "name" => "Administrator",
    "email" => "[email protected]",
    "password" => "p4ssword",
    "properties" => [
        [
            "key" => "console.order",
            "value" => "session-summary=0"
        ]
    ]
]);

//Delete a user
$response = $client->getUserModel()->deleteUser('ironman');

//Ban a user
$response = $client->getUserModel()->lockoutUser('ironman');

//Unban a user
$response = $client->getUserModel()->unlockUser('ironman');

//Please read the UserModel class for a complete list of available methods.

//Create a chat room
$response = $client->getChatRoomModel()->createChatRoom([
    "roomName" => "global-1",
    "naturalName" => "global-1_test_hello",
    "description" => "Global chat room",
    "subject" => "Global chat room subject",
    "creationDate" => "2012-10-18T16:55:12.803+02:00",
    "modificationDate" => "2014-07-10T09:49:12.411+02:00",
    "maxUsers" => "0",
    "persistent" => "true",
    "publicRoom" => "true",
    "registrationEnabled" => "false",
    "canAnyoneDiscoverJID" => "true",
    "canOccupantsChangeSubject" => "false",
    "canOccupantsInvite" => "false",
    "canChangeNickname" => "false",
    "logEnabled" => "true",
    "loginRestrictedToNickname" => "true",
    "membersOnly" => "false",
    "moderated" => "false",
    "broadcastPresenceRoles" => [
        "moderator",
        "participant",
        "visitor"
    ],
    "owners" => [
       "owner@localhost"
    ],
    "admins" => [
       "admin@localhost"
    ],
    "members" => [
        "member@localhost"
    ],
    "outcasts" => [
        "outcast@localhost"
    ]
]);

//Retrieve a chat room
$response = $client->getChatRoomModel()->retrieveChatRoom('theavengers')

//Add a user with role to a chat room
use \Gnello\OpenFireRestAPI\Models\ChatRoomModel;
$response = $client->getChatRoomModel()->addUserWithRoleToChatRoom('theavengers', 'ironman', ChatRoomModel::ROLE_MEMBER);

//Delete a chat room
$response = $client->getChatRoomModel()->deleteChatRoom('theavengers');

//Please read the ChatRoomModel class for a complete list of available methods.

//Create a group
$response = $client->getGroupModel()->createGroup([
    "name" => "theavengers",
    "description" => "team of superheroes appearing in American comic books published by Marvel Comics",
]);

//Retrieve a group
$response = $client->getGroupModel()->retrieveGroup('theavengers')

//Delete a group
$response = $client->getGroupModel()->deleteGroup('theavengers');

//Please read the GroupModel class for a complete list of available methods.

composer