notifius / php-wctp
A PHP library for creating and handling XML request/response objects for the WCTP v1.3r1 specification.
Installs: 439
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/notifius/php-wctp
Requires
- php: ^7.3|^8.0
- ext-simplexml: *
- nesbot/carbon: ^2.57.0|^3.0
Requires (Dev)
- phpstan/phpstan: ^1.10|^2.0
- phpunit/phpunit: ^9.5.20|^10.0|^11.0
README
A PHP library for creating and submitting XML WCTP requests and responses.
Getting Started
Add the library to your project using composer:
composer require notifius/php-wctp
Example usage:
use NotifiUs\WCTP\XML\ClientQuery; $clientQuery = new ClientQuery(); $xml = $clientQuery ->senderID( 'senderID' ) ->recipientID( 'recipientID' ) ->trackingNumber( 'trackingNumber' ) ->xml();
XML Request Method Templating
| WCTP Method | notifius/wctp | Status |
|---|---|---|
| wctp-ClientQuery | NotifiUs\WCTP\XML\ClientQuery | ✓ |
| wctp-LookupSubscriber | NotifiUs\WCTP\XML\LookupSubscriber | ✓ |
| wctp-DeviceLocation | NotifiUs\WCTP\XML\DeviceLocation | ✓ |
| wctp-MessageReply | NotifiUs\WCTP\XML\MessageReply | ✓ |
| wctp-PollForMessages | NotifiUs\WCTP\XML\PollForMessages | × |
| wctp-ReturnToSvc | NotifiUs\WCTP\XML\ReturnToSvc | ✓ |
| wctp-SendMsgMulti | NotifiUs\WCTP\XML\SendMsgMulti | × |
| wctp-StatusInfo | NotifiUs\WCTP\XML\StatusInfo | × |
| wctp-SubmitClientMessage | NotifiUs\WCTP\XML\SubmitClientMessage | ✓ |
| wctp-SubmitRequest | NotifiUs\WCTP\XML\SubmitRequest | ✓ |
| wctp-VersionQuery | NotifiUs\WCTP\XML\VersionQuery | ✓ |
Return Type
The $xml variable will be a SimpleXMLElement Object. You can get the XML as a string by calling $xml->asXML()
Relaxed parameter requirements
While we follow the WCTP recommendations for parameters and lengths, we don't enforce allowed characters. Anything that is not XML compliant will be automatically escaped, so keep that in mind. This should provide an additional level of flexibility (through conventions) and modernize the now ~15 year-old protocol.
Add WCTP token to wctp-Operation
For all XML WCTP methods below, you can optionally pass in a wctpToken to the constructor:
$clientQuery = new ClientQuery( 'token' );
This will add the XML attribute wctpToken="token" to the <wctp-Operation> element.
WCTP XML Methods
wctp-MessageReply
Create an XML representation of the wctp-MessageReply operation.
use Carbon\Carbon; use NotifiUs\WCTP\XML\MessageReply; $messageReply = new MessageReply(); $xml = $messageReply ->messageID( 321 ) ->senderID( 'senderID' ) ->recipientID( 'recipientID' ) ->responseToMessageID( 123 ) ->submitTimestamp( Carbon::now() ) ->payload( 'Reply to a message' ) ->xml(); print_r( $xml );
wctp-ClientQuery
Create an XML representation of the wctp-ClientQuery operation.
use NotifiUs\WCTP\XML\ClientQuery; $clientQuery = new ClientQuery(); $xml = $clientQuery ->senderID( 'senderID' ) ->recipientID( 'recipientID' ) ->trackingNumber( 'trackingNumber' ) ->xml(); print_r( $xml ); /* SimpleXMLElement Object ( [@attributes] => Array ( [wctpVersion] => WCTP-DTD-V1R3 ) [wctp-ClientQuery] => SimpleXMLElement Object ( [@attributes] => Array ( [senderID] => senderID [recipientID] => recipientID [trackingNumber] => trackingNumber ) ) ) */
wctp-VersionQuery
Create an XML representation of the wctp-VersionQuery operation.
use NotifiUs\WCTP\XML\VersionQuery; $versionQuery = new VersionQuery(); $xml = $versionQuery ->inquirer( 'inquirer' ) ->dateTime( Carbon::now() ) ->xml();
You can also leave off optional parameters like this:
//dateTime is an optional parameter $xml = $versionQuery ->inquirer( 'inquirer' ) ->xml();
License
The php-wctp library is open-source software licensed under the MIT license.
Testing
After cloning the repository and running composer install, you can run the test suite:
vendor/bin/phpunit
Static Analysis
Run PHPStan to check for type and logic errors:
vendor/bin/phpstan analyse
Security Vulnerabilities
If you discover a security vulnerability, please email support@calltheory.com.
All security vulnerabilities will be promptly addressed.