/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $destination = rtrim($input->getArgument('destination'), '/\\'); if (!$this->filesystem->dirextoryExists($destination)) { throw new RunTimeException(sprintf('The destination %s does not exist.', $destination)); } $wsdl = $input->getOption('wsdl'); if (!$wsdl) { throw new RuntimeException('You MUST specify a WSDL endpoint.'); } $namespace = $input->getOption('namespace'); $soapClient = new SoapClient($wsdl, []); $types = $soapClient->getSoapTypes(); $generator = new TypeGenerator($namespace); foreach ($types as $type => $properties) { // Check if file exists: $file = sprintf('%s/%s.php', $destination, ucfirst($type)); $data = $generator->generate($type, $properties); // Existing files ... if ($this->filesystem->fileExists($file)) { $this->handleExistingFile($input, $output, $file, $type, $data); continue; } // New files... $this->filesystem->putFileContents($file, $data); $output->writeln(sprintf('Generated class %s to %s', $type, $file)); } $output->writeln('Done'); }
/** * {@inheritdoc} * @throws \Phpro\SoapClient\Exception\InvalidArgumentException */ protected function execute(InputInterface $input, OutputInterface $output) { $configFile = $input->getOption('config'); if (!$configFile || !$this->filesystem->fileExists($configFile)) { throw InvalidArgumentException::invalidConfigFile(); } $config = (include $configFile); if (!$config instanceof ConfigInterface) { throw InvalidArgumentException::invalidConfigFile(); } $soapClient = new SoapClient($config->getWsdl(), $config->getSoapOptions()); $typeMap = TypeMap::fromSoapClient($config->getNamespace(), $soapClient); $file = new FileGenerator(); $generator = new ClassMapGenerator($config->getRuleSet()); $output->write($generator->generate($file, $typeMap)); }
/** * Try to create a class for a type. * When a class exists: try to patch * If patching the old class does not wor: ask for an overwrite * Create a class from an empty file * * @param TypeGenerator $generator * @param Type $type * @param $path * * @return bool */ protected function handleType(TypeGenerator $generator, Type $type, $path) { // Handle existing class: if ($this->filesystem->fileExists($path)) { if ($this->handleExistingFile($generator, $type, $path)) { return true; } // Ask if a class can be overwritten if it contains errors if (!$this->askForOverwrite()) { $this->output->writeln(sprintf('Skipping %s', $type->getName())); return false; } } // Try to create a blanco class: try { $file = new FileGenerator(); $this->generateType($file, $generator, $type, $path); } catch (\Exception $e) { $this->output->writeln('<fg=red>' . $e->getMessage() . '</fg=red>'); return false; } return true; }