There's a few different ways. I used namespaces.
I registered a namespace of my OAuth2 class
<?php
$loader->registerNamespaces(array(
'App\Backend\Controllers' => '../app/backend/controllers/',
'App\Backend\Models' => '../app/backend/models/',
'PayPal' => '../app/xxx/PayPal/', //I had the oAuth2 class included in paypal class
));
Then in Controller:
<?php
use PayPal\Auth\OAuthTokenCredential; //including OAuthclass
class IndexController extends \Phalcon\Mvc\Controller
{
public function authAction()
{
$oAuthToken = new OAuthTokenCredential(
'hashClientID',
'hashClientSecret'
);
// using some service with oAuth2 token, for example paypal API
$apiContext = new ApiContext($oAuthToken);
$apiContext->setConfig(
array(
//some configurations
)
);
...
...
...
try {
//Create Payment
$payment->create($apiContext);
} catch (Exception $ex) {
//errors
}
}
}