Developed with love by KnpLabs Hire us for your project!
12

HeriWebServiceBundle

by heristop

This bundle allows to configure the mapping between an entity and a webservice

WebServiceBundle

This bundle allows to synchronize a table with a soap webservice.

Installation

Download sources from github:


    [HeriJobQueueBundle]
        git=https://github.com/heristop/HeriWebServiceBundle.git
        target=/bundles/Heri/WebServiceBundle/

Or use composer adding the requirement below:

{
    "require": {
        "heristop/webservice-bundle": "*"
    }
}

Register namespace in autoload:


    $loader->registerNamespaces(array(
        ...
        'Heri' => __DIR__.'/../vendor/bundles',
    ));

Load in AppKernel:

    $bundles[] = new Heri\WebServiceBundle\HeriWebServiceBundle();

Usage

First, add the column toUpdate in your entity definition.
This field will be set to false after the synchronization:


    /**
     * @ORM\Column(name="to_update", type="boolean")
     */
    protected $toUpdate;

Generate getters and setters:

    app/console doctrine:generate:entities %YourBundle%

Create a class in %YourBundle%/Service directory to apply the mapping with the WSDL.
The bundle contains an example:


    namespace Heri\Bundle\WebServiceBundle\Service;

    use Heri\Bundle\WebServiceBundle\ClientSoap\ClientObject;

    class Sample extends ClientObject
    {
        public function configure()
        {
            $this->name  = 'sample';
            $this->table = 'HeriWebServiceBundle:Sample';
            $this->func  = 'addSample';
        }

        public function hydrate($record)
        {  
            $this->params = array(
                'id'    => $record->getId(),
                'label' => $record->getLabel(),
            );
        }

    }

Configure the webservices connection in config.yml:


    heri_web_service:  
        namespaces:             [ %YourBundleNamespace%\Service ]
        authentication:                      # optional
            login:              %login%
            password:           %password%
        webservices:
            brand:
                name:           brand
                url:            %soap_url%
                authentication: true         # optional

Then, use this command to call a webservice and retrieve all the records with toUpdate to true:

    app:console webservice:load %Service%

To see the list of available functions add list option.

Configuration

Edit config.yml to add SyncListener:


    services:
       sync.listener:
            class: Heri\Bundle\WebServiceBundle\Listener\SyncListener
            tags:
                - { name: doctrine.event_listener, event: prePersist, connection: default }
                - { name: doctrine.event_listener, event: postPersist, connection: default }

JobQueue

This bundle can be used with HeriJobQueueBundle to manage multiple webservice connections.

Override configuration and add the depedency to jobqueue service in config.yml:


    services:
        sync.listener:
            class: Heri\Bundle\WebServiceBundle\Listener\SyncListener
            arguments: [@jobqueue]
            tags:
                - { name: doctrine.event_listener, event: prePersist, connection: default }
                - { name: doctrine.event_listener, event: postPersist, connection: default }
        jobqueue:
            class: Heri\Bundle\JobQueueBundle\Service\QueueService
            arguments: [@logger]
            tags:
                - { name: monolog.logger, channel: jobqueue }

Add a method called synchronize() in the object which return the name of queue:


    /**
     * Adds synchronization in specified queue
     * 
     * @return string
     */
    public function synchronize()
    {
        return '%queue_name%';
    }

When the record will be saved in database, the synchronization to the webservice will be pushed in queue.

Note

You can override the ClientObject class in order to apply a specific configuration.

The example below shows the method to connect your application to a Magento plateform:


heri_web_service:
    namespaces:             [ %YourBundleNamespace%\Service ]
    authentication:
        login:              sampleuser
        password:           123456
    webservices:
        magento:
            name:           api
            url:            http://myshop-local.com/index.php/api/

abstract class ClientMagento extends ClientObject
{
    protected $name = 'api';

    protected function callFunction($func, array $params = array())
    {
        $connection = $this->getContainer()->getConnection();
        $sessionId = $this->client->login($connection->getLogin(), $connection->getPassword());

        return $this->client->call(
            $sessionId,
            $func,
            $params
        );
    }
}
Copyright (c) 2011 Alexandre Mogère

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
heri_web_service:
namespaces: []
authentication:
login: ~ # Required
password: ~ # Required
webservices:
name: ~ # Required
url: ~ # Required
authentication: false
cache_enabled: false
  • Updated namespace
    By heristop, 3 years ago
  • Use ZF2 class
    By heristop, 3 years ago
  • Fixed taypo
    By heristop, 3 years ago
  • Added composer.json
    By heristop, 3 years ago
  • [Propel] fixed update on 1 record
    By heristop, 5 years ago
  • Fixed typo for authentication
    By heristop, 5 years ago
  • Added Propel support
    By heristop, 5 years ago
  • Added Propel support
    By heristop, 5 years ago
  • Added a sample for the unit tests
    By heristop, 6 years ago
  • Fixed set to update
    By heristop, 6 years ago
  • fixed typo
    By heristop, 6 years ago
  • [Command] added list option to see available functions
    By heristop, 6 years ago
  • Give container to soap exception to log faults
    By heristop, 6 years ago
  • Uses array prototype to configure webservices
    By heristop, 6 years ago
  • Override joqueue service config to avoid circular reference
    By heristop, 6 years ago
  • README
    By heristop, 6 years ago
  • The call to jobqueue in the listener is now optional
    By heristop, 6 years ago
  • First commit
    By heristop, 6 years ago