3

Phalcon autoloader is configured in the following way:

$loader = new Phalcon\Loader;
$loader->registerDirs(array(
    '../app/4/controllers/',
    '../app/models/',
    '../app/services',
    '../app/forms/',
    '../app/vendor/'
))->register();

The directory tree is:

app
├───services
│   ├─── PayPalService.php   -   important
└───vendor
    └───PayPal
        ├───Api
        │   └───Amount.php
        │   └───and all other files
        ├───Auth
        ├───Common
        ├───Converter
        ├───Core
        ├───Exception
        ├───Handler
        ├───Rest
        ├───Security
        ├───Transport
        └───Validation

At the beginning of PalPalService.php there is:

use PayPal\Api\Amount;
use PayPal\Api\Details;
use PayPal\Api\Item;
use PayPal\Api\ItemList;
use PayPal\Api\Payer;
use PayPal\Api\Payment;
use PayPal\Api\RedirectUrls;
use PayPal\Api\Transaction;
use PayPal\Rest\ApiContext;

Phalcon autoloader apparently can't find these classes so I get error Undefined class constant 'PayPal'. For other classes that don't use namespaces this autoloader works. What is wrong? How to use PayPal SDK without Composer? I think Phalcon's autoloader should deal with it.

I also tried:

$loader->registerNamespaces(
    array(
        "PayPal" => "../app/vendor/PayPal/"
    )
);

It still doesn't find PayPal classes. I don't want to list each PayPal directory because according to docs Phalcon's autoloader should change namespace separator into directory separator.

Politechniczny
  • 453
  • 3
  • 13

1 Answers1

0

"../app/vendor/PayPal/" should be "../app/vendor/"

$loader->registerNamespaces(
    array(
        "PayPal" => "../app/vendor/"
    )
);
Kevin Kopf
  • 13,327
  • 14
  • 49
  • 66
Fazal Rasel
  • 4,446
  • 2
  • 20
  • 31