/** * @param array $schema * @param PhpClass $class */ protected function generateConstructor(array $schema, PhpClass $class) { $constructorParams = []; $constructorBody = []; if (!empty($schema['inherit'])) { $parent = new \ReflectionClass($schema['inherit']); $parentConstructor = $parent->getConstructor(); if ($parentConstructor) { $params = $parentConstructor->getParameters(); $callParamsDef = []; foreach ($params as $param) { $constructorParams[] = PhpParameter::fromReflection($param); $callParamsDef[] = '$' . $param->getName(); } $constructorBody[] = sprintf('parent::__construct(%s);', implode(', ', $callParamsDef)); } } foreach ($schema['addremove'] as $fieldName => $config) { $constructorBody[] = '$this->' . $fieldName . ' = new \\Doctrine\\Common\\Collections\\ArrayCollection();'; } $constructor = $this->generateClassMethod('__construct', implode("\n", $constructorBody)); foreach ($constructorParams as $constructorParam) { $constructor->addParameter($constructorParam); } $class->setMethod($constructor); }
public static function fromReflection(\ReflectionFunction $ref) { $function = new static(); if (false === ($pos = strrpos($ref->name, '\\'))) { $function->setName(substr($ref->name, $pos + 1)); $function->setNamespace(substr($ref->name, $pos)); } else { $function->setName($ref->name); } $function->referenceReturned = $ref->returnsReference(); $function->docblock = ReflectionUtils::getUnindentedDocComment($ref->getDocComment()); foreach ($ref->getParameters() as $refParam) { assert($refParam instanceof \ReflectionParameter); $param = PhpParameter::fromReflection($refParam); $function->addParameter($param); } return $function; }
/** * @return PhpParameter */ protected static function createParameter(\ReflectionParameter $parameter) { return PhpParameter::fromReflection($parameter); }