Your project must not contain invalid function or method calls 347
- Read doc
- Reliability
- Major
More information: https://insight.symfony.com/what-we-analyse/php.invalid_call
- protected OutputInterface $output;
- protected function configure(): void
- {
- $this->addOption(
- 'force',
- null,
- InputOption::VALUE_NONE,
- 'If true, then package is really generated otherwise debug information are displayed'
- );
- return true === (bool) $this->getOptionValue('force');
- }
- protected function writeLn($messages, int $type = OutputInterface::OUTPUT_NORMAL): void
- {
- $this->output->writeln($messages, $type);
- }
- protected function getOptionValue(string $name)
- {
- return $this->input->getOption($name);
- public function resolveGeneratorOptionsConfigPath(): ?string
- {
- $path = null;
- $possibilities = $this->getGeneratorOptionsPossibilities();
- foreach ($possibilities as $possibility) {
- if (!empty($possibility) && is_file($possibility)) {
- $path = $possibility;
- break;
- }
- }
- }
- protected function configure(): void
- {
- parent::configure();
- $this
- ->setName('generate:package')
- ->setDescription('Generate package based on options')
- ->addOption(
- 'urlorpath',
- null,
- }
- protected function configure(): void
- {
- parent::configure();
- $this
- ->setName('generate:package')
- ->setDescription('Generate package based on options')
- ->addOption(
- 'urlorpath',
- null,
- }
- protected function configure(): void
- {
- parent::configure();
- $this
- ->setName('generate:package')
- ->setDescription('Generate package based on options')
- ->addOption(
- 'urlorpath',
- null,
- foreach ($this->getPackageGenerationCommandLineOptions() as $optionName => $generatorOptionName) {
- if (is_null($optionValue = $this->formatOptionValue($this->input->getOption($optionName)))) {
- continue;
- }
- $generatorOptions->setOptionValue($generatorOptionName, $optionValue);
- }
- $this->generatorOptions = $generatorOptions;
- return $this;
- }
- $this->parseReservedKeywords($filename);
- }
- public function is(string $keyword): bool
- {
- return in_array($keyword, $this->keywords[self::CASE_SENSITIVE_KEY], true) || in_array(mb_strtolower($keyword), $this->keywords[self::CASE_INSENSITIVE_KEY], true);
- }
- protected function parseReservedKeywords(string $filename): AbstractReservedWord
- {
- $allKeywords = $this->parseSimpleArray($filename, self::MAIN_KEY);
- protected function parseReservedKeywords(string $filename): AbstractReservedWord
- {
- $allKeywords = $this->parseSimpleArray($filename, self::MAIN_KEY);
- $caseSensitiveKeywords = $allKeywords[self::CASE_SENSITIVE_KEY];
- $caseInsensitiveKeywords = array_map('strtolower', $allKeywords[self::CASE_INSENSITIVE_KEY]);
- $this->keywords = array_merge_recursive($this->keywords, [
- self::CASE_SENSITIVE_KEY => $caseSensitiveKeywords,
- self::CASE_INSENSITIVE_KEY => $caseInsensitiveKeywords,
- ]);
- protected function parseReservedKeywords(string $filename): AbstractReservedWord
- {
- $allKeywords = $this->parseSimpleArray($filename, self::MAIN_KEY);
- $caseSensitiveKeywords = $allKeywords[self::CASE_SENSITIVE_KEY];
- $caseInsensitiveKeywords = array_map('strtolower', $allKeywords[self::CASE_INSENSITIVE_KEY]);
- $this->keywords = array_merge_recursive($this->keywords, [
- self::CASE_SENSITIVE_KEY => $caseSensitiveKeywords,
- self::CASE_INSENSITIVE_KEY => $caseInsensitiveKeywords,
- ]);
- protected function loadYaml(string $filename)
- {
- $ymlParser = new Parser();
- return $ymlParser->parse(file_get_contents($filename));
- }
- /**
- * @throws \InvalidArgumentException
- */
- * @throws \InvalidArgumentException
- */
- protected function parseSimpleArray(string $filename, string $mainKey): array
- {
- $values = $this->loadYaml($filename);
- if (!array_key_exists($mainKey, $values)) {
- throw new \InvalidArgumentException(sprintf('Unable to find section "%s" in "%s"', $mainKey, $filename), __LINE__);
- }
- return $values[$mainKey];
- }
- {
- if (!array_key_exists($optionName, $this->options)) {
- throw new \InvalidArgumentException(sprintf('Invalid option name "%s", possible options: %s', $optionName, implode(', ', array_keys($this->options))), __LINE__);
- }
- return array_key_exists('value', $this->options[$optionName]) ? $this->options[$optionName]['value'] : $this->options[$optionName]['default'];
- }
- public function setOptionValue(string $optionName, $optionValue, array $values = []): self
- {
- if (!array_key_exists($optionName, $this->options)) {
- if (!array_key_exists($optionName, $this->options)) {
- $this->options[$optionName] = [
- 'value' => $optionValue,
- 'values' => $values,
- ];
- } elseif (!empty($this->options[$optionName]['values']) && !in_array($optionValue, $this->options[$optionName]['values'], true)) {
- throw new \InvalidArgumentException(sprintf('Invalid value "%s" for option "%s", possible values: %s', $optionValue, $optionName, implode(', ', $this->options[$optionName]['values'])), __LINE__);
- } else {
- $this->options[$optionName]['value'] = $optionValue;
- }
- $this->options[$optionName] = [
- 'value' => $optionValue,
- 'values' => $values,
- ];
- } elseif (!empty($this->options[$optionName]['values']) && !in_array($optionValue, $this->options[$optionName]['values'], true)) {
- throw new \InvalidArgumentException(sprintf('Invalid value "%s" for option "%s", possible values: %s', $optionValue, $optionName, implode(', ', $this->options[$optionName]['values'])), __LINE__);
- } else {
- $this->options[$optionName]['value'] = $optionValue;
- }
- return $this;
- $this->options[$optionName] = [
- 'value' => $optionValue,
- 'values' => $values,
- ];
- } elseif (!empty($this->options[$optionName]['values']) && !in_array($optionValue, $this->options[$optionName]['values'], true)) {
- throw new \InvalidArgumentException(sprintf('Invalid value "%s" for option "%s", possible values: %s', $optionValue, $optionName, implode(', ', $this->options[$optionName]['values'])), __LINE__);
- } else {
- $this->options[$optionName]['value'] = $optionValue;
- }
- return $this;
- return __DIR__.'/../resources/config/generator_options.yml';
- }
- public static function methodNameToOptionName(string $name): string
- {
- return strtolower(trim(preg_replace(StructValue::MATCH_PATTERN, StructValue::REPLACEMENT_PATTERN, substr($name, 3)), '_'));
- }
- public function setAddComments(array $addComments = []): self
- {
- /**
- /**
- * If array is type array("author:john Doe","Release:1",).
- */
- $comments = [];
- foreach ($addComments as $index => $value) {
- if (is_numeric($index) && mb_strpos($value, ':') > 0) {
- [$tag, $val] = explode(':', $value);
- $comments[$tag] = $val;
- } else {
- $comments[$index] = $value;
- }
- * If array is type array("author:john Doe","Release:1",).
- */
- $comments = [];
- foreach ($addComments as $index => $value) {
- if (is_numeric($index) && mb_strpos($value, ':') > 0) {
- [$tag, $val] = explode(':', $value);
- $comments[$tag] = $val;
- } else {
- $comments[$index] = $value;
- }
- }
- /**
- * If array is type array("config.value:true","require:library/src",).
- */
- $settings = [];
- foreach ($composerSettings as $index => $value) {
- if (is_numeric($index) && mb_strpos($value, ':') > 0) {
- $path = implode('', array_slice(explode(':', $value), 0, 1));
- $val = implode(':', array_slice(explode(':', $value), 1));
- self::dotNotationToArray($path, $val, $settings);
- } else {
- $settings[$index] = $value;
- * If array is type array("config.value:true","require:library/src",).
- */
- $settings = [];
- foreach ($composerSettings as $index => $value) {
- if (is_numeric($index) && mb_strpos($value, ':') > 0) {
- $path = implode('', array_slice(explode(':', $value), 0, 1));
- $val = implode(':', array_slice(explode(':', $value), 1));
- self::dotNotationToArray($path, $val, $settings);
- } else {
- $settings[$index] = $value;
- }
- */
- $settings = [];
- foreach ($composerSettings as $index => $value) {
- if (is_numeric($index) && mb_strpos($value, ':') > 0) {
- $path = implode('', array_slice(explode(':', $value), 0, 1));
- $val = implode(':', array_slice(explode(':', $value), 1));
- self::dotNotationToArray($path, $val, $settings);
- } else {
- $settings[$index] = $value;
- }
- }
- protected int $offset = 0;
- public function offsetExists($offset): bool
- {
- $element = array_slice($this->objects, $offset, 1);
- return !empty($element);
- }
- /**
- * @return mixed
- */
- #[\ReturnTypeWillChange]
- public function offsetGet($offset)
- {
- $element = array_slice($this->objects, $offset, 1);
- return $this->offsetExists($offset) ? array_shift($element) : null;
- }
- /**
- #[\ReturnTypeWillChange]
- public function offsetUnset($offset): void
- {
- if ($this->offsetExists($offset)) {
- unset($this->objects[$this->getObjectKey($this->offsetGet($offset))]);
- }
- }
- /**
- * @return mixed
- {
- if (!is_scalar($value)) {
- throw new \InvalidArgumentException(sprintf('Value "%s" can\'t be used to get an object from "%s"', is_object($value) ? get_class($value) : var_export($value, true), get_class($this)), __LINE__);
- }
- return array_key_exists($value, $this->objects) ? $this->objects[$value] : null;
- }
- public function jsonSerialize(): array
- {
- return array_values($this->objects);
- public function addService(string $serviceName, string $methodName, $methodParameter, $methodReturn): Service
- {
- if (!$this->get($serviceName) instanceof Model) {
- $this->add(new Model($this->generator, $serviceName));
- }
- $serviceMethod = $this->get($serviceName)->getMethod($methodName);
- // Service method does not already exist, register it
- if (!$serviceMethod instanceof MethodModel) {
- $this->get($serviceName)->addMethod($methodName, $methodParameter, $methodReturn);
- }
- }
- $serviceMethod = $this->get($serviceName)->getMethod($methodName);
- // Service method does not already exist, register it
- if (!$serviceMethod instanceof MethodModel) {
- $this->get($serviceName)->addMethod($methodName, $methodParameter, $methodReturn);
- }
- // Service method exists with a different signature, register it too by identifying the service functions as non unique functions
- elseif ($methodParameter !== $serviceMethod->getParameterType()) {
- $serviceMethod->setUnique(false);
- $this->get($serviceName)->addMethod($methodName, $methodParameter, $methodReturn, false);
- $this->get($serviceName)->addMethod($methodName, $methodParameter, $methodReturn);
- }
- // Service method exists with a different signature, register it too by identifying the service functions as non unique functions
- elseif ($methodParameter !== $serviceMethod->getParameterType()) {
- $serviceMethod->setUnique(false);
- $this->get($serviceName)->addMethod($methodName, $methodParameter, $methodReturn, false);
- }
- return $this;
- }
- $methods = new Method($this->generator);
- /** @var Model $service */
- foreach ($this->objects as $service) {
- foreach ($service->getMethods() as $method) {
- $methods->add($method);
- }
- }
- return $methods;
- }
- public function addStruct(string $structName, bool $isStruct = true, string $structType = ''): self
- {
- if (null === (empty($structType) ? $this->get($structName) : $this->getByType($structName, $structType))) {
- $model = new Model($this->generator, $structName, $isStruct);
- $this->add($model->setInheritance($structType));
- }
- return $this;
- }
- return array_key_exists($key, $this->objects) ? $this->objects[$key] : null;
- }
- public function getObjectKeyWithType(object $object, string $type): string
- {
- return $this->getTypeKey($this->getObjectKey($object), $type);
- }
- public function getObjectKeyWithVirtual(object $object): string
- {
- return $this->getVirtualKey($this->getObjectKey($object));
- return $this->getTypeKey($this->getObjectKey($object), $type);
- }
- public function getObjectKeyWithVirtual(object $object): string
- {
- return $this->getVirtualKey($this->getObjectKey($object));
- }
- /**
- * The key must not conflict with possible key values.
- */
- public function getFileDestination(bool $withSrc = true): string
- {
- return sprintf(
- '%s%s%s',
- $this->getDestinationFolder($withSrc),
- $this->getModel()->getSubDirectory(),
- !empty($this->getModel()->getSubDirectory()) ? '/' : ''
- );
- }
- public function getDestinationFolder(bool $withSrc = true): string
- {
- return sprintf(
- '%s%s%s',
- $this->getDestinationFolder($withSrc),
- $this->getModel()->getSubDirectory(),
- !empty($this->getModel()->getSubDirectory()) ? '/' : ''
- );
- }
- public function getDestinationFolder(bool $withSrc = true): string
- {
- return $this->model;
- }
- public function getModelFromStructAttribute(?StructAttributeModel $attribute = null): ?StructModel
- {
- return $this->getStructAttribute($attribute)->getTypeStruct();
- }
- public function getRestrictionFromStructAttribute(?StructAttributeModel $attribute = null): ?StructModel
- {
- $model = $this->getModelFromStructAttribute($attribute);
- throw new \InvalidArgumentException('Could not find any valid StructAttribute');
- }
- $attributeType = $this->getStructAttributeType($attribute, true, $returnArrayType);
- if (XsdTypes::instance($this->getGenerator()->getOptionXsdTypesPath())->isXsd($attributeType)) {
- $attributeType = self::getPhpType($attributeType, $this->getGenerator()->getOptionXsdTypesPath());
- }
- return $attributeType;
- }
- *
- * @return mixed
- */
- public static function getValidType($type, $xsdTypesPath = null, $fallback = null)
- {
- return XsdTypes::instance($xsdTypesPath)->isXsd(str_replace('[]', '', $type)) ? $fallback : $type;
- }
- /**
- * See http://php.net/manual/fr/language.oop5.typehinting.php for these cases
- * Also see http://www.w3schools.com/schema/schema_dtypes_numeric.asp.
- *
- * @return mixed
- */
- public static function getPhpType($type, $xsdTypesPath = null, $fallback = self::TYPE_STRING)
- {
- return XsdTypes::instance($xsdTypesPath)->isXsd(str_replace('[]', '', $type)) ? XsdTypes::instance($xsdTypesPath)->phpType($type) : $fallback;
- }
- protected function addAnnotationBlock(): AbstractModelFile
- {
- $this->getFile()->addAnnotationBlockElement($this->getClassAnnotationBlock());
- *
- * @return mixed
- */
- public static function getPhpType($type, $xsdTypesPath = null, $fallback = self::TYPE_STRING)
- {
- return XsdTypes::instance($xsdTypesPath)->isXsd(str_replace('[]', '', $type)) ? XsdTypes::instance($xsdTypesPath)->phpType($type) : $fallback;
- }
- protected function addAnnotationBlock(): AbstractModelFile
- {
- $this->getFile()->addAnnotationBlockElement($this->getClassAnnotationBlock());
- {
- $packageName = $this->getPackageName();
- if (!empty($packageName)) {
- $block->addChild(new PhpAnnotation(self::ANNOTATION_PACKAGE, $packageName));
- }
- if (count($this->getModel()->getDocSubPackages()) > 0) {
- $block->addChild(new PhpAnnotation(self::ANNOTATION_SUB_PACKAGE, implode(',', $this->getModel()->getDocSubPackages())));
- }
- return $this;
- }
- $packageName = $this->getPackageName();
- if (!empty($packageName)) {
- $block->addChild(new PhpAnnotation(self::ANNOTATION_PACKAGE, $packageName));
- }
- if (count($this->getModel()->getDocSubPackages()) > 0) {
- $block->addChild(new PhpAnnotation(self::ANNOTATION_SUB_PACKAGE, implode(',', $this->getModel()->getDocSubPackages())));
- }
- return $this;
- }
- return $block;
- }
- protected function getClassDeclarationLine(): string
- {
- return sprintf($this->getClassDeclarationLineText(), $this->getModel()->getName(), $this->getModel()->getContextualPart());
- }
- protected function getClassDeclarationLineText(): string
- {
- return 'This class stands for %s %s';
- return $block;
- }
- protected function getClassDeclarationLine(): string
- {
- return sprintf($this->getClassDeclarationLineText(), $this->getModel()->getName(), $this->getModel()->getContextualPart());
- }
- protected function getClassDeclarationLineText(): string
- {
- return 'This class stands for %s %s';
- return $block;
- }
- protected function getClassDeclarationLine(): string
- {
- return sprintf($this->getClassDeclarationLineText(), $this->getModel()->getName(), $this->getModel()->getContextualPart());
- }
- protected function getClassDeclarationLineText(): string
- {
- return 'This class stands for %s %s';
- return 'This class stands for %s %s';
- }
- protected function defineModelAnnotationsFromWsdl(PhpAnnotationBlock $block, ?AbstractModel $model = null): self
- {
- FileUtils::defineModelAnnotationsFromWsdl($block, $model instanceof AbstractModel ? $model : $this->getModel());
- return $this;
- }
- protected function addClassElement(): AbstractModelFile
- return $this;
- }
- protected function addClassElement(): AbstractModelFile
- {
- $class = new PhpClass($this->getModel()->getPackagedName(), $this->getModel()->isAbstract(), '' === $this->getModel()->getExtendsClassName() ? null : $this->getModel()->getExtendsClassName());
- $this
- ->defineConstants($class)
- ->defineProperties($class)
- ->defineMethods($class)
- ->getFile()
- return $this;
- }
- protected function addClassElement(): AbstractModelFile
- {
- $class = new PhpClass($this->getModel()->getPackagedName(), $this->getModel()->isAbstract(), '' === $this->getModel()->getExtendsClassName() ? null : $this->getModel()->getExtendsClassName());
- $this
- ->defineConstants($class)
- ->defineProperties($class)
- ->defineMethods($class)
- ->getFile()
- return $this;
- }
- protected function addClassElement(): AbstractModelFile
- {
- $class = new PhpClass($this->getModel()->getPackagedName(), $this->getModel()->isAbstract(), '' === $this->getModel()->getExtendsClassName() ? null : $this->getModel()->getExtendsClassName());
- $this
- ->defineConstants($class)
- ->defineProperties($class)
- ->defineMethods($class)
- ->getFile()
- return $this;
- }
- protected function defineNamespace(): self
- {
- if (!empty($this->getModel()->getNamespace())) {
- $this->getFile()->setNamespace($this->getModel()->getNamespace());
- }
- return $this;
- }
- }
- protected function defineNamespace(): self
- {
- if (!empty($this->getModel()->getNamespace())) {
- $this->getFile()->setNamespace($this->getModel()->getNamespace());
- }
- return $this;
- }
- return $this;
- }
- protected function defineUseStatements(): self
- {
- if (!empty($this->getModel()->getExtends())) {
- $this->getFile()->addUse($this->getModel()->getExtends(), null, true);
- }
- return $this;
- }
- }
- protected function defineUseStatements(): self
- {
- if (!empty($this->getModel()->getExtends())) {
- $this->getFile()->addUse($this->getModel()->getExtends(), null, true);
- }
- return $this;
- }
- protected function defineConstants(PhpClass $class): self
- {
- $constants = new Constant($this->getGenerator());
- $this->fillClassConstants($constants);
- foreach ($constants as $constant) {
- $annotationBlock = $this->getConstantAnnotationBlock($constant);
- if (!empty($annotationBlock)) {
- $class->addAnnotationBlockElement($annotationBlock);
- }
- $class->addConstantElement($constant);
- }
- foreach ($constants as $constant) {
- $annotationBlock = $this->getConstantAnnotationBlock($constant);
- if (!empty($annotationBlock)) {
- $class->addAnnotationBlockElement($annotationBlock);
- }
- $class->addConstantElement($constant);
- }
- return $this;
- }
- protected function defineProperties(PhpClass $class): self
- {
- $properties = new Property($this->getGenerator());
- $this->fillClassProperties($properties);
- foreach ($properties as $property) {
- $annotationBlock = $this->getPropertyAnnotationBlock($property);
- if (!empty($annotationBlock)) {
- $class->addAnnotationBlockElement($annotationBlock);
- }
- $class->addPropertyElement($property);
- }
- foreach ($properties as $property) {
- $annotationBlock = $this->getPropertyAnnotationBlock($property);
- if (!empty($annotationBlock)) {
- $class->addAnnotationBlockElement($annotationBlock);
- }
- $class->addPropertyElement($property);
- }
- return $this;
- }
- protected function defineMethods(PhpClass $class): self
- {
- $this->methods = new Method($this->getGenerator());
- $this->fillClassMethods();
- foreach ($this->methods as $method) {
- $annotationBlock = $this->getMethodAnnotationBlock($method);
- if (!empty($annotationBlock)) {
- $class->addAnnotationBlockElement($annotationBlock);
- }
- $class->addMethodElement($method);
- }
- foreach ($this->methods as $method) {
- $annotationBlock = $this->getMethodAnnotationBlock($method);
- if (!empty($annotationBlock)) {
- $class->addAnnotationBlockElement($annotationBlock);
- }
- $class->addMethodElement($method);
- }
- return $this;
- }
- protected function getStructAttributeTypeGetAnnotation(?StructAttributeModel $attribute = null, bool $returnArrayType = true, bool $nullableItemType = false): string
- {
- $attribute = $this->getStructAttribute($attribute);
- if ($attribute->isXml()) {
- return '\DOMDocument|string|null';
- }
- return sprintf(
- '%s%s%s',
- }
- return sprintf(
- '%s%s%s',
- $this->getStructAttributeTypeAsPhpType($attribute, false),
- $this->useBrackets($attribute, $returnArrayType) ? '[]' : '',
- !$nullableItemType && !$attribute->isNullable() && ($attribute->isRequired() || $attribute->isArray() || $attribute->isList()) ? '' : '|null'
- );
- }
- protected function getStructAttributeTypeSetAnnotation(StructAttributeModel $attribute, bool $returnArrayType = true, bool $itemType = false): string
- return sprintf(
- '%s%s%s',
- $this->getStructAttributeTypeAsPhpType($attribute, false),
- $this->useBrackets($attribute, $returnArrayType) ? '[]' : '',
- !$nullableItemType && !$attribute->isNullable() && ($attribute->isRequired() || $attribute->isArray() || $attribute->isList()) ? '' : '|null'
- );
- }
- protected function getStructAttributeTypeSetAnnotation(StructAttributeModel $attribute, bool $returnArrayType = true, bool $itemType = false): string
- {
- return sprintf(
- '%s%s%s',
- $this->getStructAttributeTypeAsPhpType($attribute, false),
- $this->useBrackets($attribute, $returnArrayType) ? '[]' : '',
- !$nullableItemType && !$attribute->isNullable() && ($attribute->isRequired() || $attribute->isArray() || $attribute->isList()) ? '' : '|null'
- );
- }
- protected function getStructAttributeTypeSetAnnotation(StructAttributeModel $attribute, bool $returnArrayType = true, bool $itemType = false): string
- {
- return sprintf(
- '%s%s%s',
- $this->getStructAttributeTypeAsPhpType($attribute, false),
- $this->useBrackets($attribute, $returnArrayType) ? '[]' : '',
- !$nullableItemType && !$attribute->isNullable() && ($attribute->isRequired() || $attribute->isArray() || $attribute->isList()) ? '' : '|null'
- );
- }
- protected function getStructAttributeTypeSetAnnotation(StructAttributeModel $attribute, bool $returnArrayType = true, bool $itemType = false): string
- {
- return sprintf(
- '%s%s%s',
- $this->getStructAttributeTypeAsPhpType($attribute, false),
- $this->useBrackets($attribute, $returnArrayType) ? '[]' : '',
- !$nullableItemType && !$attribute->isNullable() && ($attribute->isRequired() || $attribute->isArray() || $attribute->isList()) ? '' : '|null'
- );
- }
- protected function getStructAttributeTypeSetAnnotation(StructAttributeModel $attribute, bool $returnArrayType = true, bool $itemType = false): string
- {
- return $this->method;
- }
- protected function getParameterTypeModel(): ?StructModel
- {
- return $this->isParameterTypeAString() ? $this->getGenerator()->getStructByName($this->getMethod()->getParameterType()) : null;
- }
- protected function isParameterTypeEmpty(): bool
- {
- $parameterType = $this->getMethod()->getParameterType();
- }
- foreach ($parameterTypes as $parameterName => $parameterType) {
- $type = $methodUsage ? null : AbstractModelFile::TYPE_STRING;
- if (($model = $this->getGenerator()->getStructByName($parameterType)) instanceof StructModel) {
- if ($model->isStruct() && !$model->isRestriction()) {
- $type = $model->getPackagedName(true);
- } elseif (!$model->isStruct() && $model->isArray()) {
- if ($methodUsage) {
- $type = AbstractModelFile::TYPE_ARRAY;
- protected function getMethodParameter(string $name, ?string $type = null): PhpFunctionParameter
- {
- try {
- return new PhpFunctionParameter($name, PhpFunctionParameter::NO_VALUE, $type);
- } catch (\InvalidArgumentException $exception) {
- throw new \InvalidArgumentException(sprintf('Unable to create function parameter for method "%s" with type "%s" and name "%s"', $this->getMethod()->getName(), var_export($type, true), $name), __LINE__, $exception);
- }
- }
- protected function getModelByName(string $name): ?StructModel
- {
- protected function addMethodBody(PhpMethod $method): self
- {
- if ($this->getGenerator()->getStructs()->count() > 0) {
- $method->addChild('return [');
- foreach ($this->getGenerator()->getStructs() as $struct) {
- $this->addStructToClassMapList($method, $struct);
- }
- $method->addChild('];');
- }
- return $this;
- }
- protected function addStructToClassMapList(PhpMethod $method, StructModel $struct): self
- {
- if ($struct->isStruct() && !$struct->isRestriction()) {
- $method->addChild($method->getIndentedString(sprintf('\'%s\' => \'%s\',', $struct->getName(), $this->getStructName($struct)), 1));
- }
- return $this;
- }
- }
- protected function writeFile(): void
- {
- $composer = new Application();
- $composer->setAutoExit(false);
- $composer->run(new ArrayInput([
- 'command' => 'init',
- '--verbose' => true,
- '--no-interaction' => true,
- '--name' => $this->getGenerator()->getOptionComposerName(),
- $composer->run(new ArrayInput([
- 'command' => 'init',
- '--verbose' => true,
- '--no-interaction' => true,
- '--name' => $this->getGenerator()->getOptionComposerName(),
- '--description' => sprintf('Package generated from %s using wsdltophp/packagegenerator', $this->getGenerator()->getWsdl()->getName()),
- '--require' => [
- 'php:>=7.4',
- 'ext-dom:*',
- 'ext-mbstring:*',
- 'ext-soap:*',
- $composer->run(new ArrayInput([
- 'command' => 'init',
- '--verbose' => true,
- '--no-interaction' => true,
- '--name' => $this->getGenerator()->getOptionComposerName(),
- '--description' => sprintf('Package generated from %s using wsdltophp/packagegenerator', $this->getGenerator()->getWsdl()->getName()),
- '--require' => [
- 'php:>=7.4',
- 'ext-dom:*',
- 'ext-mbstring:*',
- 'ext-soap:*',
- protected function getComposerFileContent(): array
- {
- $content = [];
- $composerFilePath = $this->getComposerFilePath();
- if (!empty($composerFilePath)) {
- $content = json_decode(file_get_contents($composerFilePath), true, 512, JSON_THROW_ON_ERROR);
- }
- return $content;
- }
- protected function defineParametersFromArray(PhpMethod $method): self
- {
- if ($this->isParameterTypeAnArray()) {
- $parameters = [];
- foreach ($this->getParameterTypeArrayTypes(true) as $parameterName => $parameterType) {
- $parameters[] = $this->getMethodParameter($this->getParameterName($parameterName), $parameterType);
- }
- $method->setParameters($parameters);
- }
- return $this;
- }
- protected function defineParametersFromModel(PhpMethod $method): self
- {
- if ($this->isParameterTypeAModel()) {
- if ($this->getParameterTypeModel()->getAttributes(true, true)->count() > 0) {
- $method->setParameters([
- $this->getMethodParameter($this->getParameterName($this->getParameterTypeModel()->getPackagedName()), $this->getParameterTypeModel()->getPackagedName(true)),
- ]);
- }
- }
- protected function defineParametersFromModel(PhpMethod $method): self
- {
- if ($this->isParameterTypeAModel()) {
- if ($this->getParameterTypeModel()->getAttributes(true, true)->count() > 0) {
- $method->setParameters([
- $this->getMethodParameter($this->getParameterName($this->getParameterTypeModel()->getPackagedName()), $this->getParameterTypeModel()->getPackagedName(true)),
- ]);
- }
- }
- return $this;
- protected function defineParametersFromString(PhpMethod $method): self
- {
- if ($this->isParameterTypeAString() && !$this->isParameterTypeAModel()) {
- $method->setParameters([
- $this->getMethodParameter($this->getParameterName($this->getMethod()->getParameterType())),
- ]);
- }
- return $this;
- }
- return $this;
- }
- protected function getSoapCallName(): string
- {
- return sprintf('%s(\'%s\'%s', self::SOAP_CALL_NAME, $this->getMethod()->getName(), $this->getOperationCallParametersStarting());
- }
- protected function getOperationCallParameters(PhpMethod $method): string
- {
- $parameters = [];
- }
- protected function getOperationCallParameterName(PhpFunctionParameter $parameter, PhpMethod $method): string
- {
- $cloneParameter = clone $parameter;
- $cloneParameter->setType(null);
- return sprintf('%s%s', PhpMethod::BREAK_LINE_CHAR, $method->getIndentedString(sprintf('%s,', $cloneParameter->getPhpDeclaration()), 1));
- }
- }
- return $this;
- }
- protected function addOperationMethodDeclaration(PhpAnnotationBlock $annotationBlock): self
- {
- $annotationBlock->addChild(sprintf('Method to call the operation originally named %s', $this->getMethod()->getName()));
- if (!$this->getMethod()->isUnique()) {
- $annotationBlock->addChild('This method has been renamed because it is defined several times but with different signature');
- }
- return $this;
- $soapHeaderNamespaces = $this->getMethod()->getMetaValue(TagHeader::META_SOAP_HEADER_NAMESPACES, []);
- $soapHeaders = $this->getMethod()->getMetaValue(TagHeader::META_SOAP_HEADERS, []);
- if (!empty($soapHeaderNames) && !empty($soapHeaderTypes) && !empty($soapHeaderNamespaces)) {
- $annotationBlock
- ->addChild('Meta information extracted from the WSDL')
- ->addChild(new PhpAnnotation(PhpAnnotation::NO_NAME, sprintf('- SOAPHeaderNames: %s', implode(', ', $soapHeaderNames)), AbstractModelFile::ANNOTATION_LONG_LENGTH))
- ->addChild(new PhpAnnotation(PhpAnnotation::NO_NAME, sprintf('- SOAPHeaderNamespaces: %s', implode(', ', $soapHeaderNamespaces)), AbstractModelFile::ANNOTATION_LONG_LENGTH))
- ->addChild(new PhpAnnotation(PhpAnnotation::NO_NAME, sprintf('- SOAPHeaderTypes: %s', implode(', ', $this->getSoapHeaderTypesTypes($soapHeaderTypes))), AbstractModelFile::ANNOTATION_LONG_LENGTH))
- ->addChild(new PhpAnnotation(PhpAnnotation::NO_NAME, sprintf('- SOAPHeaders: %s', implode(', ', $soapHeaders)), AbstractModelFile::ANNOTATION_LONG_LENGTH))
- ;
- }
- $soapHeaders = $this->getMethod()->getMetaValue(TagHeader::META_SOAP_HEADERS, []);
- if (!empty($soapHeaderNames) && !empty($soapHeaderTypes) && !empty($soapHeaderNamespaces)) {
- $annotationBlock
- ->addChild('Meta information extracted from the WSDL')
- ->addChild(new PhpAnnotation(PhpAnnotation::NO_NAME, sprintf('- SOAPHeaderNames: %s', implode(', ', $soapHeaderNames)), AbstractModelFile::ANNOTATION_LONG_LENGTH))
- ->addChild(new PhpAnnotation(PhpAnnotation::NO_NAME, sprintf('- SOAPHeaderNamespaces: %s', implode(', ', $soapHeaderNamespaces)), AbstractModelFile::ANNOTATION_LONG_LENGTH))
- ->addChild(new PhpAnnotation(PhpAnnotation::NO_NAME, sprintf('- SOAPHeaderTypes: %s', implode(', ', $this->getSoapHeaderTypesTypes($soapHeaderTypes))), AbstractModelFile::ANNOTATION_LONG_LENGTH))
- ->addChild(new PhpAnnotation(PhpAnnotation::NO_NAME, sprintf('- SOAPHeaders: %s', implode(', ', $soapHeaders)), AbstractModelFile::ANNOTATION_LONG_LENGTH))
- ;
- }
- FileUtils::defineModelAnnotationsFromWsdl($annotationBlock, $this->getMethod(), [
- if (!empty($soapHeaderNames) && !empty($soapHeaderTypes) && !empty($soapHeaderNamespaces)) {
- $annotationBlock
- ->addChild('Meta information extracted from the WSDL')
- ->addChild(new PhpAnnotation(PhpAnnotation::NO_NAME, sprintf('- SOAPHeaderNames: %s', implode(', ', $soapHeaderNames)), AbstractModelFile::ANNOTATION_LONG_LENGTH))
- ->addChild(new PhpAnnotation(PhpAnnotation::NO_NAME, sprintf('- SOAPHeaderNamespaces: %s', implode(', ', $soapHeaderNamespaces)), AbstractModelFile::ANNOTATION_LONG_LENGTH))
- ->addChild(new PhpAnnotation(PhpAnnotation::NO_NAME, sprintf('- SOAPHeaderTypes: %s', implode(', ', $this->getSoapHeaderTypesTypes($soapHeaderTypes))), AbstractModelFile::ANNOTATION_LONG_LENGTH))
- ->addChild(new PhpAnnotation(PhpAnnotation::NO_NAME, sprintf('- SOAPHeaders: %s', implode(', ', $soapHeaders)), AbstractModelFile::ANNOTATION_LONG_LENGTH))
- ;
- }
- FileUtils::defineModelAnnotationsFromWsdl($annotationBlock, $this->getMethod(), [
- TagHeader::META_SOAP_HEADER_NAMES,
- $annotationBlock
- ->addChild('Meta information extracted from the WSDL')
- ->addChild(new PhpAnnotation(PhpAnnotation::NO_NAME, sprintf('- SOAPHeaderNames: %s', implode(', ', $soapHeaderNames)), AbstractModelFile::ANNOTATION_LONG_LENGTH))
- ->addChild(new PhpAnnotation(PhpAnnotation::NO_NAME, sprintf('- SOAPHeaderNamespaces: %s', implode(', ', $soapHeaderNamespaces)), AbstractModelFile::ANNOTATION_LONG_LENGTH))
- ->addChild(new PhpAnnotation(PhpAnnotation::NO_NAME, sprintf('- SOAPHeaderTypes: %s', implode(', ', $this->getSoapHeaderTypesTypes($soapHeaderTypes))), AbstractModelFile::ANNOTATION_LONG_LENGTH))
- ->addChild(new PhpAnnotation(PhpAnnotation::NO_NAME, sprintf('- SOAPHeaders: %s', implode(', ', $soapHeaders)), AbstractModelFile::ANNOTATION_LONG_LENGTH))
- ;
- }
- FileUtils::defineModelAnnotationsFromWsdl($annotationBlock, $this->getMethod(), [
- TagHeader::META_SOAP_HEADER_NAMES,
- TagHeader::META_SOAP_HEADER_NAMESPACES,
- protected function getSoapHeaderTypesTypes(array $soapHeaderTypes): array
- {
- $soapHeaderTypesTypes = [];
- foreach ($soapHeaderTypes as $soapHeaderType) {
- $soapHeaderTypesTypes[] = $this->getSoapHeaderTypeType($soapHeaderType, true);
- }
- return $soapHeaderTypesTypes;
- }
- protected function addOperationMethodParamFromArray(PhpAnnotationBlock $annotationBlock): self
- {
- if ($this->isParameterTypeAnArray()) {
- foreach ($this->getParameterTypeArrayTypes() as $parameterName => $parameterType) {
- $annotationBlock->addChild($this->getOperationMethodParam($parameterType, $this->getParameterName($parameterName)));
- }
- }
- return $this;
- }
- }
- protected function addOperationMethodParamFromModel(PhpAnnotationBlock $annotationBlock): self
- {
- if ($this->isParameterTypeAModel()) {
- $annotationBlock->addChild($this->getOperationMethodParam($this->getParameterTypeModel()->getPackagedName(true), $this->getParameterName($this->getParameterTypeModel()->getPackagedName())));
- }
- return $this;
- }
- }
- protected function addOperationMethodParamFromString(PhpAnnotationBlock $annotationBlock): self
- {
- if ($this->isParameterTypeAString() && !$this->isParameterTypeAModel()) {
- $annotationBlock->addChild($this->getOperationMethodParam($this->getMethod()->getParameterType(), lcfirst($this->getMethod()->getParameterType())));
- }
- return $this;
- }
- }
- protected function addOperationMethodParamFromString(PhpAnnotationBlock $annotationBlock): self
- {
- if ($this->isParameterTypeAString() && !$this->isParameterTypeAModel()) {
- $annotationBlock->addChild($this->getOperationMethodParam($this->getMethod()->getParameterType(), lcfirst($this->getMethod()->getParameterType())));
- }
- return $this;
- }
- if (is_null($returnType)) {
- return 'null';
- }
- if ((($struct = $generator->getStructByName($returnType)) instanceof StructModel) && !$struct->isRestriction()) {
- if ($struct->isStruct()) {
- $returnType = $struct->getPackagedName(true);
- } elseif ($struct->isArray()) {
- if (($structInheritance = $struct->getInheritanceStruct()) instanceof StructModel) {
- $returnType = sprintf('%s[]', $structInheritance->getPackagedName(true));
- protected function defineUseStatements(): AbstractModelFile
- {
- $this->getFile()->addUse(\SoapFault::class);
- /** @var Method $method */
- foreach ($this->getModel()->getMethods() as $method) {
- $soapHeaderTypes = $method->getMetaValue(TagHeader::META_SOAP_HEADER_TYPES, []);
- if (!is_array($soapHeaderTypes)) {
- continue;
- }
- foreach ($soapHeaderTypes as $soapHeaderType) {
- $soapHeaderTypes = $method->getMetaValue(TagHeader::META_SOAP_HEADER_TYPES, []);
- if (!is_array($soapHeaderTypes)) {
- continue;
- }
- foreach ($soapHeaderTypes as $soapHeaderType) {
- $model = $this->getModelByName($soapHeaderType);
- if (!$model instanceof StructModel) {
- continue;
- }
- if (!$model->isRestriction()) {
- continue;
- ;
- }
- protected function addSoapHeaderMethods(): self
- {
- foreach ($this->getModel()->getMethods() as $method) {
- $this->addSoapHeaderFromMethod($method);
- }
- return $this;
- }
- }
- protected function addSoapHeaderMethods(): self
- {
- foreach ($this->getModel()->getMethods() as $method) {
- $this->addSoapHeaderFromMethod($method);
- }
- return $this;
- }
- $soapHeaderNames = $method->getMetaValue(TagHeader::META_SOAP_HEADER_NAMES, []);
- $soapHeaderNamespaces = $method->getMetaValue(TagHeader::META_SOAP_HEADER_NAMESPACES, []);
- $soapHeaderTypes = $method->getMetaValue(TagHeader::META_SOAP_HEADER_TYPES, []);
- if (is_array($soapHeaderNames) && is_array($soapHeaderNamespaces) && is_array($soapHeaderTypes)) {
- foreach ($soapHeaderNames as $index => $soapHeaderName) {
- $methodName = $this->getSoapHeaderMethodName($soapHeaderName);
- if (is_null($this->methods->get($methodName))) {
- $soapHeaderNamespace = array_key_exists($index, $soapHeaderNamespaces) ? $soapHeaderNamespaces[$index] : null;
- $soapHeaderType = array_key_exists($index, $soapHeaderTypes) ? $soapHeaderTypes[$index] : null;
- $this->methods->add($this->getSoapHeaderMethod($methodName, $soapHeaderName, $soapHeaderNamespace, $soapHeaderType));
- }
- foreach ($soapHeaderNames as $index => $soapHeaderName) {
- $methodName = $this->getSoapHeaderMethodName($soapHeaderName);
- if (is_null($this->methods->get($methodName))) {
- $soapHeaderNamespace = array_key_exists($index, $soapHeaderNamespaces) ? $soapHeaderNamespaces[$index] : null;
- $soapHeaderType = array_key_exists($index, $soapHeaderTypes) ? $soapHeaderTypes[$index] : null;
- $this->methods->add($this->getSoapHeaderMethod($methodName, $soapHeaderName, $soapHeaderNamespace, $soapHeaderType));
- }
- }
- }
- return $this;
- foreach ($soapHeaderNames as $index => $soapHeaderName) {
- $methodName = $this->getSoapHeaderMethodName($soapHeaderName);
- if (is_null($this->methods->get($methodName))) {
- $soapHeaderNamespace = array_key_exists($index, $soapHeaderNamespaces) ? $soapHeaderNamespaces[$index] : null;
- $soapHeaderType = array_key_exists($index, $soapHeaderTypes) ? $soapHeaderTypes[$index] : null;
- $this->methods->add($this->getSoapHeaderMethod($methodName, $soapHeaderName, $soapHeaderNamespace, $soapHeaderType));
- }
- }
- }
- return $this;
- foreach ($soapHeaderNames as $index => $soapHeaderName) {
- $methodName = $this->getSoapHeaderMethodName($soapHeaderName);
- if (is_null($this->methods->get($methodName))) {
- $soapHeaderNamespace = array_key_exists($index, $soapHeaderNamespaces) ? $soapHeaderNamespaces[$index] : null;
- $soapHeaderType = array_key_exists($index, $soapHeaderTypes) ? $soapHeaderTypes[$index] : null;
- $this->methods->add($this->getSoapHeaderMethod($methodName, $soapHeaderName, $soapHeaderNamespace, $soapHeaderType));
- }
- }
- }
- return $this;
- $rules->applyRules(lcfirst($soapHeaderName));
- $firstParameter->setModel($model);
- }
- $method->addChild(sprintf('return $this->%s($%s, \'%s\', $%s, $%s, $%s);', self::METHOD_SET_HEADER_PREFIX, self::PARAM_SET_HEADER_NAMESPACE, $soapHeaderName, lcfirst($soapHeaderName), self::PARAM_SET_HEADER_MUSTUNDERSTAND, self::PARAM_SET_HEADER_ACTOR));
- } catch (\InvalidArgumentException $exception) {
- throw new \InvalidArgumentException(sprintf('Unable to create function parameter for service "%s" with type "%s"', $this->getModel()->getName(), var_export($this->getTypeFromName($soapHeaderName), true)), __LINE__, $exception);
- }
- return $method;
- }
- $rules->applyRules(lcfirst($soapHeaderName));
- $firstParameter->setModel($model);
- }
- $method->addChild(sprintf('return $this->%s($%s, \'%s\', $%s, $%s, $%s);', self::METHOD_SET_HEADER_PREFIX, self::PARAM_SET_HEADER_NAMESPACE, $soapHeaderName, lcfirst($soapHeaderName), self::PARAM_SET_HEADER_MUSTUNDERSTAND, self::PARAM_SET_HEADER_ACTOR));
- } catch (\InvalidArgumentException $exception) {
- throw new \InvalidArgumentException(sprintf('Unable to create function parameter for service "%s" with type "%s"', $this->getModel()->getName(), var_export($this->getTypeFromName($soapHeaderName), true)), __LINE__, $exception);
- }
- return $method;
- }
- protected function getTypeFromName(string $name): ?string
- {
- return self::getPhpType(
- $this->getStructAttributeTypeAsPhpType(new StructAttributeModel($this->generator, 'any', $name)),
- $this->getGenerator()->getOptionXsdTypesPath(),
- $this->getStructAttributeTypeAsPhpType(new StructAttributeModel($this->generator, 'any', $name))
- );
- }
- protected function getSoapHeaderMethodName(string $soapHeaderName): string
- return sprintf('%s%s', self::METHOD_SET_HEADER_PREFIX, ucfirst($soapHeaderName));
- }
- protected function addOperationsMethods(): self
- {
- foreach ($this->getModel()->getMethods() as $method) {
- $this->addMainMethod($method);
- }
- return $this;
- }
- }
- protected function addOperationsMethods(): self
- {
- foreach ($this->getModel()->getMethods() as $method) {
- $this->addMainMethod($method);
- }
- return $this;
- }
- ->addChild(new PhpAnnotation(self::ANNOTATION_THROWS, \InvalidArgumentException::class))
- ;
- }
- }
- $annotationBlock
- ->addChild(new PhpAnnotation(self::ANNOTATION_USES, sprintf('%s::%s()', $this->getModel()->getExtends(true), self::METHOD_SET_HEADER_PREFIX)))
- ->addChild(new PhpAnnotation(self::ANNOTATION_PARAM, sprintf('%s $%s', $firstParameterType, $firstParameter->getName())))
- ->addChild(new PhpAnnotation(self::ANNOTATION_PARAM, sprintf('%s $%s', self::TYPE_STRING, self::PARAM_SET_HEADER_NAMESPACE)))
- ->addChild(new PhpAnnotation(self::ANNOTATION_PARAM, sprintf('%s $%s', self::TYPE_BOOL, self::PARAM_SET_HEADER_MUSTUNDERSTAND)))
- ->addChild(new PhpAnnotation(self::ANNOTATION_PARAM, sprintf('%s|null $%s', self::TYPE_STRING, self::PARAM_SET_HEADER_ACTOR)))
- ->addChild(new PhpAnnotation(self::ANNOTATION_RETURN, $this->getModel()->getPackagedName(true)))
- ->addChild(new PhpAnnotation(self::ANNOTATION_USES, sprintf('%s::%s()', $this->getModel()->getExtends(true), self::METHOD_SET_HEADER_PREFIX)))
- ->addChild(new PhpAnnotation(self::ANNOTATION_PARAM, sprintf('%s $%s', $firstParameterType, $firstParameter->getName())))
- ->addChild(new PhpAnnotation(self::ANNOTATION_PARAM, sprintf('%s $%s', self::TYPE_STRING, self::PARAM_SET_HEADER_NAMESPACE)))
- ->addChild(new PhpAnnotation(self::ANNOTATION_PARAM, sprintf('%s $%s', self::TYPE_BOOL, self::PARAM_SET_HEADER_MUSTUNDERSTAND)))
- ->addChild(new PhpAnnotation(self::ANNOTATION_PARAM, sprintf('%s|null $%s', self::TYPE_STRING, self::PARAM_SET_HEADER_ACTOR)))
- ->addChild(new PhpAnnotation(self::ANNOTATION_RETURN, $this->getModel()->getPackagedName(true)))
- ;
- }
- return $this;
- }
- }
- protected function addAnnotationBlockForgetResultMethod(PhpAnnotationBlock $annotationBlock): self
- {
- $annotationBlock
- ->addChild('Returns the result')->addChild(new PhpAnnotation(self::ANNOTATION_SEE, sprintf('%s::getResult()', $this->getModel()->getExtends(true))))
- ->addChild(new PhpAnnotation(self::ANNOTATION_RETURN, $this->getServiceReturnTypes()))
- ;
- return $this;
- }
- }
- protected function getServiceReturnTypes(): string
- {
- $returnTypes = [];
- foreach ($this->getModel()->getMethods() as $method) {
- $returnTypes[] = self::getOperationMethodReturnType($method, $this->getGenerator());
- }
- natcasesort($returnTypes);
- return implode('|', array_unique($returnTypes));
- protected function getServiceReturnTypes(): string
- {
- $returnTypes = [];
- foreach ($this->getModel()->getMethods() as $method) {
- $returnTypes[] = self::getOperationMethodReturnType($method, $this->getGenerator());
- }
- natcasesort($returnTypes);
- return implode('|', array_unique($returnTypes));
- }
- return null;
- }
- protected function getModelAttributes(): StructAttributeContainer
- {
- return $this->getModel()->getProperAttributes(true);
- }
- protected function fillClassProperties(PropertyContainer $properties): void
- {
- /** @var StructAttributeModel $attribute */
- protected function getPropertyAnnotationBlock(PhpProperty $property): ?PhpAnnotationBlock
- {
- $annotationBlock = new PhpAnnotationBlock();
- $annotationBlock->addChild(sprintf('The %s', $property->getName()));
- $attribute = $this->getModel()->getAttribute($property->getName());
- if (!$attribute instanceof StructAttributeModel) {
- $attribute = $this->getModel()->getAttributeByCleanName($property->getName());
- }
- if ($attribute instanceof StructAttributeModel) {
- $this->defineModelAnnotationsFromWsdl($annotationBlock, $attribute);
- {
- $annotationBlock = new PhpAnnotationBlock();
- $annotationBlock->addChild(sprintf('The %s', $property->getName()));
- $attribute = $this->getModel()->getAttribute($property->getName());
- if (!$attribute instanceof StructAttributeModel) {
- $attribute = $this->getModel()->getAttributeByCleanName($property->getName());
- }
- if ($attribute instanceof StructAttributeModel) {
- $this->defineModelAnnotationsFromWsdl($annotationBlock, $attribute);
- $annotationBlock->addChild(new PhpAnnotation(self::ANNOTATION_VAR, $this->getStructAttributeTypeGetAnnotation($attribute)));
- }
- $count = $this->getModelAttributes()->count();
- foreach ($this->getModelAttributes() as $index => $attribute) {
- if (0 === $index) {
- $method->addChild('$this');
- }
- $this->addStructMethodConstructBodyForAttribute($method, $attribute, $count - 1 === $index);
- }
- return $this;
- }
- protected function getStructMethodParametersValues(): array
- {
- $parametersValues = [];
- foreach ($this->getModelAttributes() as $attribute) {
- $parametersValues[] = $this->getStructMethodParameter($attribute);
- }
- return $parametersValues;
- }
- $attribute->isRequired() && !$attribute->isAChoice() ? AssignedValueElementInterface::NO_VALUE : (str_contains($type ?? '', '?') ? $defaultValue ?? null : $defaultValue),
- $type,
- $attribute
- );
- } catch (\InvalidArgumentException $exception) {
- throw new \InvalidArgumentException(sprintf('Unable to create function parameter for struct "%s" with type "%s" for attribute "%s"', $this->getModel()->getName(), var_export($this->getStructAttributeTypeAsPhpType($attribute), true), $attribute->getName()), __LINE__, $exception);
- }
- }
- protected function addStructMethodsSetAndGet(): self
- {
- $attribute->isRequired() && !$attribute->isAChoice() ? AssignedValueElementInterface::NO_VALUE : (str_contains($type ?? '', '?') ? $defaultValue ?? null : $defaultValue),
- $type,
- $attribute
- );
- } catch (\InvalidArgumentException $exception) {
- throw new \InvalidArgumentException(sprintf('Unable to create function parameter for struct "%s" with type "%s" for attribute "%s"', $this->getModel()->getName(), var_export($this->getStructAttributeTypeAsPhpType($attribute), true), $attribute->getName()), __LINE__, $exception);
- }
- }
- protected function addStructMethodsSetAndGet(): self
- {
- $attribute->isRequired() && !$attribute->isAChoice() ? AssignedValueElementInterface::NO_VALUE : (str_contains($type ?? '', '?') ? $defaultValue ?? null : $defaultValue),
- $type,
- $attribute
- );
- } catch (\InvalidArgumentException $exception) {
- throw new \InvalidArgumentException(sprintf('Unable to create function parameter for struct "%s" with type "%s" for attribute "%s"', $this->getModel()->getName(), var_export($this->getStructAttributeTypeAsPhpType($attribute), true), $attribute->getName()), __LINE__, $exception);
- }
- }
- protected function addStructMethodsSetAndGet(): self
- {
- protected function addStructMethodsSetAndGet(): self
- {
- foreach ($this->getModelAttributes() as $attribute) {
- $this
- ->addStructMethodGet($attribute)
- ->addStructMethodSet($attribute)
- ->addStructMethodAddTo($attribute)
- ;
- }
- protected function addStructMethodsSetAndGet(): self
- {
- foreach ($this->getModelAttributes() as $attribute) {
- $this
- ->addStructMethodGet($attribute)
- ->addStructMethodSet($attribute)
- ->addStructMethodAddTo($attribute)
- ;
- }
- return $this;
- {
- foreach ($this->getModelAttributes() as $attribute) {
- $this
- ->addStructMethodGet($attribute)
- ->addStructMethodSet($attribute)
- ->addStructMethodAddTo($attribute)
- ;
- }
- return $this;
- }
- $this->applyRules($method, $attribute, 'item', true);
- if ($attribute->nameIsClean()) {
- $assignment = sprintf('$this->%s[] = $item;', $attribute->getCleanName());
- } else {
- $assignment = sprintf('$this->%s[] = $this->{\'%s\'}[] = $item;', $attribute->getCleanName(), addslashes($attribute->getName()));
- }
- $method
- ->addChild($assignment)
- ->addChild('')
- protected function addStructMethodSetBody(PhpMethod $method, StructAttributeModel $attribute): self
- {
- $parameters = $method->getParameters();
- $parameter = array_shift($parameters);
- $parameterName = is_string($parameter) ? $parameter : $parameter->getName();
- return $this
- ->applyRules($method, $attribute, $parameterName)
- ->addStructMethodSetBodyAssignment($method, $attribute, $parameterName)
- ->addStructMethodSetBodyReturn($method)
- protected function addStructMethodSetBodyAssignment(PhpMethod $method, StructAttributeModel $attribute, string $parameterName): self
- {
- if ($attribute->getRemovableFromRequest() || $attribute->isAChoice()) {
- $method
- ->addChild(sprintf('if (is_null($%1$s) || (is_array($%1$s) && empty($%1$s))) {', $parameterName))
- ->addChild($method->getIndentedString(sprintf('unset($this->%1$s%2$s);', $attribute->getCleanName(), $attribute->nameIsClean() ? '' : sprintf(', $this->{\'%s\'}', addslashes($attribute->getName()))), 1))
- ->addChild('} else {')
- ->addChild($method->getIndentedString($this->getStructMethodSetBodyAssignment($attribute, $parameterName), 1))
- ->addChild('}')
- ;
- } else {
- $prefix = '';
- $parameterName = sprintf('($%1$s instanceof \DOMDocument) ? $%1$s->saveXML($%1$s->hasChildNodes() ? $%1$s->childNodes->item(0) : null) : $%1$s', $parameterName);
- }
- if ($attribute->nameIsClean()) {
- $assignment = sprintf('$this->%s = %s%s;', $attribute->getName(), $prefix, $parameterName);
- } else {
- $assignment = sprintf('$this->%s = $this->{\'%s\'} = %s%s;', $attribute->getCleanName(), addslashes($attribute->getName()), $prefix, $parameterName);
- }
- return $assignment;
- }
- if ($attribute->nameIsClean()) {
- $assignment = sprintf('$this->%s = %s%s;', $attribute->getName(), $prefix, $parameterName);
- } else {
- $assignment = sprintf('$this->%s = $this->{\'%s\'} = %s%s;', $attribute->getCleanName(), addslashes($attribute->getName()), $prefix, $parameterName);
- }
- return $assignment;
- }
- $attribute->getGetterName(),
- $this->getStructMethodGetParameters($attribute),
- $returnType
- );
- if ($attribute->nameIsClean()) {
- $thisAccess = sprintf('%s', $attribute->getName());
- } else {
- $thisAccess = sprintf('{\'%s\'}', addslashes($attribute->getName()));
- }
- $this->addStructMethodGetBody($method, $attribute, $thisAccess);
- $this->methods->add($method);
- $returnType
- );
- if ($attribute->nameIsClean()) {
- $thisAccess = sprintf('%s', $attribute->getName());
- } else {
- $thisAccess = sprintf('{\'%s\'}', addslashes($attribute->getName()));
- }
- $this->addStructMethodGetBody($method, $attribute, $thisAccess);
- $this->methods->add($method);
- return $this;
- }
- protected function getStructMethodConstructAnnotationBlock(): PhpAnnotationBlock
- {
- $annotationBlock = new PhpAnnotationBlock([
- sprintf('Constructor method for %s', $this->getModel()->getName()),
- ]);
- $this->addStructPropertiesToAnnotationBlock($annotationBlock);
- return $annotationBlock;
- }
- }
- protected function getStructMethodConstructAnnotationBlock(): PhpAnnotationBlock
- {
- $annotationBlock = new PhpAnnotationBlock([
- sprintf('Constructor method for %s', $this->getModel()->getName()),
- ]);
- $this->addStructPropertiesToAnnotationBlock($annotationBlock);
- return $annotationBlock;
- }
- /**
- * Since properties can be duplicated with different case, we assume that _\d+ is replaceable by an empty string as methods are "duplicated" with this suffix.
- */
- $parameterName = preg_replace('/(_\d+)/', '', $parameterName);
- $attribute = $this->getModel()->getAttribute($parameterName);
- if (!$attribute instanceof StructAttributeModel) {
- $attribute = $this->getModel()->getAttributeByCleanName($parameterName);
- }
- if (!$attribute instanceof StructAttributeModel) {
- $parameterName = lcfirst($parameterName);
- * Since properties can be duplicated with different case, we assume that _\d+ is replaceable by an empty string as methods are "duplicated" with this suffix.
- */
- $parameterName = preg_replace('/(_\d+)/', '', $parameterName);
- $attribute = $this->getModel()->getAttribute($parameterName);
- if (!$attribute instanceof StructAttributeModel) {
- $attribute = $this->getModel()->getAttributeByCleanName($parameterName);
- }
- if (!$attribute instanceof StructAttributeModel) {
- $parameterName = lcfirst($parameterName);
- $attribute = $this->getModel()->getAttribute($parameterName);
- if (!$attribute instanceof StructAttributeModel) {
- $attribute = $this->getModel()->getAttribute($parameterName);
- if (!$attribute instanceof StructAttributeModel) {
- $attribute = $this->getModel()->getAttributeByCleanName($parameterName);
- }
- if (!$attribute instanceof StructAttributeModel) {
- $parameterName = lcfirst($parameterName);
- $attribute = $this->getModel()->getAttribute($parameterName);
- if (!$attribute instanceof StructAttributeModel) {
- $attribute = $this->getModel()->getAttributeByCleanName($parameterName);
- }
- }
- if (!$attribute instanceof StructAttributeModel) {
- $attribute = $this->getModel()->getAttributeByCleanName($parameterName);
- }
- if (!$attribute instanceof StructAttributeModel) {
- $parameterName = lcfirst($parameterName);
- $attribute = $this->getModel()->getAttribute($parameterName);
- if (!$attribute instanceof StructAttributeModel) {
- $attribute = $this->getModel()->getAttributeByCleanName($parameterName);
- }
- }
- $setValueAnnotation = '%s %s value';
- }
- if (!$attribute instanceof StructAttributeModel) {
- $parameterName = lcfirst($parameterName);
- $attribute = $this->getModel()->getAttribute($parameterName);
- if (!$attribute instanceof StructAttributeModel) {
- $attribute = $this->getModel()->getAttributeByCleanName($parameterName);
- }
- }
- $setValueAnnotation = '%s %s value';
- $annotationBlock = new PhpAnnotationBlock();
- if ($attribute instanceof StructAttributeModel) {
- $annotationBlock = new PhpAnnotationBlock();
- if ($attribute instanceof StructAttributeModel) {
- $annotationBlock->addChild(sprintf($setValueAnnotation, ucfirst($setOrGet), $parameterName));
- $this->addStructMethodsSetAndGetAnnotationBlockFromStructAttribute($setOrGet, $annotationBlock, $attribute);
- } elseif (!$attribute) {
- $annotationBlock->addChild(sprintf($setValueAnnotation, ucfirst($setOrGet), lcfirst($parameterName)));
- $this->addStructMethodsSetAndGetAnnotationBlockFromScalar($setOrGet, $annotationBlock, $parameterName);
- }
- return $annotationBlock;
- }
- if ($attribute instanceof StructAttributeModel) {
- $annotationBlock->addChild(sprintf($setValueAnnotation, ucfirst($setOrGet), $parameterName));
- $this->addStructMethodsSetAndGetAnnotationBlockFromStructAttribute($setOrGet, $annotationBlock, $attribute);
- } elseif (!$attribute) {
- $annotationBlock->addChild(sprintf($setValueAnnotation, ucfirst($setOrGet), lcfirst($parameterName)));
- $this->addStructMethodsSetAndGetAnnotationBlockFromScalar($setOrGet, $annotationBlock, $parameterName);
- }
- return $annotationBlock;
- }
- protected function addStructMethodsSetAnnotationBlock(PhpAnnotationBlock $annotationBlock, string $type, string $name): self
- {
- $annotationBlock
- ->addChild(new PhpAnnotation(self::ANNOTATION_PARAM, sprintf('%s $%s', $type, $name)))
- ->addChild(new PhpAnnotation(self::ANNOTATION_RETURN, $this->getModel()->getPackagedName(true)))
- ;
- return $this;
- }
- }
- protected function addStructPropertiesToAnnotationBlockUses(PhpAnnotationBlock $annotationBlock): self
- {
- foreach ($this->getModelAttributes() as $attribute) {
- $annotationBlock->addChild(new PhpAnnotation(self::ANNOTATION_USES, sprintf('%s::%s()', $this->getModel()->getPackagedName(), $attribute->getSetterName())));
- }
- return $this;
- }
- }
- protected function addStructPropertiesToAnnotationBlockUses(PhpAnnotationBlock $annotationBlock): self
- {
- foreach ($this->getModelAttributes() as $attribute) {
- $annotationBlock->addChild(new PhpAnnotation(self::ANNOTATION_USES, sprintf('%s::%s()', $this->getModel()->getPackagedName(), $attribute->getSetterName())));
- }
- return $this;
- }
- }
- protected function addStructPropertiesToAnnotationBlockUses(PhpAnnotationBlock $annotationBlock): self
- {
- foreach ($this->getModelAttributes() as $attribute) {
- $annotationBlock->addChild(new PhpAnnotation(self::ANNOTATION_USES, sprintf('%s::%s()', $this->getModel()->getPackagedName(), $attribute->getSetterName())));
- }
- return $this;
- }
- }
- protected function addStructPropertiesToAnnotationBlockParams(PhpAnnotationBlock $annotationBlock): self
- {
- foreach ($this->getModelAttributes() as $attribute) {
- $annotationBlock->addChild(new PhpAnnotation(self::ANNOTATION_PARAM, sprintf('%s $%s', $this->getStructAttributeTypeSetAnnotation($attribute, false), lcfirst($attribute->getCleanName()))));
- }
- return $this;
- }
- }
- protected function addStructPropertiesToAnnotationBlockParams(PhpAnnotationBlock $annotationBlock): self
- {
- foreach ($this->getModelAttributes() as $attribute) {
- $annotationBlock->addChild(new PhpAnnotation(self::ANNOTATION_PARAM, sprintf('%s $%s', $this->getStructAttributeTypeSetAnnotation($attribute, false), lcfirst($attribute->getCleanName()))));
- }
- return $this;
- }
- }
- protected function addStructPropertiesToAnnotationBlockParams(PhpAnnotationBlock $annotationBlock): self
- {
- foreach ($this->getModelAttributes() as $attribute) {
- $annotationBlock->addChild(new PhpAnnotation(self::ANNOTATION_PARAM, sprintf('%s $%s', $this->getStructAttributeTypeSetAnnotation($attribute, false), lcfirst($attribute->getCleanName()))));
- }
- return $this;
- }
- {
- $methodParameters = $method->getParameters();
- /** @var PhpFunctionParameter $firstParameter */
- $firstParameter = array_shift($methodParameters);
- $attribute = $this->getModel()->getAttribute($firstParameter->getModel()->getName());
- $annotationBlock = new PhpAnnotationBlock();
- if ($attribute instanceof StructAttributeModel) {
- $model = $this->getRestrictionFromStructAttribute($attribute);
- $annotationBlock->addChild(sprintf('Add item to %s value', $attribute->getCleanName()));
- if ($model instanceof StructModel) {
- {
- $methodParameters = $method->getParameters();
- /** @var PhpFunctionParameter $firstParameter */
- $firstParameter = array_shift($methodParameters);
- $attribute = $this->getModel()->getAttribute($firstParameter->getModel()->getName());
- $annotationBlock = new PhpAnnotationBlock();
- if ($attribute instanceof StructAttributeModel) {
- $model = $this->getRestrictionFromStructAttribute($attribute);
- $annotationBlock->addChild(sprintf('Add item to %s value', $attribute->getCleanName()));
- if ($model instanceof StructModel) {
- ;
- }
- $annotationBlock
- ->addChild(new PhpAnnotation(self::ANNOTATION_THROWS, \InvalidArgumentException::class))
- ->addChild(new PhpAnnotation(self::ANNOTATION_PARAM, sprintf('%s $item', $this->getStructAttributeTypeSetAnnotation($attribute, false, true))))
- ->addChild(new PhpAnnotation(self::ANNOTATION_RETURN, $this->getModel()->getPackagedName(true)))
- ;
- }
- return $annotationBlock;
- }
- return $this->addArrayMethodGenericMethod(
- self::METHOD_GET_ATTRIBUTE_NAME,
- sprintf(
- 'return \'%s\';',
- $model
- ->getAttributes()
- ->offsetGet(0)
- ->getName()
- ),
- [],
- return $this->addArrayMethodGenericMethod(
- self::METHOD_GET_ATTRIBUTE_NAME,
- sprintf(
- 'return \'%s\';',
- $model
- ->getAttributes()
- ->offsetGet(0)
- ->getName()
- ),
- [],
- $model = $this->getModel();
- return new PhpAnnotationBlock([
- 'Returns the attribute name',
- new PhpAnnotation(self::ANNOTATION_SEE, sprintf('%s::%s()', $model->getExtends(true), self::METHOD_GET_ATTRIBUTE_NAME)),
- new PhpAnnotation(self::ANNOTATION_RETURN, sprintf('string %s', $model->getAttributes()->offsetGet(0)->getName())),
- ]);
- }
- protected function getArrayMethodCurrentAnnotationBlock(): PhpAnnotationBlock
- {
- $model = $this->getModel();
- return new PhpAnnotationBlock([
- 'Returns the attribute name',
- new PhpAnnotation(self::ANNOTATION_SEE, sprintf('%s::%s()', $model->getExtends(true), self::METHOD_GET_ATTRIBUTE_NAME)),
- new PhpAnnotation(self::ANNOTATION_RETURN, sprintf('string %s', $model->getAttributes()->offsetGet(0)->getName())),
- ]);
- }
- protected function getArrayMethodCurrentAnnotationBlock(): PhpAnnotationBlock
- {
- protected function getArrayMethodAddAnnotationBlock(): PhpAnnotationBlock
- {
- return new PhpAnnotationBlock([
- 'Add element to array',
- new PhpAnnotation(self::ANNOTATION_SEE, sprintf('%s::add()', $this->getModel()->getExtends(true))),
- new PhpAnnotation(self::ANNOTATION_THROWS, \InvalidArgumentException::class),
- new PhpAnnotation(self::ANNOTATION_PARAM, sprintf('%s $item', $this->getStructAttributeType(null, true, false))),
- new PhpAnnotation(self::ANNOTATION_RETURN, sprintf('%s', $this->getModel()->getPackagedName(true))),
- ]);
- }
- return new PhpAnnotationBlock([
- 'Add element to array',
- new PhpAnnotation(self::ANNOTATION_SEE, sprintf('%s::add()', $this->getModel()->getExtends(true))),
- new PhpAnnotation(self::ANNOTATION_THROWS, \InvalidArgumentException::class),
- new PhpAnnotation(self::ANNOTATION_PARAM, sprintf('%s $item', $this->getStructAttributeType(null, true, false))),
- new PhpAnnotation(self::ANNOTATION_RETURN, sprintf('%s', $this->getModel()->getPackagedName(true))),
- ]);
- }
- protected function getArrayMethodGenericAnnotationBlock(string $name, string $description, $param = null): PhpAnnotationBlock
- {
- protected function getArrayMethodGenericAnnotationBlock(string $name, string $description, $param = null): PhpAnnotationBlock
- {
- $annotationBlock = new PhpAnnotationBlock([
- $description,
- new PhpAnnotation(self::ANNOTATION_SEE, sprintf('%s::%s()', $this->getModel()->getExtends(true), $name)),
- ]);
- if (!empty($param)) {
- $annotationBlock->addChild(new PhpAnnotation(self::ANNOTATION_PARAM, $param));
- }
- return $annotationBlock;
- }
- protected function getArrayMethodBody(string $method, $var = ''): string
- {
- return sprintf('return parent::%s(%s);', $method, $var);
- }
- }
- protected function fillClassConstants(ConstantContainer $constants): void
- {
- /** @var StructModel $model */
- $model = $this->getModel();
- foreach ($model->getValues() as $value) {
- $constants->add(new PhpConstant($value->getCleanName(), $value->getValue()));
- }
- }
- protected function defineUseStatements(): self
- {
- protected function fillClassConstants(ConstantContainer $constants): void
- {
- /** @var StructModel $model */
- $model = $this->getModel();
- foreach ($model->getValues() as $value) {
- $constants->add(new PhpConstant($value->getCleanName(), $value->getValue()));
- }
- }
- protected function defineUseStatements(): self
- {
- }
- protected function getConstantAnnotationBlock(PhpConstant $constant): ?PhpAnnotationBlock
- {
- $block = new PhpAnnotationBlock([
- sprintf('Constant for value \'%s\'', $constant->getValue()),
- ]);
- /** @var StructModel $model */
- $model = $this->getModel();
- if (($value = $model->getValue($constant->getValue())) instanceof StructValueModel) {
- /** @var StructModel $model */
- $model = $this->getModel();
- if (($value = $model->getValue($constant->getValue())) instanceof StructValueModel) {
- $this->defineModelAnnotationsFromWsdl($block, $value);
- }
- $block->addChild(new PhpAnnotation(self::ANNOTATION_RETURN, sprintf('string \'%s\'', $constant->getValue())));
- return $block;
- }
- protected function fillClassMethods(): void
- {
- $method = new PhpMethod(self::METHOD_GET_VALID_VALUES, [], self::TYPE_ARRAY, PhpMethod::ACCESS_PUBLIC, false, true);
- $validValues = $this->getEnumMethodValues();
- $method->addChild('return [');
- foreach ($validValues as $validValue) {
- $method->addChild(sprintf('%s,', $method->getIndentedString($validValue, 1)));
- }
- $method->addChild('];');
- return $method;
- }
- $values = [];
- /** @var StructModel $model */
- $model = $this->getModel();
- foreach ($model->getValues() as $value) {
- $values[] = sprintf('self::%s', $value->getCleanName());
- }
- return $values;
- }
- $values = [];
- /** @var StructModel $model */
- $model = $this->getModel();
- foreach ($model->getValues() as $value) {
- $values[] = sprintf('self::%s', $value->getCleanName());
- }
- return $values;
- }
- }
- public function addContent(): self
- {
- foreach ($this->getGenerator()->getServices(true) as $service) {
- $serviceVariableName = lcfirst($service->getName());
- $this->addAnnotationBlockFromService($service)->addServiceDeclaration($serviceVariableName, $service)->addServiceSoapHeadersDefinitions($serviceVariableName, $service)->addContentFromService($serviceVariableName, $service);
- }
- return $this;
- }
- }
- public function addContent(): self
- {
- foreach ($this->getGenerator()->getServices(true) as $service) {
- $serviceVariableName = lcfirst($service->getName());
- $this->addAnnotationBlockFromService($service)->addServiceDeclaration($serviceVariableName, $service)->addServiceSoapHeadersDefinitions($serviceVariableName, $service)->addContentFromService($serviceVariableName, $service);
- }
- return $this;
- }
- public function addContent(): self
- {
- foreach ($this->getGenerator()->getServices(true) as $service) {
- $serviceVariableName = lcfirst($service->getName());
- $this->addAnnotationBlockFromService($service)->addServiceDeclaration($serviceVariableName, $service)->addServiceSoapHeadersDefinitions($serviceVariableName, $service)->addContentFromService($serviceVariableName, $service);
- }
- return $this;
- }
- public function addContent(): self
- {
- foreach ($this->getGenerator()->getServices(true) as $service) {
- $serviceVariableName = lcfirst($service->getName());
- $this->addAnnotationBlockFromService($service)->addServiceDeclaration($serviceVariableName, $service)->addServiceSoapHeadersDefinitions($serviceVariableName, $service)->addContentFromService($serviceVariableName, $service);
- }
- return $this;
- }
- public function addContent(): self
- {
- foreach ($this->getGenerator()->getServices(true) as $service) {
- $serviceVariableName = lcfirst($service->getName());
- $this->addAnnotationBlockFromService($service)->addServiceDeclaration($serviceVariableName, $service)->addServiceSoapHeadersDefinitions($serviceVariableName, $service)->addContentFromService($serviceVariableName, $service);
- }
- return $this;
- }
- public function addContent(): self
- {
- foreach ($this->getGenerator()->getServices(true) as $service) {
- $serviceVariableName = lcfirst($service->getName());
- $this->addAnnotationBlockFromService($service)->addServiceDeclaration($serviceVariableName, $service)->addServiceSoapHeadersDefinitions($serviceVariableName, $service)->addContentFromService($serviceVariableName, $service);
- }
- return $this;
- }
- ->addChild($block, 'In addition, the goal is to show which methods are available and the first needed parameter(s)')
- ->addChild($block, 'You have to use an associative array such as:')
- ->addChild($block, '- the key must be a constant beginning with WSDL_ from AbstractSoapClientBase class (each generated ServiceType class extends this class)')
- ->addChild($block, '- the value must be the corresponding key value (each option matches a {@link http://www.php.net/manual/en/soapclient.soapclient.php} option)')
- ->addChild($block, '$options = [')
- ->addChild($block, sprintf('%s::WSDL_URL => \'%s\',', AbstractSoapClientBase::class, $this->getGenerator()->getWsdl()->getName()))
- ->addChild($block, sprintf('%s::WSDL_TRACE => true,', AbstractSoapClientBase::class))
- ->addChild($block, sprintf('%s::WSDL_LOGIN => \'you_secret_login\',', AbstractSoapClientBase::class))
- ->addChild($block, sprintf('%s::WSDL_PASSWORD => \'you_secret_password\',', AbstractSoapClientBase::class))
- ->addChild($block, '];')
- ->addChild($block, 'etc...')
- ->addChild($block, 'In addition, the goal is to show which methods are available and the first needed parameter(s)')
- ->addChild($block, 'You have to use an associative array such as:')
- ->addChild($block, '- the key must be a constant beginning with WSDL_ from AbstractSoapClientBase class (each generated ServiceType class extends this class)')
- ->addChild($block, '- the value must be the corresponding key value (each option matches a {@link http://www.php.net/manual/en/soapclient.soapclient.php} option)')
- ->addChild($block, '$options = [')
- ->addChild($block, sprintf('%s::WSDL_URL => \'%s\',', AbstractSoapClientBase::class, $this->getGenerator()->getWsdl()->getName()))
- ->addChild($block, sprintf('%s::WSDL_TRACE => true,', AbstractSoapClientBase::class))
- ->addChild($block, sprintf('%s::WSDL_LOGIN => \'you_secret_login\',', AbstractSoapClientBase::class))
- ->addChild($block, sprintf('%s::WSDL_PASSWORD => \'you_secret_password\',', AbstractSoapClientBase::class))
- ->addChild($block, '];')
- ->addChild($block, 'etc...')
- {
- $this
- ->getFile()
- ->getMainElement()
- ->addChild('$options = [')
- ->addChild($this->getFile()->getMainElement()->getIndentedString(sprintf('WsdlToPhp\PackageBase\AbstractSoapClientBase::WSDL_URL => \'%s\',', $this->getGenerator()->getWsdl()->getName()), 1))
- ->addChild($this->getFile()->getMainElement()->getIndentedString(sprintf('WsdlToPhp\PackageBase\AbstractSoapClientBase::WSDL_CLASSMAP => %s::%s(),', $this->getGenerator()->getFiles()->getClassmapFile()->getModel()->getPackagedName(true), ClassMap::METHOD_NAME), 1))
- ->addChild('];')
- ;
- return $this;
- {
- $this
- ->getFile()
- ->getMainElement()
- ->addChild('$options = [')
- ->addChild($this->getFile()->getMainElement()->getIndentedString(sprintf('WsdlToPhp\PackageBase\AbstractSoapClientBase::WSDL_URL => \'%s\',', $this->getGenerator()->getWsdl()->getName()), 1))
- ->addChild($this->getFile()->getMainElement()->getIndentedString(sprintf('WsdlToPhp\PackageBase\AbstractSoapClientBase::WSDL_CLASSMAP => %s::%s(),', $this->getGenerator()->getFiles()->getClassmapFile()->getModel()->getPackagedName(true), ClassMap::METHOD_NAME), 1))
- ->addChild('];')
- ;
- return $this;
- $this
- ->getFile()
- ->getMainElement()
- ->addChild('$options = [')
- ->addChild($this->getFile()->getMainElement()->getIndentedString(sprintf('WsdlToPhp\PackageBase\AbstractSoapClientBase::WSDL_URL => \'%s\',', $this->getGenerator()->getWsdl()->getName()), 1))
- ->addChild($this->getFile()->getMainElement()->getIndentedString(sprintf('WsdlToPhp\PackageBase\AbstractSoapClientBase::WSDL_CLASSMAP => %s::%s(),', $this->getGenerator()->getFiles()->getClassmapFile()->getModel()->getPackagedName(true), ClassMap::METHOD_NAME), 1))
- ->addChild('];')
- ;
- return $this;
- }
- }
- protected function addAnnotationBlockFromService(ServiceModel $service): self
- {
- return $this->addAnnotationBlock([
- sprintf('Samples for %s ServiceType', $service->getName()),
- ]);
- }
- protected function addContentFromService(string $serviceVariableName, ServiceModel $service): self
- {
- }
- protected function addContentFromService(string $serviceVariableName, ServiceModel $service): self
- {
- foreach ($service->getMethods() as $method) {
- $this->addAnnotationBlockFromMethod($method)->addContentFromMethod($serviceVariableName, $method);
- }
- return $this;
- }
- }
- protected function addContentFromService(string $serviceVariableName, ServiceModel $service): self
- {
- foreach ($service->getMethods() as $method) {
- $this->addAnnotationBlockFromMethod($method)->addContentFromMethod($serviceVariableName, $method);
- }
- return $this;
- }
- protected function addServiceSoapHeadersDefinitions(string $serviceVariableName, ServiceModel $service): self
- {
- $added = [];
- foreach ($service->getMethods() as $method) {
- $added = array_merge($added, $this->addServiceSoapHeadersDefinition($serviceVariableName, $method, $added));
- }
- return $this;
- }
- if (in_array($soapHeaderName, $added, true)) {
- continue;
- }
- $addedNames[] = $soapHeaderName;
- $this->getFile()->getMainElement()->addChild(sprintf('$%s->%s%s(%s);', $serviceVariableName, Service::METHOD_SET_HEADER_PREFIX, ucfirst($soapHeaderName), $this->getMethodParameter($soapHeaderName)));
- }
- return $addedNames;
- }
- if (in_array($soapHeaderName, $added, true)) {
- continue;
- }
- $addedNames[] = $soapHeaderName;
- $this->getFile()->getMainElement()->addChild(sprintf('$%s->%s%s(%s);', $serviceVariableName, Service::METHOD_SET_HEADER_PREFIX, ucfirst($soapHeaderName), $this->getMethodParameter($soapHeaderName)));
- }
- return $addedNames;
- }
- protected function getMethodParameters(MethodModel $method): string
- {
- $parameters = [];
- if (is_array($method->getParameterType())) {
- foreach ($method->getParameterType() as $parameterName => $parameterType) {
- $parameters[] = $this->getMethodParameter($parameterType, $parameterName);
- }
- } else {
- $parameters[] = $this->getMethodParameter($method->getParameterType());
- }
- if (is_array($method->getParameterType())) {
- foreach ($method->getParameterType() as $parameterName => $parameterType) {
- $parameters[] = $this->getMethodParameter($parameterType, $parameterName);
- }
- } else {
- $parameters[] = $this->getMethodParameter($method->getParameterType());
- }
- return implode(', ', $parameters);
- }
- $method = '';
- $checkValueDomain = '';
- if (is_numeric($value)) {
- $test = '$%1$s %3$s %2$s';
- } else {
- if (false === mb_strpos($value, '-')) {
- $method = 'add';
- } else {
- $method = 'sub';
- $value = mb_substr($value, 1);
- }
- } else {
- if (false === mb_strpos($value, '-')) {
- $method = 'add';
- } else {
- $method = 'sub';
- $value = mb_substr($value, 1);
- }
- switch ($this->symbol()) {
- case self::SYMBOL_MAX_EXCLUSIVE:
- case self::SYMBOL_MAX_INCLUSIVE:
- break;
- }
- $test = 'false %5$s mb_strpos((string) $%1$s, \'-\') && ($time = (string) time()) && \DateTime::createFromFormat(\'U\', $time)->%4$s(new \DateInterval(preg_replace(\'/(.*)(\.[0-9]*S)/\', \'$1S\', str_replace(\'-\', \'\', $%1$s)))) %3$s \DateTime::createFromFormat(\'U\', $time)->%4$s(new \DateInterval(preg_replace(\'/(.*)(\.[0-9]*S)/\', \'$1S\', \'%2$s\')))';
- }
- return sprintf(($itemType ? '' : '!is_null($%1$s) && ').$test, $parameterName, $value, $this->symbol(), $method, $checkValueDomain);
- }
- final public function exceptionMessageOnTestFailure(string $parameterName, $value, bool $itemType = false): string
- {
- return sprintf('sprintf(\'Invalid value %%s, the value must be %s %s %s\', var_export($%4$s, true))', is_numeric($value) ? 'numerically' : 'chronologically', $this->comparisonString(), is_array($value) ? implode(',', array_unique($value)) : $value, $parameterName);
- return sprintf(($itemType ? '' : '!is_null($%1$s) && ').$test, $parameterName, $value, $this->symbol(), $method, $checkValueDomain);
- }
- final public function exceptionMessageOnTestFailure(string $parameterName, $value, bool $itemType = false): string
- {
- return sprintf('sprintf(\'Invalid value %%s, the value must be %s %s %s\', var_export($%4$s, true))', is_numeric($value) ? 'numerically' : 'chronologically', $this->comparisonString(), is_array($value) ? implode(',', array_unique($value)) : $value, $parameterName);
- }
- }
- {
- if ($itemType || !$this->getAttribute()->isArray()) {
- $test = sprintf(
- ($itemType ? '' : '!is_null($%1$s) && ').'mb_strlen((string) $%1$s) %3$s %2$d',
- $parameterName,
- $value,
- $this->symbol()
- );
- } else {
- $this->addArrayValidationMethod($parameterName, $value);
- $test = sprintf(
- {
- if ($itemType || !$this->getAttribute()->isArray()) {
- $message = sprintf(
- 'sprintf(\'Invalid length of %%s, the number of characters/octets contained by the literal must be %s %s\', mb_strlen((string) $%s))',
- $this->comparisonString(),
- is_array($value) ? implode(',', array_unique($value)) : $value,
- $parameterName
- );
- } else {
- $message = $this->getArrayErrorMessageVariableName($parameterName);
- }
- final protected function getArrayExceptionMessageOnTestFailure($value): string
- {
- return sprintf(
- 'Invalid length for value(s) %%s, the number of characters/octets contained by the literal must be %s %s',
- $this->comparisonString(),
- $value
- );
- }
- }
- {
- return sprintf(
- '// %s %s%s',
- self::VALIDATION_RULE_COMMENT_SENTENCE,
- $this->name(),
- is_array($value) ? sprintf('(%s)', implode(', ', array_unique($value))) : (empty($value) ? '' : sprintf('(%s)', $value))
- );
- }
- abstract public function name(): string;
- final protected function addArrayValidationMethod(string $parameterName, $value): void
- {
- $itemName = sprintf(
- '%s%sItem',
- lcfirst($this->getFile()->getModel()->getCleanName(false)),
- ucfirst($this->getAttribute()->getCleanName())
- );
- $method = new PhpMethod($this->getValidationMethodName($parameterName), [
- new PhpFunctionParameter('values', null, '?array'),
- ], AbstractModelFile::TYPE_STRING, PhpMethod::ACCESS_PUBLIC, false, true);
- {
- $method = new PhpMethod($this->getValidationMethodName($parameterName), [
- new PhpFunctionParameter('values', [], '?array'),
- ], AbstractModelFile::TYPE_STRING, PhpMethod::ACCESS_PUBLIC, false, true);
- $model = $this->getFile()->getRestrictionFromStructAttribute($this->getAttribute());
- $itemName = sprintf('%s%sItem', lcfirst($this->getFile()->getModel()->getCleanName(false)), ucfirst($this->getAttribute()->getCleanName()));
- $rules = clone $this->getRules();
- if ($model instanceof Struct) {
- $rule = $rules->getEnumerationRule();
- } else {
- {
- $attribute = $this->getAttribute();
- $struct = $attribute->getOwner();
- $choiceAttributes = [];
- foreach ($choiceNames as $choiceName) {
- if ($choiceName !== $attribute->getName() && $choiceAttribute = $struct->getAttribute($choiceName)) {
- $choiceAttributes[] = $choiceAttribute;
- }
- }
- $method = new PhpMethod($this->getValidationMethodName($parameterName), [
- $method
- ->addChild('];')
- ->addChild('try {')
- ->addChild($method->getIndentedString('foreach ($properties as $property) {', 1))
- ->addChild($method->getIndentedString('if (isset($this->{$property})) {', 2))
- ->addChild($method->getIndentedString(sprintf('throw new InvalidArgumentException(sprintf(\'The property %1$s can\\\'t be set as the property %%s is already set. Only one property must be set among these properties: %1$s, %%s.\', $property, implode(\', \', $properties)), __LINE__);', $attribute->getName()), 3))
- ->addChild($method->getIndentedString(sprintf('}'), 2))
- ->addChild($method->getIndentedString('}', 1))
- ->addChild('} catch (InvalidArgumentException $e) {')
- ->addChild($method->getIndentedString('$message = $e->getMessage();', 1))
- ->addChild('}')
- return 'fractionDigits';
- }
- public function testConditions(string $parameterName, $value, bool $itemType = false): string
- {
- return sprintf(($itemType ? '' : '!is_null($%1$s) && ').'mb_strlen(mb_substr((string) $%1$s, false !== mb_strpos((string) $%1$s, \'.\') ? mb_strpos((string) $%1$s, \'.\') + 1 : mb_strlen((string) $%1$s))) > %2$d', $parameterName, $value);
- }
- public function exceptionMessageOnTestFailure(string $parameterName, $value, bool $itemType = false): string
- {
- return sprintf('sprintf(\'Invalid value %%s, the value must at most contain %1$d fraction digits, %%d given\', var_export($%2$s, true), mb_strlen(mb_substr((string) $%2$s, mb_strpos((string) $%2$s, \'.\') + 1)))', $value, $parameterName);
- return sprintf(($itemType ? '' : '!is_null($%1$s) && ').'mb_strlen(mb_substr((string) $%1$s, false !== mb_strpos((string) $%1$s, \'.\') ? mb_strpos((string) $%1$s, \'.\') + 1 : mb_strlen((string) $%1$s))) > %2$d', $parameterName, $value);
- }
- public function exceptionMessageOnTestFailure(string $parameterName, $value, bool $itemType = false): string
- {
- return sprintf('sprintf(\'Invalid value %%s, the value must at most contain %1$d fraction digits, %%d given\', var_export($%2$s, true), mb_strlen(mb_substr((string) $%2$s, mb_strpos((string) $%2$s, \'.\') + 1)))', $value, $parameterName);
- }
- }
- $symbol = self::SYMBOL_MAX_EXCLUSIVE;
- } else {
- $test = 'is_array($%4$s) && count($%4$s) %3$s %2$d';
- $symbol = $this->symbol();
- }
- $test = sprintf($test, $this->getAttribute()->getCleanName(), $value, $symbol, $parameterName);
- }
- return $test;
- }
- $message = 'sprintf(\'You can\\\'t add anymore element to this property that already contains %%s elements, the number of elements contained by the property must be %1$s %2$s\', count($this->%4$s))';
- } else {
- $message = 'sprintf(\'Invalid count of %%s, the number of elements contained by the property must be %1$s %2$s\', count($%3$s))';
- }
- return sprintf($message, $this->comparisonString(), is_array($value) ? implode(',', array_unique($value)) : $value, $parameterName, $this->getAttribute()->getCleanName());
- }
- }
- array_map(
- static fn ($value): string => addcslashes($value, '\'\/'),
- array_map(
- static fn ($value): string => empty($value) ? '^$' : $value,
- array_map(
- 'trim',
- array_filter(
- is_array($value) ? $value : [$value],
- static fn ($value): bool => !in_array($value, ['true', 'false', true, false], true)
- )
- )
- return 'totalDigits';
- }
- public function testConditions(string $parameterName, $value, bool $itemType = false): string
- {
- return sprintf(($itemType ? '' : '!is_null($%1$s) && ').'mb_strlen(preg_replace(\'/(\D)/\', \'\', (string) $%1$s)) > %2$d', $parameterName, $value);
- }
- public function exceptionMessageOnTestFailure(string $parameterName, $value, bool $itemType = false): string
- {
- return sprintf('sprintf(\'Invalid value %%s, the value must use at most %1$d digits, "%%d" given\', var_export($%2$s, true), mb_strlen(preg_replace(\'/(\D)/\', \'\', (string) $%2$s)))', $value, $parameterName);
- return sprintf(($itemType ? '' : '!is_null($%1$s) && ').'mb_strlen(preg_replace(\'/(\D)/\', \'\', (string) $%1$s)) > %2$d', $parameterName, $value);
- }
- public function exceptionMessageOnTestFailure(string $parameterName, $value, bool $itemType = false): string
- {
- return sprintf('sprintf(\'Invalid value %%s, the value must use at most %1$d digits, "%%d" given\', var_export($%2$s, true), mb_strlen(preg_replace(\'/(\D)/\', \'\', (string) $%2$s)))', $value, $parameterName);
- }
- }
- if (!in_array($validationRules, $existingValidationRules)) {
- foreach ($validationRules as $validationRuleIndex => $validationRule) {
- // avoid having a validation rule that has already been applied to the attribute within the method which is calling the validate method
- if (0 === $validationRuleIndex) {
- $ruleParts = [];
- preg_match(sprintf('/%s\s(\w*)(.*)?/', self::VALIDATION_RULE_COMMENT_SENTENCE), $validationRule, $ruleParts);
- if (3 === count($ruleParts) && !empty($ruleParts[1]) && $rules->getRule($ruleParts[1]) instanceof AbstractRule && Rules::hasRuleBeenAppliedToAttribute($rules->getRule($ruleParts[1]), $ruleParts[2], $this->getAttribute())) {
- continue 2;
- }
- }
- * @param mixed $arguments
- * @throws \BadMethodCallException
- */
- public function __call($name, $arguments)
- {
- if (($prefix = 'getOption') === substr($name, 0, $length = strlen($prefix)) && empty($arguments)) {
- $getMethod = 'get'.substr($name, $length);
- return $this->options->{$getMethod}();
- }
- if (($prefix = 'setOption') === substr($name, 0, $length = strlen($prefix)) && 1 === (is_countable($arguments) ? count($arguments) : 0)) {
- * @throws \BadMethodCallException
- */
- public function __call($name, $arguments)
- {
- if (($prefix = 'getOption') === substr($name, 0, $length = strlen($prefix)) && empty($arguments)) {
- $getMethod = 'get'.substr($name, $length);
- return $this->options->{$getMethod}();
- }
- if (($prefix = 'setOption') === substr($name, 0, $length = strlen($prefix)) && 1 === (is_countable($arguments) ? count($arguments) : 0)) {
- $setMethod = 'set'.substr($name, $length);
- if (($prefix = 'getOption') === substr($name, 0, $length = strlen($prefix)) && empty($arguments)) {
- $getMethod = 'get'.substr($name, $length);
- return $this->options->{$getMethod}();
- }
- if (($prefix = 'setOption') === substr($name, 0, $length = strlen($prefix)) && 1 === (is_countable($arguments) ? count($arguments) : 0)) {
- $setMethod = 'set'.substr($name, $length);
- $this->options->{$setMethod}(array_shift($arguments));
- return $this;
- }
- $getMethod = 'get'.substr($name, $length);
- return $this->options->{$getMethod}();
- }
- if (($prefix = 'setOption') === substr($name, 0, $length = strlen($prefix)) && 1 === (is_countable($arguments) ? count($arguments) : 0)) {
- $setMethod = 'set'.substr($name, $length);
- $this->options->{$setMethod}(array_shift($arguments));
- return $this;
- }
- return $this->options->{$getMethod}();
- }
- if (($prefix = 'setOption') === substr($name, 0, $length = strlen($prefix)) && 1 === (is_countable($arguments) ? count($arguments) : 0)) {
- $setMethod = 'set'.substr($name, $length);
- $this->options->{$setMethod}(array_shift($arguments));
- return $this;
- }
- throw new \BadMethodCallException(sprintf('Method %s is undefined', $name));
- $this->options->{$setMethod}(array_shift($arguments));
- return $this;
- }
- throw new \BadMethodCallException(sprintf('Method %s is undefined', $name));
- }
- public function getParsers(): GeneratorParsers
- {
- return $this->parsers;
- $services = $this->containers->getServices();
- if ($usingGatherMethods && GeneratorOptions::VALUE_NONE === $this->getOptionGatherMethods()) {
- $serviceContainer = new ServiceContainer($this);
- $serviceModel = new Service($this, Service::DEFAULT_SERVICE_CLASS_NAME);
- foreach ($services as $service) {
- foreach ($service->getMethods() as $method) {
- $serviceModel->getMethods()->add($method);
- }
- }
- $serviceContainer->add($serviceModel);
- $services = $serviceContainer;
- if ($usingGatherMethods && GeneratorOptions::VALUE_NONE === $this->getOptionGatherMethods()) {
- $serviceContainer = new ServiceContainer($this);
- $serviceModel = new Service($this, Service::DEFAULT_SERVICE_CLASS_NAME);
- foreach ($services as $service) {
- foreach ($service->getMethods() as $method) {
- $serviceModel->getMethods()->add($method);
- }
- }
- $serviceContainer->add($serviceModel);
- $services = $serviceContainer;
- }
- return $this;
- }
- public function getOptionPrefix(bool $ucFirst = true): string
- {
- return $ucFirst ? ucfirst($this->getOptions()->getPrefix()) : $this->getOptions()->getPrefix();
- }
- public function getOptionSuffix(bool $ucFirst = true): string
- {
- return $ucFirst ? ucfirst($this->getOptions()->getSuffix()) : $this->getOptions()->getSuffix();
- return $ucFirst ? ucfirst($this->getOptions()->getPrefix()) : $this->getOptions()->getPrefix();
- }
- public function getOptionSuffix(bool $ucFirst = true): string
- {
- return $ucFirst ? ucfirst($this->getOptions()->getSuffix()) : $this->getOptions()->getSuffix();
- }
- public function setOptionOrigin(string $optionOrigin): self
- {
- $this->options->setOrigin($optionOrigin);
- $decodedJson = json_decode($json, true);
- if (JSON_ERROR_NONE === json_last_error()) {
- // load options first
- $options = GeneratorOptions::instance();
- foreach ($decodedJson['options'] as $name => $value) {
- $options->setOptionValue($name, $value);
- }
- // create generator instance with options
- $instance = new self($options);
- // load services
- foreach ($decodedJson['containers']['services'] as $service) {
- }
- // create generator instance with options
- $instance = new self($options);
- // load services
- foreach ($decodedJson['containers']['services'] as $service) {
- $instance->getContainers()->getServices()->add(self::getModelInstanceFromJsonArrayEntry($instance, $service));
- }
- // load structs
- foreach ($decodedJson['containers']['structs'] as $struct) {
- $instance->getContainers()->getStructs()->add(self::getModelInstanceFromJsonArrayEntry($instance, $struct));
- }
- foreach ($decodedJson['containers']['services'] as $service) {
- $instance->getContainers()->getServices()->add(self::getModelInstanceFromJsonArrayEntry($instance, $service));
- }
- // load structs
- foreach ($decodedJson['containers']['structs'] as $struct) {
- $instance->getContainers()->getStructs()->add(self::getModelInstanceFromJsonArrayEntry($instance, $struct));
- }
- } else {
- throw new \InvalidArgumentException(sprintf('Json is invalid, please check error %s', json_last_error()));
- }
- foreach ($decodedJson['containers']['services'] as $service) {
- $instance->getContainers()->getServices()->add(self::getModelInstanceFromJsonArrayEntry($instance, $service));
- }
- // load structs
- foreach ($decodedJson['containers']['structs'] as $struct) {
- $instance->getContainers()->getStructs()->add(self::getModelInstanceFromJsonArrayEntry($instance, $struct));
- }
- } else {
- throw new \InvalidArgumentException(sprintf('Json is invalid, please check error %s', json_last_error()));
- }
- /**
- * @throws \InvalidArgumentException
- */
- protected function initDirectory(): self
- {
- Utils::createDirectory($this->getOptions()->getDestination());
- if (!is_writable($this->getOptionDestination())) {
- throw new \InvalidArgumentException(sprintf('Unable to use dir "%s" as dir does not exists, its creation has been impossible or it\'s not writable', $this->getOptionDestination()), __LINE__);
- }
- return $this;
- ;
- }
- protected function generateStructsClasses(): GeneratorFiles
- {
- foreach ($this->getGenerator()->getStructs() as $struct) {
- if (!$struct->isStruct()) {
- continue;
- }
- $this
- }
- protected function generateStructsClasses(): GeneratorFiles
- {
- foreach ($this->getGenerator()->getStructs() as $struct) {
- if (!$struct->isStruct()) {
- continue;
- }
- $this
- ->getStructFile($struct)
- if (!$struct->isStruct()) {
- continue;
- }
- $this
- ->getStructFile($struct)
- ->setModel($struct)
- ->write()
- ;
- }
- continue;
- }
- $this
- ->getStructFile($struct)
- ->setModel($struct)
- ->write()
- ;
- }
- return $this;
- return $file;
- }
- protected function generateServicesClasses(): self
- {
- foreach ($this->getGenerator()->getServices(true) as $service) {
- $file = new ServiceFile($this->generator, $service->getPackagedName());
- $file->setModel($service)->write();
- }
- return $this;
- }
- protected function generateServicesClasses(): self
- {
- foreach ($this->getGenerator()->getServices(true) as $service) {
- $file = new ServiceFile($this->generator, $service->getPackagedName());
- $file->setModel($service)->write();
- }
- return $this;
- }
- protected function generateServicesClasses(): self
- {
- foreach ($this->getGenerator()->getServices(true) as $service) {
- $file = new ServiceFile($this->generator, $service->getPackagedName());
- $file->setModel($service)->write();
- }
- return $this;
- }
- }
- public function doParse(): self
- {
- foreach ($this->parsers as $parser) {
- $parser->parse();
- }
- return $this;
- }
- $soapClient = new SoapClient($this->getSoapClientOptions(\SOAP_1_1));
- } catch (\SoapFault $fault) {
- try {
- $soapClient = new SoapClient($this->getSoapClientOptions(\SOAP_1_2));
- } catch (\SoapFault $fault) {
- throw new \InvalidArgumentException(sprintf('Unable to load WSDL at "%s"!', $this->getGenerator()->getOptionOrigin()), __LINE__, $fault);
- }
- }
- return $this->setSoapClient($soapClient);
- }
- public function getSoapClientOptions(int $soapVersion): array
- {
- return array_merge([
- SoapClientInterface::WSDL_SOAP_VERSION => $soapVersion,
- SoapClientInterface::WSDL_URL => $this->getGenerator()->getOptionOrigin(),
- SoapClientInterface::WSDL_LOGIN => $this->getGenerator()->getOptionBasicLogin(),
- SoapClientInterface::WSDL_PROXY_HOST => $this->getGenerator()->getOptionProxyHost(),
- SoapClientInterface::WSDL_PROXY_PORT => $this->getGenerator()->getOptionProxyPort(),
- SoapClientInterface::WSDL_PASSWORD => $this->getGenerator()->getOptionBasicPassword(),
- SoapClientInterface::WSDL_PROXY_LOGIN => $this->getGenerator()->getOptionProxyLogin(),
- public function getSoapClientOptions(int $soapVersion): array
- {
- return array_merge([
- SoapClientInterface::WSDL_SOAP_VERSION => $soapVersion,
- SoapClientInterface::WSDL_URL => $this->getGenerator()->getOptionOrigin(),
- SoapClientInterface::WSDL_LOGIN => $this->getGenerator()->getOptionBasicLogin(),
- SoapClientInterface::WSDL_PROXY_HOST => $this->getGenerator()->getOptionProxyHost(),
- SoapClientInterface::WSDL_PROXY_PORT => $this->getGenerator()->getOptionProxyPort(),
- SoapClientInterface::WSDL_PASSWORD => $this->getGenerator()->getOptionBasicPassword(),
- SoapClientInterface::WSDL_PROXY_LOGIN => $this->getGenerator()->getOptionProxyLogin(),
- SoapClientInterface::WSDL_PROXY_PASSWORD => $this->getGenerator()->getOptionProxyPassword(),
- {
- return array_merge([
- SoapClientInterface::WSDL_SOAP_VERSION => $soapVersion,
- SoapClientInterface::WSDL_URL => $this->getGenerator()->getOptionOrigin(),
- SoapClientInterface::WSDL_LOGIN => $this->getGenerator()->getOptionBasicLogin(),
- SoapClientInterface::WSDL_PROXY_HOST => $this->getGenerator()->getOptionProxyHost(),
- SoapClientInterface::WSDL_PROXY_PORT => $this->getGenerator()->getOptionProxyPort(),
- SoapClientInterface::WSDL_PASSWORD => $this->getGenerator()->getOptionBasicPassword(),
- SoapClientInterface::WSDL_PROXY_LOGIN => $this->getGenerator()->getOptionProxyLogin(),
- SoapClientInterface::WSDL_PROXY_PASSWORD => $this->getGenerator()->getOptionProxyPassword(),
- ], $this->getGenerator()->getOptionSoapOptions());
- return array_merge([
- SoapClientInterface::WSDL_SOAP_VERSION => $soapVersion,
- SoapClientInterface::WSDL_URL => $this->getGenerator()->getOptionOrigin(),
- SoapClientInterface::WSDL_LOGIN => $this->getGenerator()->getOptionBasicLogin(),
- SoapClientInterface::WSDL_PROXY_HOST => $this->getGenerator()->getOptionProxyHost(),
- SoapClientInterface::WSDL_PROXY_PORT => $this->getGenerator()->getOptionProxyPort(),
- SoapClientInterface::WSDL_PASSWORD => $this->getGenerator()->getOptionBasicPassword(),
- SoapClientInterface::WSDL_PROXY_LOGIN => $this->getGenerator()->getOptionProxyLogin(),
- SoapClientInterface::WSDL_PROXY_PASSWORD => $this->getGenerator()->getOptionProxyPassword(),
- ], $this->getGenerator()->getOptionSoapOptions());
- }
- SoapClientInterface::WSDL_SOAP_VERSION => $soapVersion,
- SoapClientInterface::WSDL_URL => $this->getGenerator()->getOptionOrigin(),
- SoapClientInterface::WSDL_LOGIN => $this->getGenerator()->getOptionBasicLogin(),
- SoapClientInterface::WSDL_PROXY_HOST => $this->getGenerator()->getOptionProxyHost(),
- SoapClientInterface::WSDL_PROXY_PORT => $this->getGenerator()->getOptionProxyPort(),
- SoapClientInterface::WSDL_PASSWORD => $this->getGenerator()->getOptionBasicPassword(),
- SoapClientInterface::WSDL_PROXY_LOGIN => $this->getGenerator()->getOptionProxyLogin(),
- SoapClientInterface::WSDL_PROXY_PASSWORD => $this->getGenerator()->getOptionProxyPassword(),
- ], $this->getGenerator()->getOptionSoapOptions());
- }
- SoapClientInterface::WSDL_URL => $this->getGenerator()->getOptionOrigin(),
- SoapClientInterface::WSDL_LOGIN => $this->getGenerator()->getOptionBasicLogin(),
- SoapClientInterface::WSDL_PROXY_HOST => $this->getGenerator()->getOptionProxyHost(),
- SoapClientInterface::WSDL_PROXY_PORT => $this->getGenerator()->getOptionProxyPort(),
- SoapClientInterface::WSDL_PASSWORD => $this->getGenerator()->getOptionBasicPassword(),
- SoapClientInterface::WSDL_PROXY_LOGIN => $this->getGenerator()->getOptionProxyLogin(),
- SoapClientInterface::WSDL_PROXY_PASSWORD => $this->getGenerator()->getOptionProxyPassword(),
- ], $this->getGenerator()->getOptionSoapOptions());
- }
- public function setSoapClient(SoapClient $soapClient): self
- SoapClientInterface::WSDL_LOGIN => $this->getGenerator()->getOptionBasicLogin(),
- SoapClientInterface::WSDL_PROXY_HOST => $this->getGenerator()->getOptionProxyHost(),
- SoapClientInterface::WSDL_PROXY_PORT => $this->getGenerator()->getOptionProxyPort(),
- SoapClientInterface::WSDL_PASSWORD => $this->getGenerator()->getOptionBasicPassword(),
- SoapClientInterface::WSDL_PROXY_LOGIN => $this->getGenerator()->getOptionProxyLogin(),
- SoapClientInterface::WSDL_PROXY_PASSWORD => $this->getGenerator()->getOptionProxyPassword(),
- ], $this->getGenerator()->getOptionSoapOptions());
- }
- public function setSoapClient(SoapClient $soapClient): self
- {
- SoapClientInterface::WSDL_PROXY_HOST => $this->getGenerator()->getOptionProxyHost(),
- SoapClientInterface::WSDL_PROXY_PORT => $this->getGenerator()->getOptionProxyPort(),
- SoapClientInterface::WSDL_PASSWORD => $this->getGenerator()->getOptionBasicPassword(),
- SoapClientInterface::WSDL_PROXY_LOGIN => $this->getGenerator()->getOptionProxyLogin(),
- SoapClientInterface::WSDL_PROXY_PASSWORD => $this->getGenerator()->getOptionProxyPassword(),
- ], $this->getGenerator()->getOptionSoapOptions());
- }
- public function setSoapClient(SoapClient $soapClient): self
- {
- $this->soapClient = $soapClient;
- switch ($optionValue) {
- case GeneratorOptions::VALUE_END:
- $parts = preg_split('/[A-Z]/', ucfirst($string));
- $partsCount = is_countable($parts) ? count($parts) : 0;
- if (!empty($parts[$partsCount - 1])) {
- $elementType = mb_substr($string, mb_strrpos($string, implode('', array_slice($parts, -1))) - 1);
- } else {
- for ($i = $partsCount - 1; $i >= 0; --$i) {
- $part = trim($parts[$i]);
- if (!empty($part)) {
- break;
- switch ($optionValue) {
- case GeneratorOptions::VALUE_END:
- $parts = preg_split('/[A-Z]/', ucfirst($string));
- $partsCount = is_countable($parts) ? count($parts) : 0;
- if (!empty($parts[$partsCount - 1])) {
- $elementType = mb_substr($string, mb_strrpos($string, implode('', array_slice($parts, -1))) - 1);
- } else {
- for ($i = $partsCount - 1; $i >= 0; --$i) {
- $part = trim($parts[$i]);
- if (!empty($part)) {
- break;
- }
- public static function getStreamContextOptions(?string $basicAuthLogin = null, ?string $basicAuthPassword = null, ?string $proxyHost = null, $proxyPort = null, ?string $proxyLogin = null, ?string $proxyPassword = null, array $contextOptions = []): array
- {
- $applyHttpHeader = function (array $contextOptions, string $header): array {
- if (!isset($contextOptions['http']['header']) || !in_array($header, $contextOptions['http']['header'])) {
- $contextOptions['http']['header'][] = $header;
- }
- return $contextOptions;
- };
- $authorizationHeader = sprintf('Authorization: Basic %s', base64_encode(sprintf('%s:%s', $basicAuthLogin, $basicAuthPassword)));
- $contextOptions = $applyHttpHeader($contextOptions, $authorizationHeader);
- }
- if (!empty($proxyHost)) {
- $contextOptions['http']['proxy'] = sprintf('tcp://%s%s', $proxyHost, empty($proxyPort) ? '' : sprintf(':%s', $proxyPort));
- $proxyAuthorizationHeader = sprintf('Proxy-Authorization: Basic %s', base64_encode(sprintf('%s:%s', $proxyLogin, $proxyPassword)));
- $contextOptions = $applyHttpHeader($contextOptions, $proxyAuthorizationHeader);
- }
- return $contextOptions;
- $path = str_replace('/'.$fileBasename, '', $path);
- $pathParts = explode('/', $path);
- $finalPath = implode('/', $pathParts);
- foreach ($destinationParts as $locationPart) {
- if ('..' === $locationPart) {
- $finalPath = mb_substr($finalPath, 0, mb_strrpos($finalPath, '/', 0));
- } else {
- $finalPath .= '/'.$locationPart;
- }
- }
- $port = (is_array($parts) && array_key_exists('port', $parts)) ? $parts['port'] : '';
- */
- public static function cleanString(string $string, bool $keepMultipleUnderscores = true): string
- {
- $cleanedString = preg_replace('/[^\p{L}\p{N}_]/u', '_', $string);
- if (!$keepMultipleUnderscores) {
- $cleanedString = preg_replace('/[_]+/', '_', $cleanedString);
- }
- return $cleanedString;
- }
- }
- public static function createDirectory(string $directory, $permissions = 0775): bool
- {
- if (!is_dir($directory)) {
- mkdir($directory, $permissions, true);
- }
- return true;
- }
- try {
- $domDocument->loadXML($content, LIBXML_NOERROR);
- $this->content = new $contentClass($domDocument, $this->generator);
- } catch (\Exception $exception) {
- throw new \InvalidArgumentException(sprintf('Unable to load document at "%s"', $this->getName()), __LINE__, $exception);
- }
- return $this;
- }
- return $this;
- }
- public function getInheritedModel(): ?Struct
- {
- return $this->getGenerator()->getStructByName($this->getInheritance());
- }
- public function getMeta(): array
- {
- return $this->meta;
- public function getMetaValueFirstSet(array $names, $fallback = null)
- {
- $meta = $this->getMeta();
- foreach ($names as $name) {
- if (array_key_exists($name, $meta)) {
- return $meta[$name];
- }
- }
- return $fallback;
- return $this;
- }
- public function getCleanName(bool $keepMultipleUnderscores = true): string
- {
- return self::cleanString($this->getName(), $keepMultipleUnderscores);
- }
- public function getOwner(): ?AbstractModel
- {
- return $this->owner;
- if ($namespaced && !empty($this->getNamespace())) {
- $nameParts[] = sprintf('\%s\\', $this->getNamespace());
- }
- $cleanName = $this->getCleanName();
- if (!empty($this->getGenerator()->getOptionPrefix())) {
- $nameParts[] = $this->getGenerator()->getOptionPrefix();
- } else {
- $cleanName = self::replacePhpReservedKeyword($cleanName);
- }
- $nameParts[] = sprintf('\%s\\', $this->getNamespace());
- }
- $cleanName = $this->getCleanName();
- if (!empty($this->getGenerator()->getOptionPrefix())) {
- $nameParts[] = $this->getGenerator()->getOptionPrefix();
- } else {
- $cleanName = self::replacePhpReservedKeyword($cleanName);
- }
- $nameParts[] = ucfirst(self::uniqueName($cleanName, $this->getContextualPart()));
- } else {
- $cleanName = self::replacePhpReservedKeyword($cleanName);
- }
- $nameParts[] = ucfirst(self::uniqueName($cleanName, $this->getContextualPart()));
- if (!empty($this->getGenerator()->getOptionSuffix())) {
- $nameParts[] = $this->getGenerator()->getOptionSuffix();
- }
- return implode('', $nameParts);
- }
- $cleanName = self::replacePhpReservedKeyword($cleanName);
- }
- $nameParts[] = ucfirst(self::uniqueName($cleanName, $this->getContextualPart()));
- if (!empty($this->getGenerator()->getOptionSuffix())) {
- $nameParts[] = $this->getGenerator()->getOptionSuffix();
- }
- return implode('', $nameParts);
- }
- }
- public function getNamespace(): string
- {
- $namespaces = [];
- $namespace = $this->getGenerator()->getOptionNamespacePrefix();
- if (!empty($namespace)) {
- $namespaces[] = $namespace;
- }
- }
- public function getSubDirectory(): string
- {
- $subDirectory = '';
- if (GeneratorOptions::VALUE_CAT === $this->getGenerator()->getOptionCategory()) {
- $subDirectory = $this->getContextualPart();
- }
- return $subDirectory;
- }
- $metaDocumentation = [];
- // gather meta
- foreach ($meta as $metaItem) {
- foreach ($metaItem as $metaName => $metaValue) {
- if (self::META_DOCUMENTATION === $metaName) {
- $metaDocumentation = array_merge($metaDocumentation, $metaValue);
- } elseif (!array_key_exists($metaName, $mergedMeta)) {
- $mergedMeta[$metaName] = $metaValue;
- } elseif (is_array($mergedMeta[$metaName]) && is_array($metaValue)) {
- $mergedMeta[$metaName] = array_merge($mergedMeta[$metaName], $metaValue);
- } elseif (is_array($mergedMeta[$metaName])) {
- // gather meta
- foreach ($meta as $metaItem) {
- foreach ($metaItem as $metaName => $metaValue) {
- if (self::META_DOCUMENTATION === $metaName) {
- $metaDocumentation = array_merge($metaDocumentation, $metaValue);
- } elseif (!array_key_exists($metaName, $mergedMeta)) {
- $mergedMeta[$metaName] = $metaValue;
- } elseif (is_array($mergedMeta[$metaName]) && is_array($metaValue)) {
- $mergedMeta[$metaName] = array_merge($mergedMeta[$metaName], $metaValue);
- } elseif (is_array($mergedMeta[$metaName])) {
- $mergedMeta[$metaName][] = $metaValue;
- {
- if (!array_key_exists('__CLASS__', $args)) {
- throw new \InvalidArgumentException(sprintf('__CLASS__ key is missing from "%s"', var_export($args, true)));
- }
- if (!class_exists($args['__CLASS__'])) {
- throw new \InvalidArgumentException(sprintf('Class "%s" is unknown', $args['__CLASS__']));
- }
- if (!array_key_exists('name', $args)) {
- throw new \InvalidArgumentException(sprintf('name key is missing from "%s"', var_export($args, true)));
- if (!array_key_exists('__CLASS__', $args)) {
- throw new \InvalidArgumentException(sprintf('__CLASS__ key is missing from "%s"', var_export($args, true)));
- }
- if (!class_exists($args['__CLASS__'])) {
- throw new \InvalidArgumentException(sprintf('Class "%s" is unknown', $args['__CLASS__']));
- }
- if (!array_key_exists('name', $args)) {
- throw new \InvalidArgumentException(sprintf('name key is missing from "%s"', var_export($args, true)));
- }
- $this->setMethods(new MethodContainer($generator));
- }
- public function getContextualPart(): string
- {
- return $this->getGenerator()->getOptionServicesFolder();
- }
- public function getDocSubPackages(): array
- {
- return [
- return $this->methods->getMethodByName($methodName);
- }
- public function getExtends(bool $short = false): string
- {
- $extends = $this->getGenerator()->getOptionSoapClientClass();
- return $short ? Utils::removeNamespace($extends) : $extends;
- }
- public function getReservedMethodsInstance(?string $filename = null): ServiceReservedMethod
- }
- public function setMethodsFromSerializedJson(array $methods): void
- {
- foreach ($methods as $method) {
- $this->methods->add(self::instanceFromSerializedJson($this->generator, $method)->setOwner($this));
- }
- }
- protected function setMethods(MethodContainer $methodContainer): self
- {
- public function __construct(Generator $generator, $name, $isStruct = true, $isRestriction = false)
- {
- parent::__construct($generator, $name);
- $this
- ->setStruct($isStruct)
- ->setRestriction($isRestriction)
- ->setAttributes(new StructAttributeContainer($generator))
- ->setValues(new StructValueContainer($generator))
- ;
- }
- ;
- }
- public function getContextualPart(): string
- {
- $part = $this->getGenerator()->getOptionStructsFolder();
- if ($this->isRestriction()) {
- $part = $this->getGenerator()->getOptionEnumsFolder();
- } elseif ($this->isArray()) {
- $part = $this->getGenerator()->getOptionArraysFolder();
- }
- public function getContextualPart(): string
- {
- $part = $this->getGenerator()->getOptionStructsFolder();
- if ($this->isRestriction()) {
- $part = $this->getGenerator()->getOptionEnumsFolder();
- } elseif ($this->isArray()) {
- $part = $this->getGenerator()->getOptionArraysFolder();
- }
- return $part;
- {
- $part = $this->getGenerator()->getOptionStructsFolder();
- if ($this->isRestriction()) {
- $part = $this->getGenerator()->getOptionEnumsFolder();
- } elseif ($this->isArray()) {
- $part = $this->getGenerator()->getOptionArraysFolder();
- }
- return $part;
- }
- (
- (
- ($this->isStruct() && 1 === $this->countAllAttributes())
- || (!$this->isStruct() && 1 >= $this->countOwnAttributes())
- )
- && false !== mb_stripos($this->getName(), 'array')
- )
- || (!$this->isStruct() && false !== $this->getMetaValueFirstSet(['arraytype', 'arrayType'], false));
- }
- public function getAttributes(bool $includeInheritanceAttributes = false, bool $requiredFirst = false): StructAttributeContainer
- $parentAttributes = new StructAttributeContainer($this->getGenerator());
- if (!empty($this->getInheritance()) && ($model = $this->getInheritanceStruct()) instanceof Struct) {
- while ($model instanceof Struct && $model->isStruct()) {
- foreach ($model->getAttributes() as $attribute) {
- $parentAttributes->add($attribute);
- }
- $model = $model->getInheritanceStruct();
- }
- }
- }
- }
- /** @var StructAttribute $attribute */
- foreach ($this->getAttributes() as $attribute) {
- if ($parentAttributes->getStructAttributeByName($attribute->getName())) {
- continue;
- }
- $properAttributes->add($attribute);
- }
- * @throws \InvalidArgumentException
- */
- public function addAttribute(string $attributeName, string $attributeType): self
- {
- if (empty($attributeName) || empty($attributeType)) {
- throw new \InvalidArgumentException(sprintf('Attribute name "%s" and/or attribute type "%s" is invalid for Struct "%s"', $attributeName, $attributeType, $this->getName()), __LINE__);
- }
- if (is_null($this->attributes->getStructAttributeByName($attributeName))) {
- $structAttribute = new StructAttribute($this->getGenerator(), $attributeName, $attributeType, $this);
- $this->attributes->add($structAttribute);
- }
- // this is why enumerations has to be parsed before any other elements by the WSDL parsers
- if (0 < $this->countOwnAttributes()) {
- $enum = new Struct($this->getGenerator(), $this->getName(), true, true);
- $enum->setInheritance(self::DEFAULT_ENUM_TYPE);
- $enum->getValues()->add(new StructValue($enum->getGenerator(), $value, $enum->getValues()->count(), $enum));
- $this->getGenerator()->getStructs()->add($enum);
- return $enum;
- }
- $this
- ->setStruct(true)
- }
- public function getExtends(bool $short = false): string
- {
- if ($this->isArray()) {
- $extends = $this->getGenerator()->getOptionStructArrayClass();
- } elseif ($this->isRestriction()) {
- $extends = $this->getGenerator()->getOptionStructEnumClass();
- } else {
- $extends = $this->getGenerator()->getOptionStructClass();
- }
- public function getExtends(bool $short = false): string
- {
- if ($this->isArray()) {
- $extends = $this->getGenerator()->getOptionStructArrayClass();
- } elseif ($this->isRestriction()) {
- $extends = $this->getGenerator()->getOptionStructEnumClass();
- } else {
- $extends = $this->getGenerator()->getOptionStructClass();
- }
- return $short ? Utils::removeNamespace($extends) : $extends;
- if ($this->isArray()) {
- $extends = $this->getGenerator()->getOptionStructArrayClass();
- } elseif ($this->isRestriction()) {
- $extends = $this->getGenerator()->getOptionStructEnumClass();
- } else {
- $extends = $this->getGenerator()->getOptionStructClass();
- }
- return $short ? Utils::removeNamespace($extends) : $extends;
- }
- return $short ? Utils::removeNamespace($extends) : $extends;
- }
- public function getInheritanceStruct(): ?Struct
- {
- return $this->getName() === $this->getInheritance() ? null : $this->getGenerator()->getStructByName(str_replace('[]', '', $this->getInheritance()));
- }
- public function getTopInheritance(): string
- {
- $inheritance = $this->getInheritance();
- }
- public function setAttributesFromSerializedJson(array $attributes): void
- {
- foreach ($attributes as $attribute) {
- $this->attributes->add(self::instanceFromSerializedJson($this->generator, $attribute)->setOwner($this));
- }
- }
- public function setValuesFromSerializedJson(array $values): void
- {
- }
- public function setValuesFromSerializedJson(array $values): void
- {
- foreach ($values as $value) {
- $this->values->add(self::instanceFromSerializedJson($this->generator, $value)->setOwner($this));
- }
- }
- protected function getAllAttributes(bool $includeInheritanceAttributes, bool $requiredFirst): StructAttributeContainer
- {
- if ($includeInheritanceAttributes) {
- $this->addInheritanceAttributes($allAttributes);
- }
- foreach ($this->attributes as $attribute) {
- $allAttributes->add($attribute);
- }
- if ($requiredFirst) {
- $attributes = $this->putRequiredAttributesFirst($allAttributes);
- } else {
- protected function addInheritanceAttributes(StructAttributeContainer $attributes): void
- {
- if (!empty($this->getInheritance()) && ($model = $this->getInheritanceStruct()) instanceof Struct) {
- while ($model instanceof Struct && $model->isStruct()) {
- foreach ($model->getAttributes() as $attribute) {
- $attributes->add($attribute);
- }
- $model = $model->getInheritanceStruct();
- }
- }
- }
- return \DOMDocument::class === $this->getType();
- }
- public function getTypeStruct(): ?Struct
- {
- $struct = $this->getGenerator()->getStructByNameAndType($this->getType(), $this->getInheritance());
- return $struct ?: $this->getGenerator()->getStructByName($this->getType());
- }
- public function getTypeStructMeta(): array
- public function getTypeStruct(): ?Struct
- {
- $struct = $this->getGenerator()->getStructByNameAndType($this->getType(), $this->getInheritance());
- return $struct ?: $this->getGenerator()->getStructByName($this->getType());
- }
- public function getTypeStructMeta(): array
- {
- $typeStruct = $this->getTypeStruct();
- return $typeStruct && $typeStruct->isArray() && !$typeStruct->isStruct();
- }
- public function getInheritanceStruct(): ?Struct
- {
- return $this->getGenerator()->getStructByName($this->getInheritance());
- }
- public function getInheritanceStructMeta(): array
- {
- $inheritanceStruct = $this->getInheritanceStruct();
- {
- if ($this->cleanedName) {
- return $this->cleanedName;
- }
- if ($this->getGenerator()->getOptionGenericConstantsNames()) {
- return self::GENERIC_NAME_PREFIX.$this->getIndex();
- }
- $nameWithSeparatedWords = $this->getNameWithSeparatedWords($keepMultipleUnderscores);
- $key = self::constantSuffix($this->getOwner()->getName(), $nameWithSeparatedWords, $this->getIndex());
- if ($this->getGenerator()->getOptionGenericConstantsNames()) {
- return self::GENERIC_NAME_PREFIX.$this->getIndex();
- }
- $nameWithSeparatedWords = $this->getNameWithSeparatedWords($keepMultipleUnderscores);
- $key = self::constantSuffix($this->getOwner()->getName(), $nameWithSeparatedWords, $this->getIndex());
- return $this->cleanedName = self::VALUE_NAME_PREFIX.mb_strtoupper($nameWithSeparatedWords.($key ? '_'.$key : ''));
- }
- public function getNameWithSeparatedWords(bool $keepMultipleUnderscores = false): string
- return $this->cleanedName = self::VALUE_NAME_PREFIX.mb_strtoupper($nameWithSeparatedWords.($key ? '_'.$key : ''));
- }
- public function getNameWithSeparatedWords(bool $keepMultipleUnderscores = false): string
- {
- return trim(self::cleanString(preg_replace(self::MATCH_PATTERN, self::REPLACEMENT_PATTERN, (string) $this->getName()), $keepMultipleUnderscores), '_');
- }
- public function getValue()
- {
- return Utils::getValueWithinItsType($this->getName());
- return parent::getContent();
- }
- public function addSchema(Schema $schema): self
- {
- $this->getContent()->addExternalSchema($schema->getContent());
- $this->schemas->add($schema);
- return $this;
- }
- final class Functions extends AbstractParser
- {
- public function parse(): void
- {
- $methods = $this
- ->getGenerator()
- ->getSoapClient()
- ->getSoapClient()
- ->getSoapClient()
- ->__getFunctions()
- final class Functions extends AbstractParser
- {
- public function parse(): void
- {
- $methods = $this
- ->getGenerator()
- ->getSoapClient()
- ->getSoapClient()
- ->getSoapClient()
- ->__getFunctions()
- ->getSoapClient()
- ->getSoapClient()
- ->__getFunctions()
- ;
- $services = $this->getGenerator()->getServices();
- if (!is_array($methods) || 0 === count($methods)) {
- return;
- }
- if (!is_array($methods) || 0 === count($methods)) {
- return;
- }
- foreach ($methods as $method) {
- $infos = explode(' ', $method);
- // "Regular" SOAP Style
- if (count($infos) < 3) {
- $returnType = $infos[0];
- if (false !== mb_strpos($infos[1], '()') && array_key_exists(1, $infos)) {
- $methodName = trim(str_replace('()', '', $infos[1]));
- $parameterType = null;
- } else {
- [$methodName, $parameterType] = explode('(', $infos[1]);
- }
- if (!empty($returnType) && !empty($methodName)) {
- $services->addService($this->getGenerator()->getServiceName($methodName), $methodName, $parameterType, $returnType);
- }
- } else {
- /*
- * RPC SOAP Style
- * Some RPC WS defines the return type as a list of values
- * RPC SOAP Style
- * Some RPC WS defines the return type as a list of values
- * So we define the return type as an array and reset the information to use to extract method name and parameters
- */
- if (0 === mb_stripos($infos[0], 'list(')) {
- $infos = explode(' ', preg_replace('/(list\(.*\)\s)/i', '', $method));
- array_unshift($infos, 'array');
- }
- /**
- * Returns type is not defined in some case.
- $methodParameters = array_merge($methodParameters, [
- $info => $start === $i ? $firstParameterType : $infos[$i - 1],
- ]);
- }
- }
- $services->addService($this->getGenerator()->getServiceName($methodName), $methodName, $methodParameters, empty($returnType) ? 'unknown' : $returnType);
- }
- }
- }
- }
- }
- protected array $definedStructs = [];
- public function parse(): void
- {
- $types = $this
- ->getGenerator()
- ->getSoapClient()
- ->getSoapClient()
- ->getSoapClient()
- ->__getTypes()
- protected array $definedStructs = [];
- public function parse(): void
- {
- $types = $this
- ->getGenerator()
- ->getSoapClient()
- ->getSoapClient()
- ->getSoapClient()
- ->__getTypes()
- ->getSoapClient()
- ->__getTypes()
- ;
- foreach ($types as $type) {
- $this->parseType($type);
- }
- }
- protected function parseType(string $type): void
- {
- if (self::UNION_DECLARATION === $typeDef[0]) {
- $this->parseUnionStruct($typeDef);
- } elseif (self::STRUCT_DECLARATION === $typeDef[0]) {
- $this->parseComplexStruct($typeDef);
- } else {
- $this->getGenerator()->getStructs()->addVirtualStruct($structName, $typeDef[0]);
- }
- }
- $this->structHasBeenDefined($type);
- }
- protected function parseComplexStruct(array $typeDef): void
- {
- $typeDefCount = count($typeDef);
- if (3 < $typeDefCount) {
- for ($i = 2; $i < $typeDefCount; $i += 2) {
- $structParamType = str_replace(self::ANY_XML_DECLARATION, self::ANY_XML_TYPE, $typeDef[$i]);
- $structParamName = $typeDef[$i + 1];
- $this->getGenerator()->getStructs()->addStructWithAttribute($typeDef[1], $structParamName, $structParamType);
- }
- } else {
- $this->getGenerator()->getStructs()->addStruct($typeDef[1]);
- $typeDefCount = count($typeDef);
- if (3 < $typeDefCount) {
- for ($i = 2; $i < $typeDefCount; $i += 2) {
- $structParamType = str_replace(self::ANY_XML_DECLARATION, self::ANY_XML_TYPE, $typeDef[$i]);
- $structParamName = $typeDef[$i + 1];
- $this->getGenerator()->getStructs()->addStructWithAttribute($typeDef[1], $structParamName, $structParamType);
- }
- } else {
- $this->getGenerator()->getStructs()->addStruct($typeDef[1]);
- }
- }
- $typeDefCount = count($typeDef);
- if (3 < $typeDefCount) {
- for ($i = 2; $i < $typeDefCount; $i += 2) {
- $structParamType = str_replace(self::ANY_XML_DECLARATION, self::ANY_XML_TYPE, $typeDef[$i]);
- $structParamName = $typeDef[$i + 1];
- $this->getGenerator()->getStructs()->addStructWithAttribute($typeDef[1], $structParamName, $structParamType);
- }
- } else {
- $this->getGenerator()->getStructs()->addStruct($typeDef[1]);
- }
- }
- $typeDefCount = count($typeDef);
- if (3 < $typeDefCount) {
- for ($i = 2; $i < $typeDefCount; $i += 2) {
- $structParamType = str_replace(self::ANY_XML_DECLARATION, self::ANY_XML_TYPE, $typeDef[$i]);
- $structParamName = $typeDef[$i + 1];
- $this->getGenerator()->getStructs()->addStructWithAttribute($typeDef[1], $structParamName, $structParamType);
- }
- } else {
- $this->getGenerator()->getStructs()->addStruct($typeDef[1]);
- }
- }
- $structParamType = str_replace(self::ANY_XML_DECLARATION, self::ANY_XML_TYPE, $typeDef[$i]);
- $structParamName = $typeDef[$i + 1];
- $this->getGenerator()->getStructs()->addStructWithAttribute($typeDef[1], $structParamName, $structParamType);
- }
- } else {
- $this->getGenerator()->getStructs()->addStruct($typeDef[1]);
- }
- }
- /**
- * union types are passed such as ",dateTime,time" or ",PMS_ResStatusType,TransactionActionType,UpperCaseAlphaLength1to2".
- $structParamType = str_replace(self::ANY_XML_DECLARATION, self::ANY_XML_TYPE, $typeDef[$i]);
- $structParamName = $typeDef[$i + 1];
- $this->getGenerator()->getStructs()->addStructWithAttribute($typeDef[1], $structParamName, $structParamType);
- }
- } else {
- $this->getGenerator()->getStructs()->addStruct($typeDef[1]);
- }
- }
- /**
- * union types are passed such as ",dateTime,time" or ",PMS_ResStatusType,TransactionActionType,UpperCaseAlphaLength1to2".
- protected function parseUnionStruct(array $typeDef): void
- {
- $typeDefCount = count($typeDef);
- if (3 === $typeDefCount) {
- $unionName = $typeDef[1];
- $unionTypes = array_filter(explode(',', $typeDef[2]), fn ($type): bool => !empty($type));
- sort($unionTypes);
- $this->getGenerator()->getStructs()->addUnionStruct($unionName, $unionTypes);
- }
- }
- $typeDefCount = count($typeDef);
- if (3 === $typeDefCount) {
- $unionName = $typeDef[1];
- $unionTypes = array_filter(explode(',', $typeDef[2]), fn ($type): bool => !empty($type));
- sort($unionTypes);
- $this->getGenerator()->getStructs()->addUnionStruct($unionName, $unionTypes);
- }
- }
- /**
- * Remove useless break line, tabs
- $typeDefCount = count($typeDef);
- if (3 === $typeDefCount) {
- $unionName = $typeDef[1];
- $unionTypes = array_filter(explode(',', $typeDef[2]), fn ($type): bool => !empty($type));
- sort($unionTypes);
- $this->getGenerator()->getStructs()->addUnionStruct($unionName, $unionTypes);
- }
- }
- /**
- * Remove useless break line, tabs
- ']',
- ';',
- ], '', $type);
- $type = preg_replace('/[\s]+/', ' ', $type);
- return trim($type);
- }
- protected function isStructDefined(string $type): bool
- {
- return in_array(self::typeSignature($type), $this->definedStructs);
- }
- protected function parseWsdl(Wsdl $wsdl): void
- {
- foreach ($this->getTags() as $tag) {
- $this->parseTag($tag);
- }
- }
- }
- */
- final public function parse(): void
- {
- $wsdl = $this->generator->getWsdl();
- if (!$this->isWsdlParsed($wsdl)) {
- $this
- ->setWsdlAsParsed($wsdl)
- ->setTags($wsdl->getContent()->getElementsByName($this->parsingTag()))
- ->parseWsdl($wsdl)
- ;
- {
- $wsdl = $this->generator->getWsdl();
- if (!$this->isWsdlParsed($wsdl)) {
- $this
- ->setWsdlAsParsed($wsdl)
- ->setTags($wsdl->getContent()->getElementsByName($this->parsingTag()))
- ->parseWsdl($wsdl)
- ;
- }
- $wsdl = $this->generator->getWsdl();
- if (!$this->isWsdlParsed($wsdl)) {
- $this
- ->setWsdlAsParsed($wsdl)
- ->setTags($wsdl->getContent()->getElementsByName($this->parsingTag()))
- ->parseWsdl($wsdl)
- ;
- }
- /** @var Schema $schema */
- if (!$this->isWsdlParsed($wsdl)) {
- $this
- ->setWsdlAsParsed($wsdl)
- ->setTags($wsdl->getContent()->getElementsByName($this->parsingTag()))
- ->parseWsdl($wsdl)
- ;
- }
- /** @var Schema $schema */
- foreach ($wsdl->getSchemas() as $schema) {
- ->parseWsdl($wsdl)
- ;
- }
- /** @var Schema $schema */
- foreach ($wsdl->getSchemas() as $schema) {
- if ($this->isSchemaParsed($wsdl, $schema)) {
- continue;
- }
- $this->setSchemaAsParsed($wsdl, $schema);
- ;
- }
- /** @var Schema $schema */
- foreach ($wsdl->getSchemas() as $schema) {
- if ($this->isSchemaParsed($wsdl, $schema)) {
- continue;
- }
- $this->setSchemaAsParsed($wsdl, $schema);
- foreach ($wsdl->getSchemas() as $schema) {
- if ($this->isSchemaParsed($wsdl, $schema)) {
- continue;
- }
- $this->setSchemaAsParsed($wsdl, $schema);
- $this
- ->setTags($schema->getContent()->getElementsByName($this->parsingTag()))
- ->parseSchema($wsdl, $schema)
- ;
- $this->setSchemaAsParsed($wsdl, $schema);
- $this
- ->setTags($schema->getContent()->getElementsByName($this->parsingTag()))
- ->parseSchema($wsdl, $schema)
- ;
- }
- }
- public function getTags(): array
- return $this->tags;
- }
- public function isWsdlParsed(Wsdl $wsdl): bool
- {
- return array_key_exists($wsdl->getName(), $this->parsedWsdls) && is_array($this->parsedWsdls[$wsdl->getName()]) && in_array($this->parsingTag(), $this->parsedWsdls[$wsdl->getName()]);
- }
- public function isSchemaParsed(Wsdl $wsdl, Schema $schema): bool
- {
- $key = $wsdl->getName().$schema->getName();
- return $this;
- }
- protected function setWsdlAsParsed(Wsdl $wsdl): self
- {
- if (!array_key_exists($wsdl->getName(), $this->parsedWsdls)) {
- $this->parsedWsdls[$wsdl->getName()] = [];
- }
- $this->parsedWsdls[$wsdl->getName()][] = $this->parsingTag();
- return $this;
- abstract class AbstractTagImportParser extends AbstractTagParser
- {
- protected function parseWsdl(Wsdl $wsdl, ?Schema $schema = null): void
- {
- foreach ($this->getTags() as $tag) {
- if (empty($location = $tag->getLocationAttributeValue())) {
- continue;
- }
- $finalLocation = Utils::resolveCompletePath($this->getLocation($wsdl, $schema), $location);
- $this->generator->addSchemaToWsdl($wsdl, $finalLocation);
- foreach ($this->getTags() as $tag) {
- if (empty($location = $tag->getLocationAttributeValue())) {
- continue;
- }
- $finalLocation = Utils::resolveCompletePath($this->getLocation($wsdl, $schema), $location);
- $this->generator->addSchemaToWsdl($wsdl, $finalLocation);
- }
- }
- protected function getLocation(Wsdl $wsdl, ?Schema $schema = null): string
- protected function parseSchema(Wsdl $wsdl, ?Schema $schema): void
- {
- if (0 < count($this->getTags())) {
- $this->parseWsdl($wsdl, $schema);
- } else {
- $this->getTagParser()->parse();
- }
- }
- protected function getTagParser(): ?AbstractTagImportParser
- {
- $tagName = AbstractDocument::TAG_IMPORT;
- break;
- }
- return $this->getGenerator()->getParsers()->getParsers()->getParserByName($tagName);
- }
- }
- $tagName = AbstractDocument::TAG_IMPORT;
- break;
- }
- return $this->getGenerator()->getParsers()->getParsers()->getParserByName($tagName);
- }
- }
- $parts = $tag->getParts();
- $multipleParts = count((array) $parts);
- if (is_array($parts) && $multipleParts > 1) {
- $types = [];
- foreach ($parts as $part) {
- if (!empty($type = $this->getTypeFromPart($part))) {
- $types[$part->getAttributeName()] = $type;
- }
- }
- $this->setKnownType($method, $types);
- } elseif (is_array($parts) && $multipleParts > 0) {
- $multipleParts = count((array) $parts);
- if (is_array($parts) && $multipleParts > 1) {
- $types = [];
- foreach ($parts as $part) {
- if (!empty($type = $this->getTypeFromPart($part))) {
- $types[$part->getAttributeName()] = $type;
- }
- }
- $this->setKnownType($method, $types);
- } elseif (is_array($parts) && $multipleParts > 0) {
- $part = array_shift($parts);
- abstract protected function setKnownType(Method $method, $knownType);
- protected function parseWsdl(Wsdl $wsdl): void
- {
- foreach ($this->getTags() as $tag) {
- $this->parseInputOutput($tag);
- }
- }
- protected function getTypeFromPart(TagPart $part): string
- {
- $knownType = $this->getKnownType($method);
- if (is_string($knownType)) {
- $isKnown = !empty($knownType) && self::UNKNOWN !== mb_strtolower($knownType);
- } elseif (is_array($knownType)) {
- foreach ($knownType as $knownValue) {
- $isKnown &= self::UNKNOWN !== mb_strtolower($knownValue);
- }
- }
- return (bool) !$isKnown;
- }
- /** @var AbstractAttributeHandler $attribute */
- foreach ($tag->getAttributes() as $attribute) {
- $methodToCall = $this->getParseTagAttributeMethod($attribute->getName());
- if (is_array($methodToCall)) {
- call_user_func_array($methodToCall, [
- $attribute,
- $model,
- $structAttribute,
- ]);
- } else {
- $type = $tagAttribute->getValue();
- if (is_null($type)) {
- return;
- }
- $typeModel = $this->generator->getStructByName($type);
- $modelAttributeType = $structAttribute->getType();
- if ($typeModel instanceof Struct && (empty($modelAttributeType) || 'unknown' === mb_strtolower($modelAttributeType))) {
- if ($typeModel->isRestriction()) {
- $structAttribute->setType($typeModel->getName());
- $typeModel = $this->generator->getStructByName($type);
- $modelAttributeType = $structAttribute->getType();
- if ($typeModel instanceof Struct && (empty($modelAttributeType) || 'unknown' === mb_strtolower($modelAttributeType))) {
- if ($typeModel->isRestriction()) {
- $structAttribute->setType($typeModel->getName());
- } elseif (!$typeModel->isStruct() && $typeModel->getInheritance()) {
- $structAttribute->setType($typeModel->getInheritance());
- }
- }
- } else {
- {
- }
- protected function parseTagAttributeAbstract(AttributeHandler $tagAttribute, AbstractModel $model): void
- {
- $model->setAbstract($tagAttribute->getValue(false, true, 'bool'));
- }
- /**
- * Enumeration does not need its own value as meta information, it's like the name for struct attribute.
- */
- */
- public function parseChoice(Choice $choice): void
- {
- $parent = $choice->getSuitableParent();
- $children = $choice->getChildrenElements();
- if ($parent && count($children) && ($struct = $this->getModel($parent)) instanceof Struct) {
- $unionNames = [];
- foreach ($children as $child) {
- $unionNames[] = $child->getAttributeName() ?: $child->getAttributeRef();
- }
- foreach ($children as $child) {
- $parent = $choice->getSuitableParent();
- $children = $choice->getChildrenElements();
- if ($parent && count($children) && ($struct = $this->getModel($parent)) instanceof Struct) {
- $unionNames = [];
- foreach ($children as $child) {
- $unionNames[] = $child->getAttributeName() ?: $child->getAttributeRef();
- }
- foreach ($children as $child) {
- $this->parseChoiceChild($choice, $unionNames, $child, $struct);
- }
- unset($unionNames);
- $parent = $choice->getSuitableParent();
- $children = $choice->getChildrenElements();
- if ($parent && count($children) && ($struct = $this->getModel($parent)) instanceof Struct) {
- $unionNames = [];
- foreach ($children as $child) {
- $unionNames[] = $child->getAttributeName() ?: $child->getAttributeRef();
- }
- foreach ($children as $child) {
- $this->parseChoiceChild($choice, $unionNames, $child, $struct);
- }
- unset($unionNames);
- $unionNames = [];
- foreach ($children as $child) {
- $unionNames[] = $child->getAttributeName() ?: $child->getAttributeRef();
- }
- foreach ($children as $child) {
- $this->parseChoiceChild($choice, $unionNames, $child, $struct);
- }
- unset($unionNames);
- }
- }
- }
- protected function parseWsdl(Wsdl $wsdl): void
- {
- foreach ($this->getTags() as $tag) {
- $this->parseChoice($tag);
- }
- }
- protected function parsingTag(): string
- {
- }
- protected function parseWsdl(Wsdl $wsdl): void
- {
- foreach ($this->getTags() as $tag) {
- $this->parseComplexType($tag);
- }
- }
- protected function parsingTag(): string
- {
- }
- protected function parseWsdl(Wsdl $wsdl): void
- {
- foreach ($this->getTags() as $tag) {
- $this->parseDocumentation($tag);
- }
- }
- protected function parsingTag(): string
- {
- }
- protected function parseWsdl(Wsdl $wsdl): void
- {
- foreach ($this->getTags() as $tag) {
- $this->parseEnumeration($tag);
- }
- }
- protected function parsingTag(): string
- {
- final class TagExtension extends AbstractTagParser
- {
- public function parseExtension(Extension $extension): void
- {
- $base = $extension->getAttribute('base')->getValue();
- $parent = $extension->getSuitableParent();
- if (!empty($base) && $parent instanceof AbstractTag && $this->getModel($parent) instanceof AbstractModel && $parent->getAttributeName() !== $base) {
- $this->getModel($parent)->setInheritance($base);
- }
- }
- public function parseExtension(Extension $extension): void
- {
- $base = $extension->getAttribute('base')->getValue();
- $parent = $extension->getSuitableParent();
- if (!empty($base) && $parent instanceof AbstractTag && $this->getModel($parent) instanceof AbstractModel && $parent->getAttributeName() !== $base) {
- $this->getModel($parent)->setInheritance($base);
- }
- }
- protected function parseWsdl(Wsdl $wsdl): void
- {
- }
- protected function parseWsdl(Wsdl $wsdl): void
- {
- foreach ($this->getTags() as $tag) {
- $this->parseExtension($tag);
- }
- }
- protected function parsingTag(): string
- {
- }
- protected function parseWsdl(Wsdl $wsdl): void
- {
- foreach ($this->getTags() as $tag) {
- $this->parseHeader($tag);
- }
- }
- protected function parsingTag(): string
- {
- protected function isSoapHeaderAlreadyDefined(Method $method, string $soapHeaderName): bool
- {
- $methodSoapHeaders = $method->getMetaValue(self::META_SOAP_HEADER_NAMES, []);
- return in_array($soapHeaderName, $methodSoapHeaders, true);
- }
- }
- }
- protected function parseWsdl(Wsdl $wsdl): void
- {
- foreach ($this->getTags() as $tag) {
- $this->parseList($tag);
- }
- }
- protected function parsingTag(): string
- {
- $model = $this->getModel($parent, $restriction->getAttributeBase()) ?? $this->getModel($parent);
- // If restriction is contained by a union tag, don't create the virtual struct as "union"s
- // are wrongly parsed by SoapClient::__getTypes and this creates a duplicated element then
- if (!$model && !$restriction->hasUnionParent()) {
- $this->getGenerator()->getStructs()->addVirtualStruct($parent->getAttributeName(), $restriction->getAttributeBase());
- $model = $this->getModel($parent, $restriction->getAttributeBase());
- }
- if ($model instanceof Struct) {
- $this
- {
- if ($child->hasAttributeValue()) {
- $model->addMeta($child->getName(), $child->getValueAttributeValue(true));
- } else {
- foreach ($child->getAttributes() as $attribute) {
- $this->parseRestrictionChildAttribute($model, $attribute);
- }
- }
- return $this;
- }
- }
- protected function parseRestrictionChildAttribute(AbstractModel $model, AttributeHandler $attribute): self
- {
- if ('arraytype' === mb_strtolower($attribute->getName())) {
- $model->setInheritance($attribute->getValue());
- }
- $model->addMeta($attribute->getName(), $attribute->getValue(true));
- return $this;
- $parent = $union->getSuitableParent();
- if (!$parent) {
- return;
- }
- $model = $this->getModel($parent);
- if (!$model) {
- return;
- }
- $memberTypes = $union->getAttributeMemberTypes();
- }
- protected function parseWsdl(Wsdl $wsdl): void
- {
- foreach ($this->getTags() as $tag) {
- $this->parseUnion($tag);
- }
- }
- protected function parsingTag(): string
- {
- protected function findSuitableInheritance(array $values): string
- {
- $validInheritance = '';
- foreach ($values as $value) {
- $model = $this->getStructByName($value);
- while ($model instanceof AbstractModel && !empty($model->getInheritance())) {
- $model = $this->getStructByName($validInheritance = $model->getInheritance());
- }
- if ($model instanceof AbstractModel) {
- protected function getUnionMemberTypesFromChildren(Union $union): array
- {
- $memberTypes = [];
- foreach ($union->getMemberTypesChildren() as $child) {
- if ($child instanceof SimpleType && $child->hasRestrictionChild() && '' !== $child->getFirstRestrictionChild()->getAttributeBase()) {
- $memberTypes[] = $child->getFirstRestrictionChild()->getAttributeBase();
- }
- }
- return array_unique($memberTypes);
- protected function getUnionMemberTypesFromChildren(Union $union): array
- {
- $memberTypes = [];
- foreach ($union->getMemberTypesChildren() as $child) {
- if ($child instanceof SimpleType && $child->hasRestrictionChild() && '' !== $child->getFirstRestrictionChild()->getAttributeBase()) {
- $memberTypes[] = $child->getFirstRestrictionChild()->getAttributeBase();
- }
- }
- return array_unique($memberTypes);
- }
Your project inheritance architecture should be valid
- Read doc
- Reliability
- Major
More information: https://insight.symfony.com/what-we-analyse/php.invalid_inheritance
- use Symfony\Component\Console\Command\Command;
- use Symfony\Component\Console\Input\InputInterface;
- use Symfony\Component\Console\Input\InputOption;
- use Symfony\Component\Console\Output\OutputInterface;
- abstract class AbstractCommand extends Command
- {
- public const EXIT_OK = 0;
- protected InputInterface $input;
Your project must not contain invalid instantiations 29
- Read doc
- Reliability
- Major
More information: https://insight.symfony.com/what-we-analyse/php.invalid_instantiation
- }
- protected function defineGeneralAnnotations(PhpAnnotationBlock $block): self
- {
- foreach ($this->getGenerator()->getOptionAddComments() as $tagName => $tagValue) {
- $block->addChild(new PhpAnnotation($tagName, $tagValue));
- }
- return $this;
- }
- new PhpFunctionParameterBase(self::PARAM_SET_HEADER_ACTOR, null, '?'.self::TYPE_STRING),
- ], self::TYPE_SELF);
- $model = $this->getModelByName($soapHeaderType);
- if ($model instanceof StructModel) {
- $rules = new Rules($this, $method, new StructAttributeModel($model->getGenerator(), $soapHeaderType, $model->getName(), $model), $this->methods);
- $rules->applyRules(lcfirst($soapHeaderName));
- $firstParameter->setModel($model);
- }
- $method->addChild(sprintf('return $this->%s($%s, \'%s\', $%s, $%s, $%s);', self::METHOD_SET_HEADER_PREFIX, self::PARAM_SET_HEADER_NAMESPACE, $soapHeaderName, lcfirst($soapHeaderName), self::PARAM_SET_HEADER_MUSTUNDERSTAND, self::PARAM_SET_HEADER_ACTOR));
- } catch (\InvalidArgumentException $exception) {
- new PhpFunctionParameterBase(self::PARAM_SET_HEADER_ACTOR, null, '?'.self::TYPE_STRING),
- ], self::TYPE_SELF);
- $model = $this->getModelByName($soapHeaderType);
- if ($model instanceof StructModel) {
- $rules = new Rules($this, $method, new StructAttributeModel($model->getGenerator(), $soapHeaderType, $model->getName(), $model), $this->methods);
- $rules->applyRules(lcfirst($soapHeaderName));
- $firstParameter->setModel($model);
- }
- $method->addChild(sprintf('return $this->%s($%s, \'%s\', $%s, $%s, $%s);', self::METHOD_SET_HEADER_PREFIX, self::PARAM_SET_HEADER_NAMESPACE, $soapHeaderName, lcfirst($soapHeaderName), self::PARAM_SET_HEADER_MUSTUNDERSTAND, self::PARAM_SET_HEADER_ACTOR));
- } catch (\InvalidArgumentException $exception) {
- $firstParameter = array_shift($methodParameters);
- if ($firstParameter instanceof PhpFunctionParameter) {
- $annotationBlock->addChild(sprintf('Sets the %s SoapHeader param', ucfirst($firstParameter->getName())));
- $firstParameterType = $firstParameter->getType();
- if ($firstParameter->getModel() instanceof StructModel) {
- $firstParameterType = $this->getStructAttributeTypeAsPhpType(new StructAttributeModel($firstParameter->getModel()->getGenerator(), $firstParameter->getName(), $firstParameter->getModel()->getName(), $firstParameter->getModel()));
- if ($firstParameter->getModel()->isRestriction()) {
- $annotationBlock
- ->addChild(new PhpAnnotation(self::ANNOTATION_USES, sprintf('%s::%s()', $firstParameter->getModel()->getPackagedName(true), StructEnum::METHOD_VALUE_IS_VALID)))
- ->addChild(new PhpAnnotation(self::ANNOTATION_USES, sprintf('%s::%s()', $firstParameter->getModel()->getPackagedName(true), StructEnum::METHOD_GET_VALID_VALUES)))
- ->addChild(new PhpAnnotation(self::ANNOTATION_THROWS, \InvalidArgumentException::class))
- $firstParameter = array_shift($methodParameters);
- if ($firstParameter instanceof PhpFunctionParameter) {
- $annotationBlock->addChild(sprintf('Sets the %s SoapHeader param', ucfirst($firstParameter->getName())));
- $firstParameterType = $firstParameter->getType();
- if ($firstParameter->getModel() instanceof StructModel) {
- $firstParameterType = $this->getStructAttributeTypeAsPhpType(new StructAttributeModel($firstParameter->getModel()->getGenerator(), $firstParameter->getName(), $firstParameter->getModel()->getName(), $firstParameter->getModel()));
- if ($firstParameter->getModel()->isRestriction()) {
- $annotationBlock
- ->addChild(new PhpAnnotation(self::ANNOTATION_USES, sprintf('%s::%s()', $firstParameter->getModel()->getPackagedName(true), StructEnum::METHOD_VALUE_IS_VALID)))
- ->addChild(new PhpAnnotation(self::ANNOTATION_USES, sprintf('%s::%s()', $firstParameter->getModel()->getPackagedName(true), StructEnum::METHOD_GET_VALID_VALUES)))
- ->addChild(new PhpAnnotation(self::ANNOTATION_THROWS, \InvalidArgumentException::class))
- }
- protected function addStructMethodConstruct(): self
- {
- if (0 < count($parameters = $this->getStructMethodParametersValues())) {
- $method = new PhpMethod(self::METHOD_CONSTRUCT, $parameters);
- $this->addStructMethodConstructBody($method);
- $this->methods->add($method);
- }
- return $this;
- ).$this->getStructAttributeTypeAsPhpType($attribute);
- }
- $method = new PhpMethod(
- $attribute->getGetterName(),
- $this->getStructMethodGetParameters($attribute),
- $returnType
- );
- if ($attribute->nameIsClean()) {
- $thisAccess = sprintf('%s', $attribute->getName());
- } else {
- $this->getStructAttribute()
- ),
- ], self::TYPE_SELF);
- if ($this->getGenerator()->getOptionValidation()) {
- $rules = new Rules($this, $method, $this->getStructAttribute(), $this->methods);
- $rules->applyRules('item', true);
- }
- $method->addChild('return parent::add($item);');
- $this->methods->add($method);
- return $this;
- }
- protected function addArrayMethodGenericMethod(string $name, string $body, array $methodParameters = [], ?string $returnType = null): self
- {
- $method = new PhpMethod($name, $methodParameters, $returnType);
- $method->addChild($body);
- $this->methods->add($method);
- return $this;
- }
- $description,
- new PhpAnnotation(self::ANNOTATION_SEE, sprintf('%s::%s()', $this->getModel()->getExtends(true), $name)),
- ]);
- if (!empty($param)) {
- $annotationBlock->addChild(new PhpAnnotation(self::ANNOTATION_PARAM, $param));
- }
- $annotationBlock->addChild(new PhpAnnotation(self::ANNOTATION_RETURN, $this->getStructAttributeTypeGetAnnotation($this->getStructAttribute(), false, true)));
- return $annotationBlock;
- }
- protected function fillClassConstants(ConstantContainer $constants): void
- {
- /** @var StructModel $model */
- $model = $this->getModel();
- foreach ($model->getValues() as $value) {
- $constants->add(new PhpConstant($value->getCleanName(), $value->getValue()));
- }
- }
- protected function defineUseStatements(): self
- {
- {
- $annotationBlock = new PhpAnnotationBlock([
- 'Return allowed values',
- ]);
- foreach ($this->getEnumMethodValues() as $value) {
- $annotationBlock->addChild(new PhpAnnotation(self::ANNOTATION_USES, $value));
- }
- $annotationBlock->addChild(new PhpAnnotation(self::ANNOTATION_RETURN, 'string[]'));
- return $annotationBlock;
- }
- return $parameter;
- }
- protected function addAnnotationBlock($content): self
- {
- $this->getFile()->getMainElement()->addChild(new PhpAnnotationBlock($content));
- return $this;
- }
- }
- $rules = clone $this->getRules();
- $rules->setMethod($method);
- // gather validation rules
- foreach ($unionValues as $unionValue) {
- $attribute = new StructAttribute($this->getGenerator(), 'any', $unionValue);
- $attribute->setOwner($this->getAttribute()->getOwner());
- $rules
- ->setAttribute($attribute)
- ->applyRules('value')
- ;
- }
- public function addSchemaToWsdl(Wsdl $wsdl, string $schemaLocation): self
- {
- if (!empty($schemaLocation) && !$wsdl->hasSchema($schemaLocation)) {
- $wsdl->addSchema(new Schema($wsdl->getGenerator(), $schemaLocation, $this->getUrlContent($schemaLocation)));
- }
- return $this;
- }
- }
- public function addSchemaToWsdl(Wsdl $wsdl, string $schemaLocation): self
- {
- if (!empty($schemaLocation) && !$wsdl->hasSchema($schemaLocation)) {
- $wsdl->addSchema(new Schema($wsdl->getGenerator(), $schemaLocation, $this->getUrlContent($schemaLocation)));
- }
- return $this;
- }
- return $this;
- }
- protected function initWsdl(): self
- {
- $this->setWsdl(new Wsdl($this, $this->getOptionOrigin(), $this->getUrlContent($this->getOptionOrigin())));
- return $this;
- }
- /**
- }
- protected function generateServicesClasses(): self
- {
- foreach ($this->getGenerator()->getServices(true) as $service) {
- $file = new ServiceFile($this->generator, $service->getPackagedName());
- $file->setModel($service)->write();
- }
- return $this;
- }
- return $this->methods;
- }
- public function addMethod(string $methodName, $methodParameterType, $methodReturnType, $methodIsUnique = true): Method
- {
- $method = new Method($this->getGenerator(), $methodName, $methodParameterType, $methodReturnType, $this, $methodIsUnique);
- $this->methods->add($method);
- return $method;
- }
- return $this->methods;
- }
- public function addMethod(string $methodName, $methodParameterType, $methodReturnType, $methodIsUnique = true): Method
- {
- $method = new Method($this->getGenerator(), $methodName, $methodParameterType, $methodReturnType, $this, $methodIsUnique);
- $this->methods->add($method);
- return $method;
- }
- *
- * @param bool $requiredFirst places the required attributes first, then the not required in order to have the _construct method with the required attribute at first
- */
- public function getProperAttributes(bool $requiredFirst = false): StructAttributeContainer
- {
- $properAttributes = new StructAttributeContainer($this->getGenerator());
- $parentAttributes = new StructAttributeContainer($this->getGenerator());
- if (!empty($this->getInheritance()) && ($model = $this->getInheritanceStruct()) instanceof Struct) {
- while ($model instanceof Struct && $model->isStruct()) {
- foreach ($model->getAttributes() as $attribute) {
- * @param bool $requiredFirst places the required attributes first, then the not required in order to have the _construct method with the required attribute at first
- */
- public function getProperAttributes(bool $requiredFirst = false): StructAttributeContainer
- {
- $properAttributes = new StructAttributeContainer($this->getGenerator());
- $parentAttributes = new StructAttributeContainer($this->getGenerator());
- if (!empty($this->getInheritance()) && ($model = $this->getInheritanceStruct()) instanceof Struct) {
- while ($model instanceof Struct && $model->isStruct()) {
- foreach ($model->getAttributes() as $attribute) {
- $parentAttributes->add($attribute);
- {
- if (empty($attributeName) || empty($attributeType)) {
- throw new \InvalidArgumentException(sprintf('Attribute name "%s" and/or attribute type "%s" is invalid for Struct "%s"', $attributeName, $attributeType, $this->getName()), __LINE__);
- }
- if (is_null($this->attributes->getStructAttributeByName($attributeName))) {
- $structAttribute = new StructAttribute($this->getGenerator(), $attributeName, $attributeType, $this);
- $this->attributes->add($structAttribute);
- }
- return $this;
- }
- if (is_null($this->getValue($value))) {
- // issue #177, rare case: a struct and an enum has the same name and the enum is not detected by the SoapClient,
- // then we need to create the enumeration struct in order to deduplicate the two structs
- // this is why enumerations has to be parsed before any other elements by the WSDL parsers
- if (0 < $this->countOwnAttributes()) {
- $enum = new Struct($this->getGenerator(), $this->getName(), true, true);
- $enum->setInheritance(self::DEFAULT_ENUM_TYPE);
- $enum->getValues()->add(new StructValue($enum->getGenerator(), $value, $enum->getValues()->count(), $enum));
- $this->getGenerator()->getStructs()->add($enum);
- return $enum;
- // then we need to create the enumeration struct in order to deduplicate the two structs
- // this is why enumerations has to be parsed before any other elements by the WSDL parsers
- if (0 < $this->countOwnAttributes()) {
- $enum = new Struct($this->getGenerator(), $this->getName(), true, true);
- $enum->setInheritance(self::DEFAULT_ENUM_TYPE);
- $enum->getValues()->add(new StructValue($enum->getGenerator(), $value, $enum->getValues()->count(), $enum));
- $this->getGenerator()->getStructs()->add($enum);
- return $enum;
- }
- $this
- return $enum;
- }
- $this
- ->setStruct(true)
- ->setRestriction(true)
- ->getValues()->add(new StructValue($this->getGenerator(), $value, $this->getValues()->count(), $this))
- ;
- }
- return $this;
- }
- }
- }
- protected function getAllAttributes(bool $includeInheritanceAttributes, bool $requiredFirst): StructAttributeContainer
- {
- $allAttributes = new StructAttributeContainer($this->getGenerator());
- if ($includeInheritanceAttributes) {
- $this->addInheritanceAttributes($allAttributes);
- }
- foreach ($this->attributes as $attribute) {
- }
- }
- protected function putRequiredAttributesFirst(StructAttributeContainer $allAttributes): StructAttributeContainer
- {
- $attributes = new StructAttributeContainer($this->getGenerator());
- $requiredAttributes = [];
- $notRequiredAttributes = [];
- $nullableNotRequiredAttributes = [];
- /** @var StructAttribute $attribute */
- if (1 === count($block->getChildren())) {
- $block->addChild('Meta information extracted from the WSDL');
- }
- foreach ($validMeta as $meta) {
- $block->addChild(new PhpAnnotation(PhpAnnotation::NO_NAME, $meta, AbstractModelFile::ANNOTATION_META_LENGTH));
- }
- }
- }
- public static function getValidMetaValues(AbstractModel $model, array $ignoreMeta = []): array
Your project should only use iterable types in foreach loops 7
- Read doc
- Reliability
- Major
More information: https://insight.symfony.com/what-we-analyse/php.invalid_foreach_iterable
- protected function addServiceSoapHeadersDefinition(string $serviceVariableName, MethodModel $method, array $added): array
- {
- $addedNames = [];
- $soapHeaderNames = $method->getMetaValue(TagHeader::META_SOAP_HEADER_NAMES, []);
- foreach ($soapHeaderNames as $soapHeaderName) {
- if (in_array($soapHeaderName, $added, true)) {
- continue;
- }
- $addedNames[] = $soapHeaderName;
- $services = $this->containers->getServices();
- if ($usingGatherMethods && GeneratorOptions::VALUE_NONE === $this->getOptionGatherMethods()) {
- $serviceContainer = new ServiceContainer($this);
- $serviceModel = new Service($this, Service::DEFAULT_SERVICE_CLASS_NAME);
- foreach ($services as $service) {
- foreach ($service->getMethods() as $method) {
- $serviceModel->getMethods()->add($method);
- }
- }
- $serviceContainer->add($serviceModel);
- $services = $serviceContainer;
- {
- $decodedJson = json_decode($json, true);
- if (JSON_ERROR_NONE === json_last_error()) {
- // load options first
- $options = GeneratorOptions::instance();
- foreach ($decodedJson['options'] as $name => $value) {
- $options->setOptionValue($name, $value);
- }
- // create generator instance with options
- $instance = new self($options);
- // load services
- $options->setOptionValue($name, $value);
- }
- // create generator instance with options
- $instance = new self($options);
- // load services
- foreach ($decodedJson['containers']['services'] as $service) {
- $instance->getContainers()->getServices()->add(self::getModelInstanceFromJsonArrayEntry($instance, $service));
- }
- // load structs
- foreach ($decodedJson['containers']['structs'] as $struct) {
- $instance->getContainers()->getStructs()->add(self::getModelInstanceFromJsonArrayEntry($instance, $struct));
- // load services
- foreach ($decodedJson['containers']['services'] as $service) {
- $instance->getContainers()->getServices()->add(self::getModelInstanceFromJsonArrayEntry($instance, $service));
- }
- // load structs
- foreach ($decodedJson['containers']['structs'] as $struct) {
- $instance->getContainers()->getStructs()->add(self::getModelInstanceFromJsonArrayEntry($instance, $struct));
- }
- } else {
- throw new \InvalidArgumentException(sprintf('Json is invalid, please check error %s', json_last_error()));
- }
- $meta = func_get_args();
- $mergedMeta = [];
- $metaDocumentation = [];
- // gather meta
- foreach ($meta as $metaItem) {
- foreach ($metaItem as $metaName => $metaValue) {
- if (self::META_DOCUMENTATION === $metaName) {
- $metaDocumentation = array_merge($metaDocumentation, $metaValue);
- } elseif (!array_key_exists($metaName, $mergedMeta)) {
- $mergedMeta[$metaName] = $metaValue;
- } elseif (is_array($mergedMeta[$metaName]) && is_array($metaValue)) {
- ->getSoapClient()
- ->getSoapClient()
- ->__getTypes()
- ;
- foreach ($types as $type) {
- $this->parseType($type);
- }
- }
- protected function parseType(string $type): void
Your project files should use safer permissions
- Read doc
- Security
- Major
More information: https://insight.symfony.com/what-we-analyse/php.too_permissive_file_permissions
chmod a-x 'src/Command/AbstractCommand.php' \
'src/Command/GeneratePackageCommand.php' \
'src/ConfigurationReader/AbstractReservedWord.php' \
'src/ConfigurationReader/AbstractYamlReader.php' \
'src/ConfigurationReader/GeneratorOptions.php' \
'src/ConfigurationReader/PhpReservedKeyword.php' \
'src/ConfigurationReader/ServiceReservedMethod.php' \
'src/ConfigurationReader/StructArrayReservedMethod.php' \
'src/ConfigurationReader/StructReservedMethod.php' \
'src/ConfigurationReader/XsdTypes.php' \
'src/Container/AbstractObjectContainer.php' \
'src/Container/Model/AbstractModel.php' \
'src/Container/Model/EmptyModel.php' \
'src/Container/Model/Method.php' \
'src/Container/Model/Schema.php' \
'src/Container/Model/Service.php' \
'src/Container/Model/Struct.php' \
'src/Container/Model/StructAttribute.php' \
'src/Container/Model/StructValue.php' \
'src/Container/Parser.php' \
'src/Container/PhpElement/AbstractPhpElement.php' \
'src/Container/PhpElement/Constant.php' \
'src/Container/PhpElement/Method.php' \
'src/Container/PhpElement/Property.php' \
'src/File/AbstractFile.php' \
'src/File/AbstractModelFile.php' \
'src/File/AbstractOperation.php' \
'src/File/ClassMap.php' \
'src/File/Composer.php' \
'src/File/Element/PhpFunctionParameter.php' \
'src/File/FileInterface.php' \
'src/File/Operation.php' \
'src/File/OperationAnnotationBlock.php' \
'src/File/Service.php' \
'src/File/Struct.php' \
'src/File/StructArray.php' \
'src/File/StructEnum.php' \
'src/File/Tutorial.php' \
'src/File/Utils.php' \
'src/File/Validation/AbstractBoundRule.php' \
'src/File/Validation/AbstractLengthRule.php' \
'src/File/Validation/AbstractMinMaxRule.php' \
'src/File/Validation/AbstractRule.php' \
'src/File/Validation/AbstractSetOfValuesRule.php' \
'src/File/Validation/ArrayRule.php' \
'src/File/Validation/BoolRule.php' \
'src/File/Validation/BooleanRule.php' \
'src/File/Validation/ChoiceMaxOccursRule.php' \
'src/File/Validation/ChoiceMinOccursRule.php' \
'src/File/Validation/ChoiceRule.php' \
'src/File/Validation/EnumerationRule.php' \
'src/File/Validation/FloatRule.php' \
'src/File/Validation/FractionDigitsRule.php' \
'src/File/Validation/IntRule.php' \
'src/File/Validation/ItemTypeRule.php' \
'src/File/Validation/LengthRule.php' \
'src/File/Validation/ListRule.php' \
'src/File/Validation/MaxExclusiveRule.php' \
'src/File/Validation/MaxInclusiveRule.php' \
'src/File/Validation/MaxLengthRule.php' \
'src/File/Validation/MaxOccursRule.php' \
'src/File/Validation/MinExclusiveRule.php' \
'src/File/Validation/MinInclusiveRule.php' \
'src/File/Validation/MinLengthRule.php' \
'src/File/Validation/MinOccursRule.php' \
'src/File/Validation/PatternRule.php' \
'src/File/Validation/Rules.php' \
'src/File/Validation/StringRule.php' \
'src/File/Validation/TotalDigitsRule.php' \
'src/File/Validation/UnionRule.php' \
'src/File/Validation/XmlRule.php' \
'src/Generator/AbstractGeneratorAware.php' \
'src/Generator/Generator.php' \
'src/Generator/GeneratorContainers.php' \
'src/Generator/GeneratorFiles.php' \
'src/Generator/GeneratorParsers.php' \
'src/Generator/GeneratorSoapClient.php' \
'src/Generator/SoapClient.php' \
'src/Generator/Utils.php' \
'src/Model/AbstractDocument.php' \
'src/Model/AbstractModel.php' \
'src/Model/EmptyModel.php' \
'src/Model/Method.php' \
'src/Model/Schema.php' \
'src/Model/Service.php' \
'src/Model/Struct.php' \
'src/Model/StructAttribute.php' \
'src/Model/StructValue.php' \
'src/Model/Wsdl.php' \
'src/Parser/AbstractParser.php' \
'src/Parser/ParserInterface.php' \
'src/Parser/SoapClient/AbstractParser.php' \
'src/Parser/SoapClient/Functions.php' \
'src/Parser/SoapClient/Structs.php' \
'src/Parser/Wsdl/AbstractAttributesParser.php' \
'src/Parser/Wsdl/AbstractParser.php' \
'src/Parser/Wsdl/AbstractTagImportParser.php' \
'src/Parser/Wsdl/AbstractTagInputOutputParser.php' \
'src/Parser/Wsdl/AbstractTagParser.php' \
'src/Parser/Wsdl/README.md' \
'src/Parser/Wsdl/TagAttribute.php' \
'src/Parser/Wsdl/TagChoice.php' \
'src/Parser/Wsdl/TagComplexType.php' \
'src/Parser/Wsdl/TagDocumentation.php' \
'src/Parser/Wsdl/TagElement.php' \
'src/Parser/Wsdl/TagEnumeration.php' \
'src/Parser/Wsdl/TagExtension.php' \
'src/Parser/Wsdl/TagHeader.php' \
'src/Parser/Wsdl/TagImport.php' \
'src/Parser/Wsdl/TagInclude.php' \
'src/Parser/Wsdl/TagInput.php' \
'src/Parser/Wsdl/TagList.php' \
'src/Parser/Wsdl/TagOutput.php' \
'src/Parser/Wsdl/TagRestriction.php' \
'src/Parser/Wsdl/TagUnion.php' \
'src/resources/config/generator_options.yml' \
'src/resources/config/php_reserved_keywords.yml' \
'src/resources/config/service_reserved_keywords.yml' \
'src/resources/config/struct_array_reserved_keywords.yml' \
'src/resources/config/struct_reserved_keywords.yml' \
'src/resources/config/xsd_types.yml'
Text files should end with a valid new line character.
- Read doc
- Productivity
- Info
More information: https://insight.symfony.com/what-we-analyse/missing_e_o_l
- up:
- $(DOCKER_COMPOSE) up -d
- update:
- $(DOCKER_EXEC_CONTAINER) $(PHP_VERSION) $(COMPOSER) update