Added NS checking
This commit is contained in:
parent
3dc2a68583
commit
c04b01cbd7
@ -61,13 +61,27 @@ class <className> extends <repositoryName>
|
||||
|
||||
$variables = array(
|
||||
'<namespace>' => $this->generateEntityRepositoryNamespace($fullClassName),
|
||||
'<repositoryName>' => $this->generateEntityRepositoryName(),
|
||||
'<repositoryName>' => $this->generateEntityRepositoryName($fullClassName),
|
||||
'<className>' => $className
|
||||
);
|
||||
|
||||
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.
|
||||
*
|
||||
@ -77,19 +91,23 @@ class <className> extends <repositoryName>
|
||||
*/
|
||||
private function generateEntityRepositoryNamespace($fullClassName)
|
||||
{
|
||||
$namespace = substr($fullClassName, 0, strrpos($fullClassName, '\\'));
|
||||
$namespace = $this->getClassNamespace($fullClassName);
|
||||
|
||||
return $namespace ? 'namespace ' . $namespace . ';' : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $fullClassName
|
||||
*
|
||||
* @return string $repositoryName
|
||||
*/
|
||||
protected function generateEntityRepositoryName()
|
||||
protected function generateEntityRepositoryName($fullClassName)
|
||||
{
|
||||
$namespace = $this->getClassNamespace($fullClassName);
|
||||
|
||||
$repositoryName = $this->_repositoryName;
|
||||
|
||||
if (substr($repositoryName, 0, 1) != '\\') {
|
||||
if ($namespace && $repositoryName[0] !== '\\') {
|
||||
$repositoryName = '\\' . $repositoryName;
|
||||
}
|
||||
|
||||
@ -121,6 +139,7 @@ class <className> extends <repositoryName>
|
||||
|
||||
/**
|
||||
* @param string $repositoryName
|
||||
*
|
||||
* @return \Doctrine\ORM\Tools\EntityRepositoryGenerator
|
||||
*/
|
||||
public function setDefaultRepositoryName($repositoryName)
|
||||
|
Loading…
Reference in New Issue
Block a user