BMC/UUP-SOAP - SOAP service with WSDL and API documentation.

This library makes it easy to publish your PHP classes as SOAP handlers using the native SOAP extension in PHP (fast). The WSDL and API documentation is generated from class and method annotations, with optional WSDL cache.

PHP classes and namespaces (including use alias) is supported. In addition to basic types like int and string, arrays are also supported possibly containing class objects. In the generated XML an array is represented as an unlimited sequence of basic or comlex types.

Getting started

Add your SOAP operations as public methods, possibly having classes as input or return values.

<?php

namespace Blogger\WebServices\Soap;

use UUP\WebService\Soap\SoapHandler;
use UUP\WebService\Soap\SoapService;
use Blogger\Models\Post;

/**
 * Our blog service.
 */
class BlogService implements SoapHandler
{

        /**
         * Add post.
         * @param Post $post The post to add.
         * @return int The post ID.
         */
        public function addPost($post)
        {
                // Save to database...
        }

        /**
         * Delete post.
         * @param int $post The post ID.
         */
        public function deletePost($post)
        {
                // Delete from database...
        }

        /**
         * Get all posts by author.
         * @param string $author The post author.
         * @param string $date Get newer than this date.
         * @return Post[]
         */
        public function getPosts($author, $date)
        {
                // Get posts from database...
        }

        // To be continued...
}

Then create the service frontend. Wrapped mode is used so that input and return gets proxied as ordinary PHP types. In this example we also tells the library to handle request for API docs and WSDL transparent.

<?php

try {
        $service = new SoapService(BlogService::class);

        $service->useWrapper();         // Use wrapped mode
        $service->useRequest();         // Use request detection

        $description = $service->getServiceDescription();
        $description->addClassPath("Application\Models\Post");

        $service->handleRequest();
} catch (Exception $exception) {
        error_log($exception);          // SOAP fault already sent
}

If you don't care for logging exceptions you can skip the try/catch block. The exception has already been sent when catch block is entered.

Read More

Exceptions

You can throw exceptions at any time in your handler class. These are trapped automatic and forwarded to the peer side wrapped in SOAP faults.

Reflection

This library uses reflecton on classes and annotations to gather information for exporting the class. Use support methods from service description class to add PHP namespaces and class mapping.

Read More

Examples

More examples, including fully functional that can be tested online, can be found in the demo section. These examples are also bundled with the source code available for download from here.

Read More