Skip to content

Commit

Permalink
update deprecated command
Browse files Browse the repository at this point in the history
  • Loading branch information
Gyvastis committed Apr 12, 2021
1 parent 16d7d46 commit 824f0c7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
"require": {
"php": ">=7.4",
"guzzlehttp/guzzle": "^7.3",
"php-arsenal/salesforce-soap-client": "^2.0"
"php-arsenal/salesforce-soap-client": "^2.0",
"symfony/console": "^5.2",
"ext-curl": "*",
"ext-simplexml": "*"
},
"require-dev": {
"phpunit/phpunit": "^9.5",
Expand Down
30 changes: 23 additions & 7 deletions src/SalesforceBundle/Command/RefreshWsdlCommand.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,43 @@
<?php
namespace PhpArsenal\SalesforceBundle\Command;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use PhpArsenal\SoapClient\Client;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\ArrayInput;
use GuzzleHttp\Client;

/**
* Fetch latest WSDL from Salesforce and store it locally
*
* @author David de Boer <[email protected]>
*/
class RefreshWsdlCommand extends ContainerAwareCommand
class RefreshWsdlCommand extends Command
{
/** @var Client */
private $soapClient;

private const COMMAND_NAME = 'arsenal:refresh-wsdl';

/**
* RefreshWsdlCommand constructor.
* @param Client $soapClient
*/
public function __construct(Client $soapClient)
{
parent::__construct(self::COMMAND_NAME);

$this->soapClient = $soapClient;
}

/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('arsenal:refresh-wsdl')
->setName(self::COMMAND_NAME)
->setDescription('Refresh Salesforce WSDL')
->setHelp(
'Refreshing the WSDL itself requires a WSDL, so when using this'
Expand Down Expand Up @@ -59,14 +75,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
public function downloadWsdl(): void
{
/** @var \PhpArsenal\SoapClient\Client $client */
$client = $this->getContainer()->get('arsenal.soap_client');
$client = $this->soapClient;

// Get current session id
$loginResult = $client->getLoginResult();
$sessionId = $loginResult->getSessionId();

// type=* for enterprise WSDL
$response = (new Client())->request('GET', vsprintf('https://%s.my.salesforce.com/soap/wsdl.jsp?type=*', [
$response = (new \GuzzleHttp\Client())->request('GET', vsprintf('https://%s.my.salesforce.com/soap/wsdl.jsp?type=*', [
$loginResult->getServerInstance()
]), [
'headers' => [
Expand All @@ -81,7 +97,7 @@ public function downloadWsdl(): void

$wsdlFile = $this->getContainer()->getParameter('arsenal.soap_client.wsdl');

if(!simplexml_load_string((string)$response->getBody())) {
if(!\simplexml_load_string((string)$response->getBody())) {
throw new \Exception('The downloaded WSDL is invalid. ' . sprintf('`%s`', (string)$response->getBody()));
}

Expand Down

0 comments on commit 824f0c7

Please sign in to comment.