Utiliser nuSOAP Bundle avec Symfony2

Share Button

J’ai besoin d’utiliser des webservices SOAP, je veux utiliser nuSOAP, après quelques recherches, je vois le bundle symfony2 de nuSOAP.

Sur leur doc, il y a ça :

{
    "require": {
        "noiselabs/nusoap-bundle": "dev-master"
    },
    "repositories": [
        {
            "type": "package",
            "package": {
                "name": "nusphere/nusoap",
                "version": "0.9.5",
                "dist": {
                    "url": "http://downloads.sourceforge.net/project/nusoap/nusoap/0.9.5/nusoap-0.9.5.zip",
                    "type": "zip"
                },
                "autoload": {
                    "classmap": ["lib/"]
                }
            }
        }
    ],
}

Je met ça dans mon composer.json et j’obtiens des erreurs lorsque je lance composer, en mettant ce code à la fin de mon fichier, ça me désinstallait une partie des bundle (je ne suis pas très familier avec composer).

J’ai pris la ligne require que j’ai simplement ajouté , il faut penser à finir la ligne du dessus par une virgule:

    "require": {
        "php": ">=5.3.3",
        "symfony/symfony": "~2.4",
        "doctrine/orm": "~2.2,>=2.2.3",
        "doctrine/doctrine-bundle": "~1.2",
        "twig/extensions": "~1.0",
        "symfony/assetic-bundle": "~2.3",
        "symfony/swiftmailer-bundle": "~2.3",
        "symfony/monolog-bundle": "~2.4",
        "sensio/distribution-bundle": "~2.3",
        "sensio/framework-extra-bundle": "~3.0",
        "sensio/generator-bundle": "~2.3",
        "incenteev/composer-parameter-handler": "~2.0",
        "doctrine/doctrine-fixtures-bundle": "2.2.*",
        "ddeboer/data-import": "@stable",
        "ddeboer/data-import-bundle": "~0.1",
        "noiselabs/nusoap-bundle": "dev-master"
    },

Et à la fin du fichier, j’ai ajouté le repository de type “package”, il faut ajouter une virgule après le } de la section “extra” et coller le code :

 "repositories": [
        {
            "type": "package",
            "package": {
                "name": "nusphere/nusoap",
                "version": "0.9.5",
                "dist": {
                    "url": "http://downloads.sourceforge.net/project/nusoap/nusoap/0.9.5/nusoap-0.9.5.zip",
                    "type": "zip"
                },
                "autoload": {
                    "classmap": ["lib/"]
                }
            }
        }
    ]

 

Voici mon fichier composer.json avec nuSOAP Bundle qui fonctionne en entier.

{
    "name": "symfony/framework-standard-edition",
    "license": "MIT",
    "type": "project",
    "description": "The \"Symfony Standard Edition\" distribution",
    "autoload": {
        "psr-0": { "": "src/" }
    },
    "require": {
        "php": ">=5.3.3",
        "symfony/symfony": "~2.4",
        "doctrine/orm": "~2.2,>=2.2.3",
        "doctrine/doctrine-bundle": "~1.2",
        "twig/extensions": "~1.0",
        "symfony/assetic-bundle": "~2.3",
        "symfony/swiftmailer-bundle": "~2.3",
        "symfony/monolog-bundle": "~2.4",
        "sensio/distribution-bundle": "~2.3",
        "sensio/framework-extra-bundle": "~3.0",
        "sensio/generator-bundle": "~2.3",
        "incenteev/composer-parameter-handler": "~2.0",
        "doctrine/doctrine-fixtures-bundle": "2.2.*",
        "ddeboer/data-import": "@stable",
        "ddeboer/data-import-bundle": "~0.1",
        "noiselabs/nusoap-bundle": "dev-master"
    },
    "scripts": {
        "post-install-cmd": [
            "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"
        ],
        "post-update-cmd": [
            "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"
        ]
    },
    "config": {
        "bin-dir": "bin"
    },
    "extra": {
        "symfony-app-dir": "app",
        "symfony-web-dir": "web",
        "incenteev-parameters": {
            "file": "app/config/parameters.yml"
        },
        "branch-alias": {
            "dev-master": "2.4-dev"
        }
        
    },    "repositories": [
        {
            "type": "package",
            "package": {
                "name": "nusphere/nusoap",
                "version": "0.9.5",
                "dist": {
                    "url": "http://downloads.sourceforge.net/project/nusoap/nusoap/0.9.5/nusoap-0.9.5.zip",
                    "type": "zip"
                },
                "autoload": {
                    "classmap": ["lib/"]
                }
            }
        }
    ]


}

Pour finir le code de mon controller, qui utilise un service de météo, juste pour initialiser et tester le SOAP.

    /**
     * @Route("/Connect")
     * @Template()
     */
    public function ConnectAction()
    {
      $error = "";

      $client = new \nusoap_client('http://www.webservicex.net/globalweather.asmx?WSDL', 'wsdl');					
      
      $err = $client->getError();
      if ($err) {
	      $error .= "<h2>Constructor error</h2><pre>" . $err . "</pre>";
      }
     
      $param = array('CountryName' => 'FRANCE');

      $result = $client->call('GetCitiesByCountry', array('parameters' => $param), '', '', false, true);

      // Check for a fault
      if ($client->fault) {
	$error .= "<h2>Fault</h2><pre>";
	$error .= print_r($result);
	$error .= "</pre>";
      } else {
	// Check for errors
	$err = $client->getError();
	  if ($err) {
		  // Display the error
		  $error .= "<h2>Error</h2><pre>" . $err . "</pre>";
	  } else {
		  // Display the result
		  $resultat["resultat"] = $result;
		  
	  }
	}

	$xml = simplexml_load_string($result["GetCitiesByCountryResult"]);

	foreach ($xml->Table as $character) {
	  echo $character->City."</br>";
	}

		
	return $resultat;

    }

 

 

 

 

 

 

 

 

 

 

 

 

 

Share Button

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>