Phpro\SoapClient\CodeGenerator\Assembler\GetterAssembler::assemble PHP Метод

assemble() публичный Метод

public assemble ( Phpro\SoapClient\CodeGenerator\Context\ContextInterface $context )
$context Phpro\SoapClient\CodeGenerator\Context\ContextInterface
    public function assemble(ContextInterface $context)
    {
        $class = $context->getClass();
        $property = $context->getProperty();
        try {
            $methodName = Normalizer::generatePropertyMethod('get', $property->getName());
            $class->removeMethod($methodName);
            $class->addMethodFromGenerator(MethodGenerator::fromArray(['name' => $methodName, 'parameters' => [], 'visibility' => MethodGenerator::VISIBILITY_PUBLIC, 'body' => sprintf('return $this->%s;', $property->getName()), 'docblock' => DocBlockGenerator::fromArray(['tags' => [['name' => 'return', 'description' => $property->getType()]]])]));
        } catch (\Exception $e) {
            throw AssemblerException::fromException($e);
        }
    }

Usage Example

Пример #1
0
    /**
     * @test
     */
    function it_assembles_a_property()
    {
        $assembler = new GetterAssembler();
        $context = $this->createContext();
        $assembler->assemble($context);
        $code = $context->getClass()->generate();
        $expected = <<<CODE
namespace MyNamespace;

class MyType
{

    /**
     * @return string
     */
    public function getProp1()
    {
        return \$this->prop1;
    }


}

CODE;
        $this->assertEquals($expected, $code);
    }