notifius/php-wctp

A PHP library for creating and handling XML request/response objects for the WCTP v1.3r1 specification.

v0.1.0 2023-03-25 01:25 UTC

This package is auto-updated.

Last update: 2024-09-25 05:05:42 UTC


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

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.