Integrating Balanced Payments Php Library (Uses Namespaces) In Yii

I’m trying to integrated the Balanced Payments PHP library (github.com/balanced/balanced-php) into Yii.

The Balanced Payments lib uses PHP class namespaces, which I know is an issue with Yii. I’m trying to load it using the following:

$basePath = Yii::app()->getBasePath();

require_once($basePath . ‘/libraries/Balanced/vendor/httpful/bootstrap.php’);

require_once($basePath . ‘/libraries/Balanced/vendor/restful/bootstrap.php’);

require_once($basePath . ‘/libraries/Balanced/bootstrap.php’);

I’m getting the following error:

Fatal error: Class ‘RESTful\CEvent’ not found in /protected/libraries/Balanced/vendor/restful/src/RESTful/Resource.php on line 10

CEvent is a core Yii class and it’s looking for it in RESTful which is a vendor lib used by Balanced.

I tried using Yii::setPathOfAlias() as documented at yiiframework.com/doc/guide/1.1/en/basics.namespace#namespaced-classes but it did not work.

Can anyone help?

FYI for anyone struggling with importing a library that uses namespaces, this custom autoloader solved it for me: