Symfony2:与非命名空间的SDK(特别是PayPal)集成 [英] Symfony2: Integrating with a non-namespaced SDK (specifically PayPal)

查看:86
本文介绍了Symfony2:与非命名空间的SDK(特别是PayPal)集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了PaypalBundle,并添加了Paypal merchant-php-sdk 到我的composer.json,现在我有一个vendor\paypal\merchant-php-sdk目录. 但是此SDK没有命名空间,并且看起来不太OOP. 访问这些文件的最佳方法是什么?

I've created a PaypalBundle and added the Paypal merchant-php-sdk to my composer.json and now I've got a vendor\paypal\merchant-php-sdk directory. But this SDK isn't namespaced and doesn't seem very OOP. What's the best way to access these files?

  • 我应该使用require吗?
  • 我应该对autoloading做任何事情吗?
  • Should I use require?
  • Should I do anything with autoloading?

我已经研究了使用类似的AmazonAPI所做的事情,但是Amazon代码通过定义名称空间等对OOP更为友好.

I've looked into the what was done with a similar AmazonAPI but the Amazon code is more OOP friendly with namespaces defined, etc.

步骤1:Composer.json存储库"配置

{
    "type": "package",
    "package": {
        "version": "master",
        "name": "paypal/merchant-php-sdk",
        "source": {
            "url": "https://github.com/paypal/merchant-php-sdk.git",
            "type": "git",
            "reference": "master"
        }
    }
}

推荐答案

您可以使用作曲家 Classmap 正在加载.

You can use Composers Classmap Loading.

{
    "autoload": {
        "classmap": ["src/", "lib/", "Something.php"]
    }
}

OR

如果您想在每个请求中明确要求某些文件,则可以使用文件自动加载机制.

If you want to require certain files explicitly on every request then you can use the files autoloading mechanism.

{
    "autoload": {
        "files": ["src/MyLibrary/functions.php"]
    }
}

这篇关于Symfony2:与非命名空间的SDK(特别是PayPal)集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆