【问题标题】:Autoload classes using namespace within Symfony 1.4在 Symfony 1.4 中使用命名空间自动加载类
【发布时间】:2014-03-30 20:58:51
【问题描述】:

我想在我的 symfony (1.4) 项目中包含 phpleague 的 oauth 客户端 (https://github.com/thephpleague/oauth2-client),但它到处都在使用命名空间,所以我寻找了一种解决方法,并想出了使用 Symfony2 Universal 自动加载器,连同这块我的 projectConfiguration.class.php 中的代码

 public function namespacesClassLoader() 
 {
   $loader = new UniversalClassLoader();
   $loader->registerNamespaces(array(
        'League' => __DIR__ . '/../lib/League',
    ));
   $loader->register();
 }

该函数在 setup() 中被调用。当我尝试实例化这样的提供程序时,这不起作用

$provider = new League\OAuth2\Client\Provider\Google(array(
            'clientId' => '',
            'clientSecret' => '',
            'redirectUri' => $redirect_url
        ));

有什么想法吗?

【问题讨论】:

    标签: php namespaces symfony-1.4 autoload


    【解决方案1】:

    所以这是很久以前修复的,但对于任何感兴趣的人,我只需要更改它

    $loader->registerNamespaces(array(
        'League' => __DIR__ . '/../lib/League',
    ));
    

    到这里

    $loader->registerNamespaces(array(
        'League' => __DIR__ . '/../lib',
    ));
    

    【讨论】:

      猜你喜欢
      • 2011-09-09
      • 2015-07-30
      • 1970-01-01
      • 2017-11-03
      • 2021-06-29
      • 2013-05-16
      • 2012-09-05
      • 2010-11-24
      • 2016-07-01
      相关资源
      最近更新 更多