Download the PHP package viewflex/zoap without Composer
On this page you can find all versions of the php package viewflex/zoap. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download viewflex/zoap
More information about viewflex/zoap
Files in viewflex/zoap
Informations about the package zoap
Zoap
Instant SOAP server for Laravel and Lumen, turns any class into a WS-I compliant SOAP service, with automatic discovery of WSDL definitions. Wraps the Laminas SOAP components to provide easy declarative configuration of services, requiring no additional coding.
Overview
System Requirements
Laravel or Lumen framework, version 5.2 or greater.
Basic Steps
Setting up services is quick and painless:
- Install this package in your Laravel or Lumen application.
- Publish the config file for customization.
- Define configurations for your services.
Examples
There is a Demo service already configured and ready to test. This can be used as a template for creating your own services from existing classes. WSDL auto-discovery and generation depends on you having properly annotated your service class attributes and methods with PHP DocBlocks, as illustrated in the DemoService
class and explained below.
Architecture
This package uses the document/literal wrapped
pattern in SOAP communications and WSDL generation, but if necessary, the ZoapController
class can be extended to deploy an alternate pattern.
Installation
From your Laravel or Lumen application's root directory, install via Composer:
After installing, add the ZoapServiceProvider
to the list of service providers:
For Laravel
Add this line in config/app.php
. If you are using Laravel version 5.5 or greater, this step is not necessary.
For Lumen
Add this line in bootstrap/app.php
:
You may also want to install the irazasyed/larasupport package, which adds a few basic Laravel features to Lumen, including support for publishing package files. This will allow you to publish the Zoap config and view files for customization as described below; otherwise, you can just copy those files manually from the package to their published locations.
Configuration
The zoap.php
config file contains both general settings and configuration of individual services.
Run this command to publish the zoap.php
config file to the project's config
directory for customization:
This will also publish the SoapFault response template to your project's resources/views/vendor/zoap
directory.
Logging
When enabled, full error information, including trace stack, will be logged for exceptions.
Services
The ZoapController
class configures the server for the service matching the key
route parameter (see Routing below). In this way you can serve any number of classes with your SOAP server, simply by defining them here.
The Demo service is provided as an example; it's configuration is shown here:
Name
Specify the name of the service as it will appear in the generated WSDL file.
Class
Specify the class you want to serve. Public attributes and methods of this class will be made available by the SOAP server.
Exceptions
List any exceptions you want caught and converted to a SoapFault
. Using Exception
will catch all exceptions, or you can be more specific and list individual child exceptions. Any exceptions not on this whitelist may return unpredictable results, including no result at all. We don't want to let the server return a SoapFault
directly, which could expose a stack trace; instead the exception is caught and then returned as a SoapFault
with the proper message.
Types
Add complex types as necessary - typically auto-discovery will find them, but if not they can be specified here - auto-discovery will not redundantly add the same type again anyway.
Strategy
Specify one of these ComplexTypeStrategyInterface
implementations to use in auto-discovery:
- AnyType
- ArrayOfTypeComplex
- ArrayOfTypeSequence
- DefaultComplexType
If not specified, the ArrayOfTypeComplex
strategy will be used.
Headers
A Content-Type
header of 'application/xml; charset=utf-8' is set automatically if not otherwise specified here. Specify any additional HTTP response headers required.
Options
Specify an array of server options for this service (optional).
Routing
The package routes file routes the Demo service:
Use this route or create new routes as necessary to access your SOAP services on the ZoapController
class, using the same URL parameter {key}
to indicate the key for a service configuration. The key 'demo' is used to look up the Demo service configuration.
Usage
SOAP is a complex specification with various implementations, and can be difficult to work with for a number of reasons. This package abstracts much of the implementation details away from the developer.
It remains for you to define your SOAP API using PHP DocBlock notation on all public class attributes and methods; this is used by the auto-discovery process to define your service. See the Demo section below to get a walk-through of a real implementation provided as an example to get you started.
Demo
The Demo SOAP service provided with this package is a simple implementation example, with commonly used configuration values. The DemoService
class references a fictional provider (DemoProvider
class) which returns some hard-coded results, simply to illustrate the concept of application functionality exposed as a SOAP service.
Example requests for the Demo service methods are provided below, along with the expected responses. Replace 'http://example.com' in the requests with the actual domain of your Laravel application.
The Demo service class provides an example of how method parameters and return values are automatically transformed by the server to the appropriate data formats. Shown here is the DocBlock of the getProducts
method in the DemoService
class:
This method returns an array of Product
objects, wrapped and formatted as an XML string, as shown below.
WSDL Generation
A SOAP server must be provided with a WSDL file to be able to recognize the methods and data models it is expected to handle, but writing one manually is difficult and error-prone, given the complexity of the specification and the lack of good documentation. This package uses auto-discovery to generate the WSDL file automatically.
The WSDL definition of the Demo service can be obtained via GET request to the Demo route with the empty URL parameter 'wsdl'
:
http://example.com/zoap/demo/server?wsdl
It should return a complete WSDL file describing the Demo service.
Service Methods
To access a service method, use a POST request with Content-Type
header of 'application/xml' or 'text/xml', and body content as shown below. The user
, password
and token
parameters will be authenticated against hard-coded values, so you can see the failure result if you change them. Also included in the Demo service are methods for getting a single product or an array of products, to illustrate the formatting of results from methods returning complex objects.
auth
Request
Response
ping
Request
Response
getProduct
Request
Response
getProducts
Request
Response
Tests
Using an HTTP client such as Postman, you can test your services directly with XML requests. A http://example.com').
License
This software is offered for use under the MIT License.
Changelog
Release versions are tracked in the Changelog.