Skip to content

Commit

Permalink
add command to services
Browse files Browse the repository at this point in the history
  • Loading branch information
Gyvastis committed Sep 3, 2021
1 parent bb221ce commit f1f34b5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 33 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
}
},
"require": {
"php": ">=7.4",
"php": ">=8.0",
"guzzlehttp/guzzle": "^7.3",
"php-arsenal/salesforce-soap-client": "^2.0",
"symfony/console": "^5.2",
Expand Down
44 changes: 15 additions & 29 deletions src/Command/RefreshWsdlCommand.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace PhpArsenal\SalesforceBundle\Command;

use PhpArsenal\SoapClient\Client;
Expand All @@ -10,34 +11,25 @@

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

private const COMMAND_NAME = 'salesforce:wsdl:refresh';
protected static $defaultName = 'salesforce:wsdl:refresh';

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

$this->soapClient = $soapClient;
parent::__construct();
}

/**
* {@inheritdoc}
*/
protected function configure()
protected function configure(): void
{
$this
->setName(self::COMMAND_NAME)
->setDescription('Refresh Salesforce WSDL')
->setHelp(
'Refreshing the WSDL itself requires a WSDL, so when using this'
Expand All @@ -55,21 +47,18 @@ protected function configure()
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$output->writeln('Updating the WSDL file');

$this->downloadWsdl();

if (!$input->getOption('no-cache-clear')) {
$command = $this->getApplication()->find('cache:clear');

$arguments = array(
'command' => 'cache:clear',
);
$input = new ArrayInput($arguments);
$command->run($input, $output);
$command->run(new ArrayInput(['command' => 'cache:clear']), $output);
}

return Command::SUCCESS;
}

public function downloadWsdl(): void
Expand All @@ -95,13 +84,10 @@ public function downloadWsdl(): void
]
]);

$wsdlFile = $this->getContainer()->getParameter('salesforce.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()));
}

file_put_contents($wsdlFile, (string)$response->getBody());
file_put_contents($this->wsdlPath, (string)$response->getBody());
}
}

}
11 changes: 8 additions & 3 deletions src/DependencyInjection/SalesforceExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,15 @@ public function load(array $configs, ContainerBuilder $container)
$configuration = new Configuration();
$processedConfiguration = $this->processConfiguration($configuration, $configs);

$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$fileLocator = new FileLocator(__DIR__.'/../Resources/config');

$xmlLoader = new Loader\XmlFileLoader($container, $fileLocator);
$xmlLoader->load('soap_client.xml');
$xmlLoader->load('rest_client.xml');

$yamlLoader = new Loader\YamlFileLoader($container, $fileLocator);
$yamlLoader->load('services.yaml');

$loader->load('soap_client.xml');
$loader->load('rest_client.xml');
foreach ($processedConfiguration as $key => $value) {
$container->setParameter('salesforce.soap_client.' . $key, $value);
}
Expand Down
4 changes: 4 additions & 0 deletions src/Resources/config/services.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
services:
PhpArsenal\SalesforceBundle\Command\RefreshWsdlCommand:
autoconfigure: true
arguments: ['@salesforce.soap_client', '%salesforce.soap_client.wsdl%']

0 comments on commit f1f34b5

Please sign in to comment.