notifius / php-wctp
A PHP library for creating and handling XML request/response objects for the WCTP v1.3r1 specification.
Requires
- php: ^7.3|^8.0
- ext-simplexml: ^7.3|^8.0
- nesbot/carbon: ^2.57.0
Requires (Dev)
- phpunit/phpunit: ^9.5.20
README
A PHP library for creating and submitting XML WCTP requests and responses
Not production ready
Not ready for every day use! We will tag a version 1.0.0 when we're ready for you to use in production. For now, expect namespace updates and other breaking changes.
Getting Started
Install the library using composer:
composer require notifius/php-wctp
Example use of library:
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 | ✓ |
General Information
Dates
We rely on the nesbot/carbon
composer package for handling dates throughout our library.
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.
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.
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 like this:
vendor/bin/phpunit --bootstrap vendor/autoload.php tests/
Security Vulnerabilities
If you discover a security vulnerability, please send an e-mail to support@notifi.us. All security vulnerabilities will be promptly addressed.