Merge branch 'master' of github.com:doctrine/doctrine2
This commit is contained in:
commit
6b0cd7b604
@ -225,6 +225,14 @@ class EntityRepository implements ObjectRepository
|
|||||||
return $this->_entityName;
|
return $this->_entityName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getClassName()
|
||||||
|
{
|
||||||
|
return $this->getEntityName();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return EntityManager
|
* @return EntityManager
|
||||||
*/
|
*/
|
||||||
@ -240,4 +248,4 @@ class EntityRepository implements ObjectRepository
|
|||||||
{
|
{
|
||||||
return $this->_class;
|
return $this->_class;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
@ -406,7 +406,7 @@ public function <methodName>()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($collections) {
|
if ($collections) {
|
||||||
return $this->_prefixCodeWithSpaces(str_replace("<collections>", implode("\n", $collections), self::$_constructorMethodTemplate));
|
return $this->_prefixCodeWithSpaces(str_replace("<collections>", implode("\n".$this->_spaces, $collections), self::$_constructorMethodTemplate));
|
||||||
}
|
}
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
@ -634,7 +634,8 @@ 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'])) {
|
$nullable = $this->_isAssociationIsNullable($associationMapping) ? 'null' : null;
|
||||||
|
if ($code = $this->_generateEntityStubMethod($metadata, 'set', $associationMapping['fieldName'], $associationMapping['targetEntity'], $nullable)) {
|
||||||
$methods[] = $code;
|
$methods[] = $code;
|
||||||
}
|
}
|
||||||
if ($code = $this->_generateEntityStubMethod($metadata, 'get', $associationMapping['fieldName'], $associationMapping['targetEntity'])) {
|
if ($code = $this->_generateEntityStubMethod($metadata, 'get', $associationMapping['fieldName'], $associationMapping['targetEntity'])) {
|
||||||
@ -653,6 +654,22 @@ public function <methodName>()
|
|||||||
return implode("\n\n", $methods);
|
return implode("\n\n", $methods);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function _isAssociationIsNullable($associationMapping)
|
||||||
|
{
|
||||||
|
if (isset($associationMapping['joinColumns'])) {
|
||||||
|
$joinColumns = $associationMapping['joinColumns'];
|
||||||
|
} else {
|
||||||
|
//@todo thereis no way to retreive targetEntity metadata
|
||||||
|
$joinColumns = array();
|
||||||
|
}
|
||||||
|
foreach ($joinColumns as $joinColumn) {
|
||||||
|
if(isset($joinColumn['nullable']) && !$joinColumn['nullable']) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private function _generateEntityLifecycleCallbackMethods(ClassMetadataInfo $metadata)
|
private function _generateEntityLifecycleCallbackMethods(ClassMetadataInfo $metadata)
|
||||||
{
|
{
|
||||||
if (isset($metadata->lifecycleCallbacks) && $metadata->lifecycleCallbacks) {
|
if (isset($metadata->lifecycleCallbacks) && $metadata->lifecycleCallbacks) {
|
||||||
@ -707,7 +724,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 +754,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)
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -805,7 +823,12 @@ public function <methodName>()
|
|||||||
{
|
{
|
||||||
$lines = array();
|
$lines = array();
|
||||||
$lines[] = $this->_spaces . '/**';
|
$lines[] = $this->_spaces . '/**';
|
||||||
$lines[] = $this->_spaces . ' * @var ' . $associationMapping['targetEntity'];
|
|
||||||
|
if ($associationMapping['type'] & ClassMetadataInfo::TO_MANY) {
|
||||||
|
$lines[] = $this->_spaces . ' * @var \Doctrine\Common\Collections\ArrayCollection';
|
||||||
|
} else {
|
||||||
|
$lines[] = $this->_spaces . ' * @var ' . $associationMapping['targetEntity'];
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->_generateAnnotations) {
|
if ($this->_generateAnnotations) {
|
||||||
$lines[] = $this->_spaces . ' *';
|
$lines[] = $this->_spaces . ' *';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user