1
0
mirror of synced 2025-01-19 06:51:40 +03:00

Added <variableDefault> on generated class.

This allow to unset many-to-one and one-to-one relations


Example: $user->setGroup(null);
This commit is contained in:
Asmir Mustafic 2011-10-19 09:15:41 +02:00
parent e19fd756cb
commit 9c1202a766

View File

@ -117,7 +117,7 @@ public function <methodName>()
* @param <variableType>$<variableName> * @param <variableType>$<variableName>
* @return <entity> * @return <entity>
*/ */
public function <methodName>(<methodTypeHint>$<variableName>) public function <methodName>(<methodTypeHint>$<variableName><variableDefault>)
{ {
<spaces>$this-><fieldName> = $<variableName>; <spaces>$this-><fieldName> = $<variableName>;
<spaces>return $this; <spaces>return $this;
@ -634,7 +634,7 @@ public function <methodName>()
foreach ($metadata->associationMappings as $associationMapping) { foreach ($metadata->associationMappings as $associationMapping) {
if ($associationMapping['type'] & ClassMetadataInfo::TO_ONE) { if ($associationMapping['type'] & ClassMetadataInfo::TO_ONE) {
if ($code = $this->_generateEntityStubMethod($metadata, 'set', $associationMapping['fieldName'], $associationMapping['targetEntity'])) { if ($code = $this->_generateEntityStubMethod($metadata, 'set', $associationMapping['fieldName'], $associationMapping['targetEntity'], 'null')) {
$methods[] = $code; $methods[] = $code;
} }
if ($code = $this->_generateEntityStubMethod($metadata, 'get', $associationMapping['fieldName'], $associationMapping['targetEntity'])) { if ($code = $this->_generateEntityStubMethod($metadata, 'get', $associationMapping['fieldName'], $associationMapping['targetEntity'])) {
@ -707,7 +707,7 @@ public function <methodName>()
return implode("\n", $lines); return implode("\n", $lines);
} }
private function _generateEntityStubMethod(ClassMetadataInfo $metadata, $type, $fieldName, $typeHint = null) private function _generateEntityStubMethod(ClassMetadataInfo $metadata, $type, $fieldName, $typeHint = null, $defaultValue = null)
{ {
if ($type == "add") { if ($type == "add") {
$addMethod = explode("\\", $typeHint); $addMethod = explode("\\", $typeHint);
@ -737,6 +737,7 @@ public function <methodName>()
'<variableName>' => Inflector::camelize($fieldName), '<variableName>' => Inflector::camelize($fieldName),
'<methodName>' => $methodName, '<methodName>' => $methodName,
'<fieldName>' => $fieldName, '<fieldName>' => $fieldName,
'<variableDefault>' => ($defaultValue!==null?('='.$defaultValue):''),
'<entity>' => $this->_getClassName($metadata) '<entity>' => $this->_getClassName($metadata)
); );