在没有命名空间的情况下调用静态自动加载 class

Calling static autoloaded class without namespace

我想知道是否可以在不通过命名空间 ala laravel?

我意识到这与名称空间的性质冲突,但我主要想像 Laravel 一样使用它们,我可以调用 Example::method('test') 而不是 \example\example\Example::method('test')

在文件的顶部,声明一个创建别名的 use 语句:

use example\example\Example;

Example::method('test'); //resolves to example\example\Example::('test')

您甚至可以使用不同的名称 'as':

use example\example\Example as MyAlias;

MyAlias::method('test'); //resolves to example\example\Example::('test')

有关详细信息,请参阅 http://php.net/manual/en/language.namespaces.importing.php

注意:这不是 laravel 立面的工作方式,但我认为这正是您要寻找的。如果你想要更自动化的东西然后别名你将不得不将一些逻辑合并到你的自动加载器中。