/** * @param ContextInterface|TypeContext|PropertyContext $context */ public function apply(ContextInterface $context) { $type = $context->getType(); $typeName = $type->getName(); $rule = array_key_exists($typeName, $this->typeMap) ? $this->typeMap[$typeName] : $this->defaultRule; $rule->apply($context); }
/** * @param ContextInterface $context * * @return bool */ public function appliesToContext(ContextInterface $context) { if (!$context instanceof TypeContext && !$context instanceof PropertyContext) { return false; } $type = $context->getType(); if (!preg_match($this->regex, $type->getName())) { return false; } return $this->subRule->appliesToContext($context); }
/** * @param ContextInterface|TypeContext $context */ public function assemble(ContextInterface $context) { $class = $context->getClass(); $type = $context->getType(); try { $class->removeMethod('__construct'); $constructor = $this->assembleConstructor($type); $class->addMethodFromGenerator($constructor); } catch (\Exception $e) { throw AssemblerException::fromException($e); } }
/** * @param ContextInterface|TypeContext $context * * @throws AssemblerException */ public function assemble(ContextInterface $context) { $class = $context->getClass(); $properties = $context->getType()->getProperties(); $firstProperty = count($properties) ? current($properties) : null; try { $interfaceAssembler = new InterfaceAssembler(\IteratorAggregate::class); if ($interfaceAssembler->canAssemble($context)) { $interfaceAssembler->assemble($context); } if ($firstProperty) { $this->implementGetIterator($class, $firstProperty); } } catch (\Exception $e) { throw AssemblerException::fromException($e); } }