Joli\Jane\Generator\Normalizer\DenormalizerGenerator::createDenormalizeMethod PHP 메소드

createDenormalizeMethod() 보호된 메소드

Create the denormalization method.
protected createDenormalizeMethod ( $modelFqdn, Joli\Jane\Generator\Context\Context $context, $properties ) : ClassMethod
$modelFqdn
$context Joli\Jane\Generator\Context\Context
$properties
리턴 PhpParser\Node\Stmt\ClassMethod
    protected function createDenormalizeMethod($modelFqdn, Context $context, $properties)
    {
        $context->refreshScope();
        $objectVariable = new Expr\Variable('object');
        $assignStatement = new Expr\Assign($objectVariable, new Expr\New_(new Name('\\' . $modelFqdn)));
        $statements = [$assignStatement];
        if ($this->useReference) {
            $statements = [new Stmt\If_(new Expr\Isset_([new Expr\PropertyFetch(new Expr\Variable('data'), "{'\$ref'}")]), ['stmts' => [new Stmt\Return_(new Expr\New_(new Name('Reference'), [new Expr\PropertyFetch(new Expr\Variable('data'), "{'\$ref'}"), new Expr\Ternary(new Expr\ArrayDimFetch(new Expr\Variable('context'), new Scalar\String_('rootSchema')), null, new Expr\ConstFetch(new Name('null')))]))]]), $assignStatement, new Stmt\If_(new Expr\BooleanNot(new Expr\Isset_([new Expr\ArrayDimFetch(new Expr\Variable('context'), new Scalar\String_('rootSchema'))])), ['stmts' => [new Expr\Assign(new Expr\ArrayDimFetch(new Expr\Variable('context'), new Scalar\String_('rootSchema')), $objectVariable)]])];
        }
        foreach ($properties as $property) {
            $propertyVar = new Expr\PropertyFetch(new Expr\Variable('data'), sprintf("{'%s'}", $property->getName()));
            list($denormalizationStatements, $outputVar) = $property->getType()->createDenormalizationStatement($context, $propertyVar);
            $statements[] = new Stmt\If_(new Expr\FuncCall(new Name('property_exists'), [new Arg(new Expr\Variable('data')), new Arg(new Scalar\String_($property->getName()))]), ['stmts' => array_merge($denormalizationStatements, [new Expr\MethodCall($objectVariable, $this->getNaming()->getPrefixedMethodName('set', $property->getName()), [$outputVar])])]);
        }
        $statements[] = new Stmt\Return_($objectVariable);
        return new Stmt\ClassMethod('denormalize', ['type' => Stmt\Class_::MODIFIER_PUBLIC, 'params' => [new Param('data'), new Param('class'), new Param('format', new Expr\ConstFetch(new Name('null'))), new Param('context', new Expr\Array_(), 'array')], 'stmts' => $statements]);
    }