[Doc] Global update

This commit is contained in:
Francis Besset
2011-11-13 22:40:42 +01:00
parent 4abf5a59ed
commit 0ac7a78870
9 changed files with 87 additions and 10 deletions

View File

@ -0,0 +1,58 @@
Configuration
=============
Routing
-------
Include the `BeSimpleSoapBundle`'s routing configuration in your routing file (you can choose the prefix arbitrarily):
.. code-block:: yaml
# app/config/routing.yml
_besimple_soap:
resource: "@BeSimpleSoapBundle/Resources/config/routing/webservicecontroller.xml"
prefix: /ws
Config
------
Configure your first web service in your config file:
.. code-block:: yaml
# app/config/config.yml
be_simple_soap:
services:
DemoApi:
namespace: http://mysymfonyapp.com/ws/DemoApi/1.0/
binding: rpc-literal
resource: "@AcmeDemoBundle/Controller/DemoController.php"
resource_type: annotation
Annotations for Controllers
---------------------------
.. code-block:: php
namespace My\App\Controller;
use BeSimple\SoapBundle\ServiceDefinition\Annotation as Soap;
use Symfony\Component\DependencyInjection\ContainerAware;
class DemoController extends ContainerAware
{
/**
* @Soap\Method("hello")
* @Soap\Param("name", phpType = "string")
* @Soap\Result(phpType = "string")
*/
public function helloAction($name)
{
return $this->container->get('besimple.soap.response')->setReturnValue(sprintf('Hello %s!', $name));
}
}
Get your WSDL
-------------
To access your WSDL go to the following address: http://localhost/app_dev.php/ws/DemoApi?wsdl

View File

@ -0,0 +1,25 @@
Array
=====
Controller
----------
.. code-block:: php
namespace My\App\Controller;
use BeSimple\SoapBundle\ServiceDefinition\Annotation as Soap;
use Symfony\Component\DependencyInjection\ContainerAware;
class DemoController extends ContainerAware
{
/**
* @Soap\Method("hello")
* @Soap\Param("names", phpType = "string[]")
* @Soap\Result(phpType = "string")
*/
public function helloAction(array $names)
{
return $this->container->get('besimple.soap.response')->setReturnValue("Hello ".implode(', ', $names));
}
}

View File

@ -0,0 +1,85 @@
Complex Type
============
This tutorial explains how to do to return a complex type.
If your SOAP function takes a complex type as input, this tutorial is
valid. You'll just have to adapt the input parameters of your method.
Controller
----------
.. code-block:: php
namespace My\App\Controller;
use BeSimple\SoapBundle\ServiceDefinition\Annotation as Soap;
use Symfony\Component\DependencyInjection\ContainerAware;
class DemoController extends ContainerAware
{
/**
* @Soap\Method("getUser")
* @Soap\Param("name", phpType = "string")
* @Soap\Result(phpType = "My\App\Entity\User")
*/
public function getUserAction($name)
{
$user = $this->container->getDoctrine()->getRepository('MyApp:User')->findOneBy(array(
'name' => $name,
));
if (!$user) {
throw new \SoapFault('USER_NOT_FOUND', sprintf('The user with the name "%s" can not be found', $name));
}
return $this->container->get('besimple.soap.response')->setReturnValue($user);
}
}
User class
----------
You can expose only the properties (public, protected or private) of a complex type.
.. code-block:: php
namespace My\App\Entity;
use BeSimple\SoapBundle\ServiceDefinition\Annotation as Soap;
class User
{
/**
* @Soap\ComplexType("string")
*/
public $firstname;
/**
* @Soap\ComplexType("string")
*/
public $lastname;
/**
* @Soap\ComplexType("int", nillable=true)
*/
private $id;
/**
* @Soap\ComplexType("string")
*/
private $username;
/**
* @Soap\ComplexType("string")
*/
private $email;
}
ComplexType
-----------
`ComplexType` accepts the following options:
* nillable: To specify that the value can be null

View File

@ -0,0 +1,89 @@
Header
======
Controller
----------
.. code-block:: php
namespace My\App\Controller;
use BeSimple\SoapBundle\ServiceDefinition\Annotation as Soap;
use Symfony\Component\DependencyInjection\ContainerAware;
class DemoController extends ContainerAware
{
/**
* @Soap\Method("hello")
* @Soap\Header("api_key", phpType = "string")
* @Soap\Param("names", phpType = "string[]")
* @Soap\Result(phpType = "string")
*/
public function helloAction(array $names)
{
$soapHeaders = $this->container->get('request')->getSoapHeaders();
// You can use '1234' !== (string) $soapHeaders->get('api_key')
if (!$soapHeaders->has('api_key') || '1234' !== $soapHeaders->get('api_key')->getData()) {
throw new \SoapFault("INVALID_API_KEY", "The api_key is invalid.");
}
return $this->container->get('besimple.soap.response')->setReturnValue("Hello ".implode(', ', $names));
}
}
Global header
-------------
If you want use a header for all actions of your controller you can declare the header like this:
.. code-block:: php
namespace My\App\Controller;
use BeSimple\SoapBundle\ServiceDefinition\Annotation as Soap;
use Symfony\Component\DependencyInjection\ContainerAware;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* @Soap\Header("api_key", phpType = "string")
*/
class DemoController extends ContainerAware
{
/**
* @Soap\Method("hello")
* @Soap\Param("names", phpType = "string[]")
* @Soap\Result(phpType = "string")
*/
public function helloAction(array $names)
{
return $this->container->get('besimple.soap.response')->setReturnValue("Hello ".implode(', ', $names));
}
/**
* @Soap\Method("welcome")
* @Soap\Param("names", phpType = "string[]")
* @Soap\Result(phpType = "string")
*/
public function welcomeAction()
{
return $this->container->get('besimple.soap.response')->setReturnValue("Welcome ".implode(', ', $names));
}
public function setContainer(ContainerInterface $container = null)
{
parent::setContainer($container);
$this->checkApiKeyHeader();
}
private function checkApiKeyHeader()
{
$soapHeaders = $this->container->get('request')->getSoapHeaders();
// You can use '1234' !== (string) $soapHeaders->get('api_key')
if (!$soapHeaders->has('api_key') || '1234' !== $soapHeaders->get('api_key')->getData()) {
throw new \SoapFault("INVALID_API_KEY", "The api_key is invalid.");
}
}
}

View File

@ -0,0 +1,9 @@
Tutorials
=========
.. toctree::
:maxdepth: 1
tutorial/array
tutorial/complex_type
tutorial/header

View File

@ -0,0 +1,25 @@
Types available
===============
+----------+-----------------+
| Php Type | XML Type |
+==========+=================+
| string | `xsd:string`_ |
+----------+-----------------+
| boolean | `xsd:boolean`_ |
+----------+-----------------+
| int | `xsd:int`_ |
+----------+-----------------+
| float | `xsd:float`_ |
+----------+-----------------+
| date | `xsd:date`_ |
+----------+-----------------+
| dateTime | `xsd:dateTime`_ |
+----------+-----------------+
.. _`xsd:string`: http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/datatypes.html#string
.. _`xsd:boolean`: http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/datatypes.html#boolean
.. _`xsd:int`: http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/datatypes.html#int
.. _`xsd:float`: http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/datatypes.html#float
.. _`xsd:date`: http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/datatypes.html#date
.. _`xsd:dateTime`: http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/datatypes.html#dateTime