Braintree autoload problem

Hi there I try to integrate Braintree but I have difficulties getting their autoload to work. As mention in Yii’s doc:


make sure any 3rd-party class autoloaders are registered before the Yii autoloader:

require_once('PHPUnit/Autoload.php'); // register 3rd-party autoloader

require_once('/path/to/framework/yii.php'); // register Yii autoloader

...



Soo that’s what I did:

index.php




require_once Yii::getPathOfAlias("application.components.Vendors.Braintree.lib.Braintree").".php";

        $yii =  dirname(__FILE__).'/protected/yii/framework/yii.php';

        require_once($yii); 



But I get this

[color="#FF0000"]PHP Fatal error: Class ‘Braintree’ not found in /var/www/xxx/protected/yii/framework/YiiBase.php on line 217[/color]


Braintree.php application.components.Vendors.Braintree.lib.Braintree




<?php

/**

 * Braintree PHP Library

 * Creates class_aliases for old class names replaced by PSR-4 Namespaces

 *

 * @copyright  2015 Braintree, a division of PayPal, Inc.

 */


require_once(__DIR__ . DIRECTORY_SEPARATOR . 'autoload.php');


if (version_compare(PHP_VERSION, '5.4.0', '<')) {

    throw new Braintree_Exception('PHP version >= 5.4.0 required');

}




function requireDependencies() {

    $requiredExtensions = ['xmlwriter', 'openssl', 'dom', 'hash', 'curl'];

    foreach ($requiredExtensions AS $ext) {

        if (!extension_loaded($ext)) {

            throw new Braintree_Exception('The Braintree library requires the ' . $ext . ' extension.');

        }

    }

}

 

requireDependencies();



autoload.php application.components.Vendors.Braintree.lib.autoload




<?php

spl_autoload_register(function ($className) {

   

    if (strpos($className, 'Braintree') !== 0) {

        return;

    }


    $fileName = dirname(__DIR__) . '/lib/';


    if ($lastNsPos = strripos($className, '\\')) {

        $namespace = substr($className, 0, $lastNsPos);

        $className = substr($className, $lastNsPos + 1);

        $fileName  .= str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;

    }


    $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';


    if (is_file($fileName)) {

        require_once $fileName;

    }

});