Closed mrtnzlml closed 8 years ago
What about to preserve class names when no namespace is passed to class constructor?
It would be satisfactory i guess. Namespace doesn't change anyway in this particular case. In other words it means return name immediately if there is no namespace (passed through constructor), right? If so, I'll prepare PR.
I already have PR :)
It's much more better than my naive implementation. Thank you.
@mrtnzlml @dg due to this change I am unable to extend a class with another class on a separate namespace. the only workaround is to use the full namespace after the extends keyword (which sucks :/).
I'm on v2.6 since I need php 5.6 support.
Example:
namespace App\Http\Controllers\Users;
use App\Http\Controllers\Controller;
class UserController extends \Controller
{
}
Why not?
$namespace = new PhpNamespace('Foo');
$class = $namespace->addClass('A');
$class->addExtend('B');
echo $namespace;
generates
namespace Foo;
class A extends \B
{
}
or
$namespace = new PhpNamespace('Foo');
$namespace->addUse('B');
$class = $namespace->addClass('A');
$class->addExtend('B');
echo $namespace;
generates
namespace Foo;
use B;
class A extends B
{
}
Due to this commit (https://github.com/nette/php-generator/commit/6e1b2935dae0b505aa56d1c31b725f0f69e42d83) it's not possible to generate namespace with leading backslash. I know it was intended, but unfortunately it can be BC break. For example Kdyby\AOP generates class namespaces with leading backslash, but classes are in custom block namespace and if the leading \ is removed, it generates nonsense:
It would be great to preserve leading \ (example why). Should I prepare PR or it's completely wrong approach and should it be fixed in Kdyby?
Suggested behavior (PhpNamespace.phpt:13):