PHP code example of cx-engine / expert-stats-api-sdk-php
1. Go to this page and download the library: Download cx-engine/expert-stats-api-sdk-php 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/ */
cx-engine / expert-stats-api-sdk-php example snippets
use CXEngine\ExpertStats\ExpertStatisticsConnector;
$api = new ExpertStatisticsConnector(
apiUrl: 'https://xp-stats-201.bluerock.tel/api',
email: '[email protected]',
password: 'secret',
);
use CXEngine\ExpertStats\ExpertStatisticsConnector;
use CXEngine\ExpertStats\Requests;
$api = new ExpertStatisticsConnector(XPSTATS_API_URL, XPSTATS_API_USERNAME, XPSTATS_API_PASSWORD);
$response = $api->call(
new Requests\Pbx3cxHosts\GetPbx3cxHostsRequest()
);
use CXEngine\ExpertStats\ExpertStatisticsConnector;
$api = new ExpertStatisticsConnector(XPSTATS_API_URL, XPSTATS_API_USERNAME, XPSTATS_API_PASSWORD);
$response = $api->pbx3cxCall()->index(
hostName: 'pbx01.acme.com',
);
class NamespaceResource
{
public function index(array $params = [], int $perPage = 20, int $page = 1): Response;
public function show(int $id): Response;
public function store(Entity $entity): Response;
public function update(Entity $entity): Response;
public function upsert(Entity $entity): Response;
public function delete(int $id): Response;
}
$connector = new ExpertStatisticsConnector(...);
$connector->pbx3cxHost(): Resources\Pbx3cxHostResource
$connector->pbx3cxCall(): Resources\Pbx3cxCallResource
...
use CXEngine\ExpertStats\ExpertStatisticsConnector;
use CXEngine\ExpertStats\Resources\Pbx3cxHostResource;
$api = new ExpertStatisticsConnector();
$resource = new Pbx3cxHostResource($api);
$hostData = $resource->show($hostId)->dtoOrFail();
$resource->upsert($hostData);
// Check response status
$response->ok();
$response->failed();
$response->status();
$response->headers();
// Get response data
$response->json(); # as an array
$response->body(); # as an raw string
$response->dtoOrFail(); # as a Data Transfer Object
$query = [
'sort' => 'created_at',
];
# Create a PagedPaginator instance
$paginator = $api->paginate(new GetExamplesRequest($query));
# Iterate on all pages entities, using lazy loading for performance
foreach ($paginator->items() as $example) {
$name = $example->name;
}
use CXEngine\ExpertStats\ExpertStatisticsConnector;
class MyCustomConnector extends ExpertStatisticsConnector
{
public function defaultConfig(): array
{
return [
'timeout' => 120,
];
}
public function customResource(): \App\Resources\CustomResource
{
return new \App\Resources\CustomResource($this);
}
}
$api = new MyCustomConnector(XPSTATS_API_URL, XPSTATS_API_USERNAME, XPSTATS_API_PASSWORD);
$api->customResource()->index();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.