Created
July 14, 2013 17:55
-
-
Save bes89/5995093 to your computer and use it in GitHub Desktop.
Doctrine2: Generate correct variable names (singular) in add or remove methods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// File: doctrine/orm/lib/Doctrine/ORM/Tools/EntityGenerator.php | |
// ... | |
class EntityGenerator | |
{ | |
// ... | |
protected function generateEntityStubMethod(ClassMetadataInfo $metadata, $type, $fieldName, $typeHint = null, $defaultValue = null) | |
{ | |
$methodName = $type . Inflector::classify($fieldName); | |
+ $variableName = $fieldName; | |
if (in_array($type, array("add", "remove"))) { | |
$methodName = Inflector::singularize($methodName); | |
+ $variableName = Inflector::singularize($variableName); | |
} | |
// ... | |
$replacements = array( | |
- '<description>' => ucfirst($type) . ' ' . $fieldName, | |
+ '<description>' => ucfirst($type) . ' ' . $variableName, | |
'<methodTypeHint>' => $methodTypeHint, | |
'<variableType>' => $variableType, | |
- '<variableName>' => Inflector::camelize($fieldName), | |
+ '<variableName>' => Inflector::camelize($variableName), | |
'<methodName>' => $methodName, | |
'<fieldName>' => $fieldName, | |
'<variableDefault>' => ($defaultValue !== null ) ? (' = '.$defaultValue) : '', | |
'<entity>' => $this->getClassName($metadata) | |
); | |
// ... | |
} | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment