/** * TypeMap constructor. * * @param string $namespace * @param array $types */ public function __construct($namespace, array $types) { $this->namespace = Normalizer::normalizeNamespace($namespace); foreach ($types as $type => $properties) { $this->types[] = new Type($namespace, $type, $properties); } }
/** * @param ContextInterface|PropertyContext $context * * @throws AssemblerException */ 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); } }
/** * @param ContextInterface|TypeContext $context */ public function assemble(ContextInterface $context) { $class = $context->getClass(); try { $uses = $class->getUses(); if (!in_array(Normalizer::getCompleteUseStatement($this->useName, $this->useAlias), $uses) && !in_array($this->useName, $uses)) { $class->addUse($this->useName, $this->useAlias); } } catch (\Exception $e) { throw AssemblerException::fromException($e); } }
/** * @param ContextInterface|TypeContext $context */ public function assemble(ContextInterface $context) { $class = $context->getClass(); try { $useAssembler = new UseAssembler($this->traitName, $this->traitAlias); if ($useAssembler->canAssemble($context)) { $useAssembler->assemble($context); } $traitAlias = $this->traitAlias ?: Normalizer::getClassNameFromFQN($this->traitName); $class->addTrait($traitAlias); } catch (\Exception $e) { throw AssemblerException::fromException($e); } }
/** * @return string */ public function setterName() { return Normalizer::generatePropertyMethod('set', $this->getName()); }
/** * @return string */ public function getFullName() { $fqnName = sprintf('%s\\%s', $this->getNamespace(), $this->getName()); return Normalizer::normalizeNamespace($fqnName); }
/** * @param string $namespace * * @return Config */ public function setNamespace($namespace) { $this->namespace = Normalizer::normalizeNamespace($namespace); return $this; }
/** * @param Property $property * * @return string */ private function generateGetResultReturnTag(Property $property) { if ($this->wrapperClass === null) { return $property->getType() . '|' . Normalizer::getClassNameFromFQN(ResultInterface::class); } return Normalizer::getClassNameFromFQN($this->wrapperClass); }