在Symfony 1.4中使用名称空间自动加载类 [英] Autoload classes using namespace within Symfony 1.4
问题描述
我想包括phpleague的oauth客户端( https://github.com/thephpleague/oauth2-client )放在我的symfony(1.4)项目上,但它到处都使用名称空间,因此我研究了一种解决方法,并提出了使用Symfony2 Universal自动加载器以及我的projectConfiguration.class.php
I want to include the phpleague's oauth client (https://github.com/thephpleague/oauth2-client) on my symfony (1.4) project, but it's using namespace everywhere, so I looked on a workaround and came up with using Symfony2 Universal autoloader, together with this piece of code in my projectConfiguration.class.php
public function namespacesClassLoader()
{
$loader = new UniversalClassLoader();
$loader->registerNamespaces(array(
'League' => __DIR__ . '/../lib/League',
));
$loader->register();
}
该函数在setup()内部被调用.当我尝试实例化这样的提供程序
That function being called inside the setup(). This doesn't work when I try to instantiate a provider like this
$provider = new League\OAuth2\Client\Provider\Google(array(
'clientId' => '',
'clientSecret' => '',
'redirectUri' => $redirect_url
));
有什么想法吗?
推荐答案
所以很久以前就已解决此问题,但对于有兴趣的人,我只需要更改此内容
So this was fixed long time ago, but for anyone interested I just needed to change this
$loader->registerNamespaces(array(
'League' => __DIR__ . '/../lib/League',
));
对此
$loader->registerNamespaces(array(
'League' => __DIR__ . '/../lib',
));
这篇关于在Symfony 1.4中使用名称空间自动加载类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!