Skip to content

Commit 35fc5de

Browse files
committed
Make it possible to configure a mapping of type namespaces based on xmlns
1 parent 1b14f81 commit 35fc5de

44 files changed

Lines changed: 442 additions & 1184 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/Phpro/SoapClient/CodeGenerator/Assembler/ClassMapAssembler.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ public function assemble(ContextInterface $context)
4242
$file->setClass($class);
4343
$file->setNamespace($context->getNamespace());
4444
$typeMap = $context->getTypeMap();
45-
$typeNamespace = $typeMap->getNamespace();
46-
$file->setUse($typeNamespace, preg_match('/\\\\Type$/', $typeNamespace) ? null : 'Type');
4745

4846
try {
4947
$file->setUse(ClassMapCollection::class);
@@ -117,7 +115,7 @@ private function assembleClassMap(
117115
$indentation,
118116
$type->getXsdType()->getXmlNamespace(),
119117
$type->getXsdType()->getName(),
120-
'Type\\'.$type->getName()
118+
'\\' . $type->getFullName(),
121119
);
122120
}
123121

src/Phpro/SoapClient/CodeGenerator/ClassMapGenerator.php

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace Phpro\SoapClient\CodeGenerator;
44

5+
use Phpro\SoapClient\CodeGenerator\Config\ClassMapConfig;
56
use Phpro\SoapClient\CodeGenerator\Context\ClassMapContext;
67
use Phpro\SoapClient\CodeGenerator\Context\FileContext;
7-
use Phpro\SoapClient\CodeGenerator\Model\Type;
88
use Phpro\SoapClient\CodeGenerator\Model\TypeMap;
99
use Phpro\SoapClient\CodeGenerator\Rules\RuleSetInterface;
1010
use Laminas\Code\Generator\FileGenerator;
@@ -14,33 +14,10 @@
1414
*/
1515
class ClassMapGenerator implements GeneratorInterface
1616
{
17-
/**
18-
* @var RuleSetInterface
19-
*/
20-
private $ruleSet;
21-
22-
/**
23-
* @var string
24-
*/
25-
private $name;
26-
27-
/**
28-
* @var string
29-
*/
30-
private $namespace;
31-
32-
/**
33-
* TypeGenerator constructor.
34-
*
35-
* @param RuleSetInterface $ruleSet
36-
* @param string $name
37-
* @param string $namespace
38-
*/
39-
public function __construct(RuleSetInterface $ruleSet, string $name, string $namespace)
40-
{
41-
$this->ruleSet = $ruleSet;
42-
$this->name = $name;
43-
$this->namespace = $namespace;
17+
public function __construct(
18+
private RuleSetInterface $ruleSet,
19+
private ClassMapConfig $classMap
20+
) {
4421
}
4522

4623
/**
@@ -51,7 +28,7 @@ public function __construct(RuleSetInterface $ruleSet, string $name, string $nam
5128
*/
5229
public function generate(FileGenerator $file, $typeMap): string
5330
{
54-
$this->ruleSet->applyRules(new ClassMapContext($file, $typeMap, $this->name, $this->namespace));
31+
$this->ruleSet->applyRules(new ClassMapContext($file, $typeMap, $this->classMap));
5532
$this->ruleSet->applyRules(new FileContext($file));
5633

5734
return $file->generate();

src/Phpro/SoapClient/CodeGenerator/ClientGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function generate(FileGenerator $file, $client): string
5050
$class->setNamespaceName($client->getNamespace());
5151
$class->setName($client->getName());
5252

53-
$this->ruleSet->applyRules(new ClientContext($class, $client->getName(), $client->getNamespace()));
53+
$this->ruleSet->applyRules(new ClientContext($class, $client->config()));
5454

5555
$methods = $client->getMethodMap();
5656
foreach ($methods->getMethods() as $method) {
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Phpro\SoapClient\CodeGenerator\Config;
4+
5+
final readonly class ClassMapConfig
6+
{
7+
/**
8+
* @param non-empty-string $name
9+
*/
10+
public function __construct(
11+
public string $name,
12+
public Destination $destination,
13+
) {
14+
}
15+
16+
/**
17+
* @return non-empty-string
18+
*/
19+
public function path(): string
20+
{
21+
return $this->destination->path . '/' . $this->name . '.php';
22+
}
23+
24+
/**
25+
* @return non-empty-string
26+
*/
27+
public function fqcn(): string
28+
{
29+
return $this->destination->namespace . '\\' . $this->name;
30+
}
31+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Phpro\SoapClient\CodeGenerator\Config;
4+
5+
final readonly class ClientConfig
6+
{
7+
/**
8+
* @param non-empty-string $name
9+
*/
10+
public function __construct(
11+
public string $name,
12+
public Destination $destination,
13+
) {
14+
}
15+
16+
/**
17+
* @return non-empty-string
18+
*/
19+
public function path(): string
20+
{
21+
return $this->destination->path . '/' . $this->name . '.php';
22+
}
23+
24+
/**
25+
* @return non-empty-string
26+
*/
27+
public function fqcn(): string
28+
{
29+
return $this->destination->namespace . '\\' . $this->name;
30+
}
31+
}

0 commit comments

Comments
 (0)