【发布时间】:2013-07-30 18:21:48
【问题描述】:
我构建了一个使用命名空间和 PSR-0 自动加载的 PHP 应用程序。在尝试实现Stripe 库时,我发现它似乎无法加载这些类,因为它们没有命名空间。如果我手动包含文件,有没有办法不自动加载?
// Get Stripe Library
require_once(App\App::$APP_PATH . "/Extensions/Stripe.php");
// Set Key
Stripe::setApiKey($stripe['secret_key']);
在示例中设置密钥失败并出现致命错误,因为它认为当前文件的命名空间中存在Stripe 类。
我发现,如果我在命名空间声明下方添加 use Stripe; 行,它将起作用,但随后在 Stripe 库中的下一个类上失败。
我真的必须添加一个Use Stripe, Stripe_Customer, Stripe_xyz...; 行以让它正确加载文件(其中有超过 25 个文件)还是有更好的方法?
[编辑]
直到我听到是否有更好的方法,我已经这样做了:
// Import Non-Namespaced Stripe Library
use Stripe, Stripe_Account, Stripe_ApiConnectionError, Stripe_ApiError, Stripe_ApiRequestor, Stripe_ApiResource, Stripe_AuthenticationError;
use Stripe_Card, Stripe_CardError, Stripe_Charge, Stripe_Coupon, Stripe_Customer, Stripe_Error, Stripe_Event, Stripe_InvalidRequestError;
use Stripe_Invoice, Stripe_InvoiceItem, Stripe_List, Stripe_Object, Stripe_Plan, Stripe_Recipient, Stripe_SingletonApiResource;
use Stripe_Stripe, Stripe_Token, Stripe_Transfer, Stripe_Util;
【问题讨论】:
标签: php namespaces stripe-payments