Пример #1
0
 /**
  * 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);
     }
 }
Пример #2
0
 /**
  * @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);
     }
 }
Пример #3
0
 /**
  * @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);
     }
 }
Пример #4
0
 /**
  * @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);
     }
 }
Пример #5
0
 /**
  * @return string
  */
 public function setterName()
 {
     return Normalizer::generatePropertyMethod('set', $this->getName());
 }
Пример #6
0
 /**
  * @return string
  */
 public function getFullName()
 {
     $fqnName = sprintf('%s\\%s', $this->getNamespace(), $this->getName());
     return Normalizer::normalizeNamespace($fqnName);
 }
Пример #7
0
 /**
  * @param string $namespace
  *
  * @return Config
  */
 public function setNamespace($namespace)
 {
     $this->namespace = Normalizer::normalizeNamespace($namespace);
     return $this;
 }
Пример #8
0
 /**
  * @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);
 }