/** * @param FieldMappingInterface $fieldMapping * @return Node[] */ public function getPropertyNodes(FieldMappingInterface $fieldMapping) { if (!$fieldMapping instanceof AbstractRelationMapping) { throw new \InvalidArgumentException('Field mapping has to be AbstractRelationMapping!'); } return array(new Property(2, array(new PropertyProperty($fieldMapping->getName())), array('comments' => array(new Comment(new Documentor(array(new VarRow($this->getVarString($fieldMapping))))))))); }
/** * @param FieldMappingInterface $fieldMapping * @return Node[] */ public function getMetadataNodes(FieldMappingInterface $fieldMapping) { if (!$fieldMapping instanceof One2OneInverseSideMapping) { throw new \InvalidArgumentException('Field mapping has to be One2OneInverseSideMapping!'); } return array(new MethodCall(new Variable('builder'), 'addInverseOneToOne', array(new Arg(new String_($fieldMapping->getName())), new Arg(new String_($fieldMapping->getTargetModel())), new Arg(new String_($fieldMapping->getMappedBy()))))); }
/** * @param FieldMappingInterface $fieldMapping * @return string */ public function getPhpDocType(FieldMappingInterface $fieldMapping) { if (!$fieldMapping instanceof ObjectFieldMapping) { throw new \InvalidArgumentException('Field mapping has to be ObjectFieldMapping!'); } return $fieldMapping->getClass(); }
/** * @param FieldMappingInterface $fieldMapping * @param string $relatedName * @param string $relatedRemovePrefix * @param string $relatedAddPrefix * @return Node */ protected function getBidiretionalSetterMethodNode(FieldMappingInterface $fieldMapping, $relatedName, $relatedRemovePrefix, $relatedAddPrefix) { if (!$fieldMapping instanceof AbstractRelationMapping) { throw new \InvalidArgumentException('Field mapping has to be AbstractRelationMapping!'); } $name = $fieldMapping->getName(); $targetModel = $fieldMapping->getTargetModel(); return new ClassMethod('set' . ucfirst($name), array('type' => 1, 'params' => array(new Param($name, new ConstFetch(new Name('null')), new Name($targetModel)), new Param('stopPropagation', new ConstFetch(new Name('false')))), 'stmts' => array(new If_(new BooleanNot(new Variable('stopPropagation')), array('stmts' => array(new If_(new NotIdentical(new ConstFetch(new Name('null')), new PropertyFetch(new Variable('this'), $name)), array('stmts' => array(new MethodCall(new PropertyFetch(new Variable('this'), $name), $relatedRemovePrefix . ucfirst($relatedName), array(new Arg(new Variable('this')), new Arg(new ConstFetch(new Name('true')))))))), new If_(new NotIdentical(new ConstFetch(new Name('null')), new Variable($name)), array('stmts' => array(new MethodCall(new Variable($name), $relatedAddPrefix . ucfirst($relatedName), array(new Arg(new Variable('this')), new Arg(new ConstFetch(new Name('true'))))))))))), new Assign(new PropertyFetch(new Variable('this'), $name), new Variable($name)), new Return_(new Variable('this')))), array('comments' => array(new Comment(new Documentor(array(new ParamRow($targetModel, $name), new ParamRow('bool', 'stopPropagation'), new ReturnRow('$this'))))))); }
/** * @param FieldMappingInterface $fieldMapping * @return Node */ protected function getBidiretionalSetterMethodNode(FieldMappingInterface $fieldMapping) { if (!$fieldMapping instanceof AbstractMany2ManyMapping) { throw new \InvalidArgumentException('Field mapping has to be AbstractMany2ManyMapping!'); } $name = $fieldMapping->getName(); $singularName = StringUtil::singularify($name); $targetModel = $fieldMapping->getTargetModel(); return new ClassMethod('set' . ucfirst($name), array('type' => 1, 'params' => array(new Param($name)), 'stmts' => array(new Foreach_(new PropertyFetch(new Variable('this'), $name), new Variable($singularName), array('stmts' => array(new MethodCall(new Variable('this'), 'remove' . ucfirst($singularName), array(new Arg(new Variable($singularName))))))), new Foreach_(new Variable($name), new Variable($singularName), array('stmts' => array(new MethodCall(new Variable('this'), 'add' . ucfirst($singularName), array(new Arg(new Variable($singularName))))))), new Return_(new Variable('this')))), array('comments' => array(new Comment(new Documentor(array(new ParamRow($targetModel . '[]|\\Doctrine\\Common\\Collections\\Collection', $name), new ReturnRow('$this'))))))); }
/** * @param FieldMappingInterface $fieldMapping * @param array $items * @return array */ protected function addOtherMetadataArrayItems(FieldMappingInterface $fieldMapping, array $items) { if (!$fieldMapping instanceof StringFieldMapping) { return $items; } if (null !== ($length = $fieldMapping->getLength())) { $items[] = new ArrayItem(new LNumber($length), new String_('length')); } return $items; }
/** * @param FieldMappingInterface $fieldMapping * @param array $items * @return array */ protected function addOtherMetadataArrayItems(FieldMappingInterface $fieldMapping, array $items) { if (!$fieldMapping instanceof DecimalFieldMapping) { return $items; } if (null !== ($precision = $fieldMapping->getPrecision())) { $items[] = new ArrayItem(new LNumber($precision), new String_('precision')); } if (null !== ($scale = $fieldMapping->getScale())) { $items[] = new ArrayItem(new LNumber($scale), new String_('scale')); } return $items; }
/** * @param FieldMappingInterface $fieldMapping * @return Node[] */ public function getMetadataNodes(FieldMappingInterface $fieldMapping) { if (!$fieldMapping instanceof Many2ManyOwningSideMapping) { throw new \InvalidArgumentException('Field mapping has to be Many2ManyOwningSideMapping!'); } if (null === $fieldMapping->getInversedBy()) { return array(new MethodCall(new Variable('builder'), 'addOwningManyToMany', array(new Arg(new String_($fieldMapping->getName())), new Arg(new String_($fieldMapping->getTargetModel()))))); } return array(new MethodCall(new Variable('builder'), 'addOwningManyToMany', array(new Arg(new String_($fieldMapping->getName())), new Arg(new String_($fieldMapping->getTargetModel())), new Arg(new String_($fieldMapping->getInversedBy()))))); }
/** * @param FieldMappingInterface $fieldMapping * @return Node[] */ public function getMetadataNodes(FieldMappingInterface $fieldMapping) { $items = array(); if (null !== ($nullable = $fieldMapping->isNullable())) { $items[] = new ArrayItem(new ConstFetch(new Name($nullable ? 'true' : 'false')), new String_('nullable')); } if (null !== ($unique = $fieldMapping->isUnique())) { $items[] = new ArrayItem(new ConstFetch(new Name($unique ? 'true' : 'false')), new String_('unique')); } if (null !== ($columnName = $fieldMapping->getColumnName())) { $items[] = new ArrayItem(new String_($columnName), new String_('columnName')); } if (null !== ($columnDefinition = $fieldMapping->getColumnDefinition())) { $items[] = new ArrayItem(new String_($columnDefinition), new String_('columnDefinition')); } if (null !== ($options = $fieldMapping->getOptions())) { $items[] = new ArrayItem($this->covertArrayToNodes($options), new String_('options')); } $items = $this->addOtherMetadataArrayItems($fieldMapping, $items); if (count($items) > 0) { return array(new MethodCall(new Variable('builder'), 'addField', array(new Arg(new String_($fieldMapping->getName())), new Arg(new String_($this->getName())), new Arg(new Array_($items))))); } return array(new MethodCall(new Variable('builder'), 'addField', array(new Arg(new String_($fieldMapping->getName())), new Arg(new String_($this->getName()))))); }
/** * @param FieldMappingInterface $fieldMapping * @return Node[] */ public function getMetadataNodes(FieldMappingInterface $fieldMapping) { return array(new MethodCall(new MethodCall(new MethodCall(new MethodCall(new Variable('builder'), 'createField', array(new Arg(new String_($fieldMapping->getName())), new Arg(new String_('integer')))), 'isPrimaryKey'), 'generatedValue'), 'build')); }
/** * @param FieldMappingInterface $fieldMapping * @return $this */ public function addField(FieldMappingInterface $fieldMapping) { $this->fieldMappings[$fieldMapping->getName()] = $fieldMapping; return $this; }
/** * @param FieldMappingInterface $fieldMapping * @return Node[] */ public function getConstructNodes(FieldMappingInterface $fieldMapping) { return array(new Assign(new PropertyFetch(new Variable('this'), $fieldMapping->getName()), new New_(new Name('\\Doctrine\\Common\\Collections\\ArrayCollection')))); }