PHP Custom Class,PayPal API,Mailgun API,Easypost API。 他们可以一起工作吗?

I have an ecommerce site that i am building for a client. This site had previously worked perfectly fine using procedural functions and curl to make the calls to Paypal. I download the Mailgun and Easypost API manual and installed manually. DOwn the road, I wanted to update the site to utilize PDO & OOP. I have done a fair job at getting the foundation laid. Now it is time to start making calls to the various API's.I installed everything using composer and currently run a dual autoloader. The composer autoload and then beneath it a custom autoload to load my classes. Now, when I call on the PayPal API, I get the following error:

Fatal error: Class 'Paypal\Rest\ApiContext' not found in /var/www/html/myla-dev/shoppingCartFinalize.php on line 18 

I think what is happening is my autoloader is trying to load this rather than the composers autoloader. Here is where the autoloading is occurring:

init.php

require __DIR__.'/core/functions/general.php';
function autoLoader ($class) {
  if (file_exists(__DIR__.'/core/classes/'.$class.'.php')) {
    require __DIR__.'/core/classes/'.$class.'.php';
  }
}
spl_autoload_register('autoLoader');
require __DIR__.'/vendor/autoload.php';

This file sits in project root directory and is then required at the top of every file.

File Structure

core
--classes
----Alert.php
----....
--functions
----general.php
vendor
--composer
--easypost
--guzzle
--mailgun
--symfony
--paypal
--autoload.php
index.php
init.php
...

composer.json

{
  "repositories": [
    {
      "type": "vcs",
      "url": "https://github.com/EasyPost/easypost-php"
    }
  ],
  "require": {
    "php": ">=5.3.0",
    "easypost/easypost-php": "dev-master",
    "ext-curl": "*",
    "ext-json": "*",
    "paypal/rest-api-sdk-php":"*",
    "mailgun/mailgun-php": "dev-master"
  }
}

Any and all assistance is appreciated. If you feel like writing code, GREAT, but that is not what I am asking for. That is my job, but help with reworking to make it work would be awesome.

Thanks

drv16821
drv16821 您可以拥有多个自动加载器功能。您的自定义自动加载器功能应该不是问题。您总是可以尝试不添加自动加载功能,只需执行一个简单的$test=newPaypal\Rest\ApiContext(),看看会发生什么。我怀疑你的问题是代码18类型的问题。您还可以尝试添加文件夹,以便由作曲家的自动加载器扫描:getcomposer.org/doc/01-basic-usage.md#autoloading
5 年多之前 回复
doulu7258
doulu7258 我现在无法测试,但是我的建议会鼓励我,希望直到明天晚上我有时间继续排除故障。我可以通过将我的classes文件夹和我的供应商与composerautoloader一起放在同一个文件夹中然后在我的init.php文件中需要自动加载器来解决这个问题吗?
5 年多之前 回复
douyan1882
douyan1882 这是我的故障排除过程的第一步。显然它没有用。
5 年多之前 回复
doukuibi9631
doukuibi9631 愚蠢的问题,但你确定100%你实际安装了Paypalapi吗?通过验证文件是否确实存在来进行双重检查。你也可以重新做一个作曲家更新或作曲家dumpautoload来重新生成自动加载。
5 年多之前 回复
duandingqi9442
duandingqi9442 对不起,花了这么久。我昨晚必须上班。使用composer.json文件更新OP。谢谢
5 年多之前 回复
dongyixiu3110
dongyixiu3110 发布你的composer.json文件
5 年多之前 回复

1个回答



它最终成为一个简单的语法错误。 在我转储和更新作曲家后,它仍然无法工作,所以我只是从安装维基中复制了代码。 它起作用所以我把他们的代码编写成我的代码,我在维基的调用中错过了一个反斜杠。 感谢您的帮助。</ p>
</ div>

展开原文

原文

It ended up being a simple syntax error. After I dumped and updated composer it still failed to work, so I just copied the code from the installation wiki. It worked so I composer their code to mine and I was missing a backslash in my call to the wiki. Thank you for your assistance though.

立即提问
相关内容推荐