public function generatePropertiesConstructor(array $properties) { if ($this->class->hasOwnMethod('__construct')) { $constructor = $this->class->getMethod('__construct'); //if (count($constructor->getBodyCode()) > 0) { // throw new \Psc\Exception('Ein constructor für '.$this->class->getFQN().' ist bereits definiert und hat einen Body. Deshalb kann er nicht überschrieben werden'); // ändere dies, falls das mal anders sein soll - dunno (yagni) //} } else { $constructor = $this->class->createMethod('__construct'); $this->class->setMethodOrder($constructor, GClass::PREPEND); } $code = array(); foreach ($properties as $property) { if (is_array($property) && array_key_exists('property', $property)) { $argument = $property; $property = $argument['property']; } else { $argument = array(); } if (!$property instanceof ClassBuilderProperty) { throw new \InvalidArgumentException('Es können nur ClassBuilderProperties übergeben werden'); } $param = new GParameter($property->getName(), $property->getPHPHint()); if (array_key_exists('default', $argument)) { $param->setDefault($argument['default']); $codeName = 'constructorSetterPartOptional'; } else { $codeName = 'constructorSetterPart'; } $code = array_merge($code, $this->createCode($codeName, array('setter' => $property->getSetterName(), 'property' => $property->getName()))); $constructor->addParameter($param); } $constructor->appendBodyLines($code); return $this; }