cloudonix / cxml-php
A PHP Wrapper library for Cloudonix's CXML language
Requires
- php: >=8.0
This package is auto-updated.
Last update: 2025-03-28 22:06:42 UTC
README
Documentation
The documentation for the Cloudonix CXML markup language can be found here.
The PHP library documentation can be found here
Supported PHP Versions
This library supports the following PHP versions:
- PHP 8.0
- PHP 8.1
- PHP 8.2
- PHP 8.3
Installation
You can install cxml-php
via composer or by downloading the source.
composer require cloudonix/cxml-php
Test your installation
Here is a sample PHP script that will generate a CXML Voice Application document, using the library:
<?php require(__DIR__ . "/vendor/autoload.php"); use Cloudonix\CXML\Response; $responder = new Response(); $responder->dial("12127773456"); $responder->redirect("https://example.com/script.php"); $responder->gather([ (new Response())->play("https://example.com/playfile.mp3")->attributes(["loop" => 3]), (new Response())->pause()->attributes(["length" => 5]), ])->attributes(["action" => "https://example.com/script.php"]); $responder->hangup(); echo $responder;
Copy&Paste the above script to a new file, and execute it from the command line, the following should be the result:
$ php cxmlResponder.php <Response> <DIAL>12127773456</DIAL> <REDIRECT>https://example.com/script.php</REDIRECT> <GATHER action="https://example.com/script.php"> <PLAY loop="3">https://example.com/playfile.mp3</PLAY> <PAUSE length="5" /> </GATHER> <HANGUP /> </Response>
Usage
Create a CXML Document Response with a <PLAY>
and <HANGUP>
<?php require(__DIR__ . "/vendor/autoload.php"); use Cloudonix\CXML\Response; $responder = new Response(); $responder ->play("https://example.com/playfile.mp3") ->attributes([ "loop" => 3, "statusCallback" => "https://example.com/statusCallback" ]); $responder->hangup(); echo $responder;
Expected result:
<Response> <PLAY loop="3" statusCallback="https://example.com/statusCallback">https://example.com/playfile.mp3</PLAY> <HANGUP /> </Response>
Create a CXML Document Response with a <GATHER>
, <PLAY>
, <PAUSE>
and <HANGUP>
<?php require(__DIR__ . "/vendor/autoload.php"); use Cloudonix\CXML\Response; $responder = new Response(); $responder->gather([ (new Response())->play("https://example.com/playfile.mp3")->attributes(["loop" => 3]), (new Response())->pause()->attributes(["length" => 5]), ])->attributes(["action" => "https://example.com/script.php"]); $responder->hangup(); echo $responder;
Expected result:
<Response> <GATHER action="https://example.com/script.php"> <PLAY loop="3">https://example.com/playfile.mp3</PLAY> <PAUSE length="5" /> </GATHER> <HANGUP /> </Response>
Getting help
If you need help installing or using the library, please check the Cloudonix Developers Website first.
If you've instead found a bug in the library or would like new features added, go ahead and open issues or pull requests against this repo!