1
0
mirror of synced 2025-01-09 18:47:10 +03:00

Added NS checking

This commit is contained in:
encoder64 2014-07-27 17:02:19 +03:00
parent 3dc2a68583
commit c04b01cbd7

View File

@ -61,13 +61,27 @@ class <className> extends <repositoryName>
$variables = array( $variables = array(
'<namespace>' => $this->generateEntityRepositoryNamespace($fullClassName), '<namespace>' => $this->generateEntityRepositoryNamespace($fullClassName),
'<repositoryName>' => $this->generateEntityRepositoryName(), '<repositoryName>' => $this->generateEntityRepositoryName($fullClassName),
'<className>' => $className '<className>' => $className
); );
return str_replace(array_keys($variables), array_values($variables), self::$_template); return str_replace(array_keys($variables), array_values($variables), self::$_template);
} }
/**
* Generates the namespace, if class do not have namespace, return empty string instead.
*
* @param string $fullClassName
*
* @return string $namespace
*/
protected function getClassNamespace($fullClassName)
{
$namespace = substr($fullClassName, 0, strrpos($fullClassName, '\\'));
return $namespace;
}
/** /**
* Generates the namespace statement, if class do not have namespace, return empty string instead. * Generates the namespace statement, if class do not have namespace, return empty string instead.
* *
@ -77,19 +91,23 @@ class <className> extends <repositoryName>
*/ */
private function generateEntityRepositoryNamespace($fullClassName) private function generateEntityRepositoryNamespace($fullClassName)
{ {
$namespace = substr($fullClassName, 0, strrpos($fullClassName, '\\')); $namespace = $this->getClassNamespace($fullClassName);
return $namespace ? 'namespace ' . $namespace . ';' : ''; return $namespace ? 'namespace ' . $namespace . ';' : '';
} }
/** /**
* @param string $fullClassName
*
* @return string $repositoryName * @return string $repositoryName
*/ */
protected function generateEntityRepositoryName() protected function generateEntityRepositoryName($fullClassName)
{ {
$namespace = $this->getClassNamespace($fullClassName);
$repositoryName = $this->_repositoryName; $repositoryName = $this->_repositoryName;
if (substr($repositoryName, 0, 1) != '\\') { if ($namespace && $repositoryName[0] !== '\\') {
$repositoryName = '\\' . $repositoryName; $repositoryName = '\\' . $repositoryName;
} }
@ -121,6 +139,7 @@ class <className> extends <repositoryName>
/** /**
* @param string $repositoryName * @param string $repositoryName
*
* @return \Doctrine\ORM\Tools\EntityRepositoryGenerator * @return \Doctrine\ORM\Tools\EntityRepositoryGenerator
*/ */
public function setDefaultRepositoryName($repositoryName) public function setDefaultRepositoryName($repositoryName)