-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from webmasterskaya/update-to-base-lib-compatible
Update to base lib v1.0.0 compatible
- Loading branch information
Showing
17 changed files
with
434 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
src/CodeGenerator/Assembler/ClientConstructorAssembler.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
namespace Webmasterskaya\Soap\Base\Dev\CodeGenerator\Assembler; | ||
|
||
use Laminas\Code\Generator\AbstractMemberGenerator; | ||
use Laminas\Code\Generator\ClassGenerator; | ||
use Laminas\Code\Generator\DocBlock\Tag\VarTag; | ||
use Laminas\Code\Generator\DocBlockGenerator; | ||
use Laminas\Code\Generator\MethodGenerator; | ||
use Laminas\Code\Generator\ParameterGenerator; | ||
use Laminas\Code\Generator\PropertyGenerator; | ||
use Laminas\Code\Generator\TypeGenerator; | ||
use Phpro\SoapClient\CodeGenerator\Context\ClientContext; | ||
use Phpro\SoapClient\CodeGenerator\Context\ContextInterface; | ||
use Phpro\SoapClient\Exception\AssemblerException; | ||
use Webmasterskaya\Soap\Base\Caller\CallerInterface; | ||
|
||
use function Psl\Type\non_empty_string; | ||
|
||
class ClientConstructorAssembler extends \Phpro\SoapClient\CodeGenerator\Assembler\ClientConstructorAssembler | ||
{ | ||
public function assemble(ContextInterface $context) | ||
{ | ||
if (!$context instanceof ClientContext) { | ||
throw new AssemblerException( | ||
__METHOD__ . ' expects an ' . ClientContext::class . ' as input ' . get_class($context) . ' given' | ||
); | ||
} | ||
|
||
$class = $context->getClass(); | ||
try { | ||
$caller = $this->generateClassNameAndAddImport(CallerInterface::class, $class); | ||
$class->removeProperty('caller'); | ||
$class->addPropertyFromGenerator( | ||
(new PropertyGenerator( | ||
name: 'caller', | ||
flags: AbstractMemberGenerator::FLAG_PRIVATE, | ||
type: TypeGenerator::fromTypeString(CallerInterface::class) | ||
)) | ||
->setDocBlock(new DocBlockGenerator(tags: [new VarTag(description: $caller)])) | ||
->omitDefaultValue(true) | ||
); | ||
$class->removeMethod('__construct'); | ||
$class->addMethodFromGenerator( | ||
(new MethodGenerator( | ||
name: '__construct', | ||
parameters: [ | ||
new ParameterGenerator('caller', CallerInterface::class) | ||
], | ||
body: '$this->caller = $caller;' | ||
)) | ||
); | ||
} catch (\Exception $e) { | ||
throw AssemblerException::fromException($e); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* @param non-empty-string $fqcn | ||
*/ | ||
private function generateClassNameAndAddImport(string $fqcn, ClassGenerator $class): string | ||
{ | ||
$fqcn = non_empty_string()->assert(ltrim($fqcn, '\\')); | ||
$parts = explode('\\', $fqcn); | ||
$className = array_pop($parts); | ||
|
||
if (!\in_array($fqcn, $class->getUses(), true)) { | ||
$class->addUse($fqcn); | ||
} | ||
|
||
return $className; | ||
} | ||
} |
Oops, something went wrong.