PHP code example of thomasvargiu / pami-module

1. Go to this page and download the library: Download thomasvargiu/pami-module 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/ */

    

thomasvargiu / pami-module example snippets


return [
    'pami_module' => [
        'connection' => [
            'default' => [
                'host' => '', // IP or hostname of asterisk server
                'port' => 5038, // (optional) Asterisk AMI port (default: 5038)
                'username' => '', // Username for asterisk AMI
                'secret' => '', // Password for asterisk AMI
                'scheme' => 'tcp://', // (optional) Connection scheme (default: tcp://)
                'connect_timeout' => 10000, // (optional) Connection timeout in ms (default: 10000)
                'read_timeout' => 10000 // (optional) Read timeout in ms (default: 10000)
            ]
        ],
        'client' => [
            'default' => []
        ]
    ]
]

use PamiModule\Service\Client;
use PAMI\Client\Impl\ClientImpl;

// Getting the PamiModule client
/** @var Client $client */
$client = $serviceLocator->get('pami.client.default');


use PamiModule\Service\Client;
use PamiModule\Event\PamiEvent;

/* @var Client $client */
$client = $serviceLocator->get('pami.client.default');
$client->getEventManager()->attach('event.Bridge', function(PamiEvent $event) {
    // Getting the client
    /* @var Client $client */
    $client = $event->getTarget();
    
    // Getting the original Event
    /* @var \PAMI\Message\Event\BridgeEvent $pamiEvent */
    $pamiEvent = $event->getEvent();
});

return [
    'pami_module' => [
        'connection' => [
            'default' => [
                // configuration
            ],
            'asterisk2' => [
                // configuration
            ]
        ],
        'client' => [
            'default' => [],
            'asterisk2 => []
        ]
    ]
]

return [
    'pami_module' => [
        'connection' => [
            'default' => [
                // configuration
            ]
        ],
        'client' => [
            'default' => [
                'connection' => 'default'
            ],
            'client2' => [
                'connection' => 'default'
            ]
        ]
    ]
]

$client1 = $serviceLocator->get('pami.client.default');
$client2 = $serviceLocator->get('pami.client.client2');

$client1->getConnection() === $client2->getConnection(); // true

use PAMI\Client\Impl\ClientImpl;

/* @var ClientImpl $connection */
$connection = $serviceLocator->get('pami.connection.default');

use PamiModule\Service\Client;
use PAMI\Client\Impl\ClientImpl;

// Getting the PamiModule client
/* @var Client $client */
$client = $serviceLocator->get('pami.client.default');
// Getting the PAMI client
/* @var ClientImpl $connection */
$connection = $client->getConnection();

return [
    'service_manager' => [
        'delegators' => [
            'pami.client.default' => [
                'PamiModule\\Service\\ConnectionStatusDelegatorFactory'
            ]
        ]
    ]
];

use PamiModule\Listener\CacheListener;
use Zend\Cache\Storage\StorageInterface;

$client = $serviceLocator->get('pami.client.default')
/* @var StorageInterface $cache */
$cache = $serviceLocator->get('asterisk_sippeers_cache');

$actionsToCache = ['SIPPeers', 'ShowPeer'];
$cacheListener = new CacheListener($cache, $actionsToCache);

$client->getEventManager()->attachAggregate($cacheListener);