Permalink
Browse files

support short class name

  • Loading branch information...
1 parent 368cf73 commit 0f081d7c4525b51f577a753173f7ba9dd00350b6 @FabioBatSilva committed with fabio.silva Jul 29, 2012
@@ -1326,10 +1326,7 @@ protected function _validateAndCompleteAssociationMapping(array $mapping)
$mapping['sourceEntity'] = $this->name;
if (isset($mapping['targetEntity'])) {
- if (strlen($this->namespace) > 0 && strpos($mapping['targetEntity'], '\\') === false) {
- $mapping['targetEntity'] = $this->namespace . '\\' . $mapping['targetEntity'];
- }
-
+ $mapping['targetEntity'] = $this->fullyQualifiedClassName($mapping['targetEntity']);
$mapping['targetEntity'] = ltrim($mapping['targetEntity'], '\\');
}
@@ -1917,11 +1914,7 @@ public function getTemporaryIdTableName()
public function setSubclasses(array $subclasses)
{
foreach ($subclasses as $subclass) {
- if (strpos($subclass, '\\') === false && strlen($this->namespace)) {
- $this->subClasses[] = $this->namespace . '\\' . $subclass;
- } else {
- $this->subClasses[] = $subclass;
- }
+ $this->subClasses[] = $this->fullyQualifiedClassName($subclass);
}
}
@@ -2274,11 +2267,9 @@ public function addNamedNativeQuery(array $queryMapping)
$queryMapping['isSelfClass'] = true;
$queryMapping['resultClass'] = $this->name;
-
- } else if (strlen($this->namespace) > 0 && strpos($queryMapping['resultClass'], '\\') === false) {
- $queryMapping['resultClass'] = $this->namespace . '\\' . $queryMapping['resultClass'];
}
+ $queryMapping['resultClass'] = $this->fullyQualifiedClassName($queryMapping['resultClass']);
$queryMapping['resultClass'] = ltrim($queryMapping['resultClass'], '\\');
}
@@ -2317,10 +2308,9 @@ public function addSqlResultSetMapping(array $resultMapping)
$entityResult['isSelfClass'] = true;
$entityResult['entityClass'] = $this->name;
- } else if (strlen($this->namespace) > 0 && strpos($entityResult['entityClass'], '\\') === false) {
- $entityResult['entityClass'] = $this->namespace . '\\' . $entityResult['entityClass'];
}
+ $entityResult['entityClass'] = $this->fullyQualifiedClassName($entityResult['entityClass']);
$resultMapping['entities'][$key]['entityClass'] = ltrim($entityResult['entityClass'], '\\');
$resultMapping['entities'][$key]['isSelfClass'] = $entityResult['isSelfClass'];
@@ -2432,11 +2422,7 @@ protected function _storeAssociationMapping(array $assocMapping)
*/
public function setCustomRepositoryClass($repositoryClassName)
{
- if ($repositoryClassName !== null && strpos($repositoryClassName, '\\') === false
- && strlen($this->namespace) > 0) {
- $repositoryClassName = $this->namespace . '\\' . $repositoryClassName;
- }
- $this->customRepositoryClassName = $repositoryClassName;
+ $this->customRepositoryClassName = $this->fullyQualifiedClassName($repositoryClassName);
}
/**
@@ -2605,10 +2591,7 @@ public function setDiscriminatorMap(array $map)
*/
public function addDiscriminatorMapClass($name, $className)
{
- if (strlen($this->namespace) > 0 && strpos($className, '\\') === false) {
- $className = $this->namespace . '\\' . $className;
- }
-
+ $className = $this->fullyQualifiedClassName($className);
$className = ltrim($className, '\\');
$this->discriminatorMap[$name] = $className;
@@ -3030,4 +3013,17 @@ public function getAssociationsByTargetClass($targetClass)
}
return $relations;
}
+
+ /**
+ * @param string $className
+ * @return string
+ */
+ public function fullyQualifiedClassName($className)
+ {
+ if ($className !== null && strpos($className, '\\') === false && strlen($this->namespace) > 0) {
+ return $this->namespace . '\\' . $className;
+ }
+
+ return $className;
+ }
}
@@ -385,9 +385,8 @@ public function loadMetadataForClass($className, ClassMetadata $metadata)
// Check for JoinTable annotations
if ($associationOverride->joinTable) {
- $joinTable = null;
$joinTableAnnot = $associationOverride->joinTable;
- $joinTable = array(
+ $joinTable = array(
'name' => $joinTableAnnot->name,
'schema' => $joinTableAnnot->schema
);
@@ -421,17 +420,16 @@ public function loadMetadataForClass($className, ClassMetadata $metadata)
$entityListenersAnnot = $classAnnotations['Doctrine\ORM\Mapping\EntityListeners'];
foreach ($entityListenersAnnot->value as $listener) {
+ $listener = $metadata->fullyQualifiedClassName($listener);
if ( ! class_exists($listener)) {
throw new \InvalidArgumentException("Indefined class \"$listener\"");
}
$listener = new \ReflectionClass($listener);
-
foreach ($listener->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
foreach ($this->getMethodCallbacks($method) as $value) {
- list($callback, $event) = $value;
- $metadata->addEntityListener($event, $listener->name, $callback);
+ $metadata->addEntityListener($value[1], $listener->name, $value[0]);
}
}
}
@@ -447,8 +445,7 @@ public function loadMetadataForClass($className, ClassMetadata $metadata)
}
foreach ($this->getMethodCallbacks($method) as $value) {
- list($callback, $event) = $value;
- $metadata->addLifecycleCallback($callback, $event);
+ $metadata->addLifecycleCallback($value[0], $value[1]);
}
}
}
@@ -7,7 +7,7 @@
* @Table(name="company_contracts")
* @InheritanceType("SINGLE_TABLE")
* @DiscriminatorColumn(name="discr", type="string")
- * @EntityListeners({"Doctrine\Tests\Models\Company\ContractSubscriber"})
+ * @EntityListeners({"ContractSubscriber"})
* @DiscriminatorMap({
* "fix" = "CompanyFixContract",
* "flexible" = "CompanyFlexContract",

0 comments on commit 0f081d7

Please sign in to comment.