2
votes

I'm trying to integrate a proprietary third-party library into my CakePHP app. All I could find in the manual is the App Class section but it's basically a set of examples rather than a proper explanation so I'm trying to guess.

I got the impression that you should use the App::uses() alternative when possible and at first I thought I was lucky because this code:

App::build(
    array(
        'Vendor' => array(
            APP . 'Vendor' . DS . 'Acme' . DS. 'API-1.0' . DS . 'base',
            APP . 'Vendor' . DS . 'Acme' . DS. 'API-1.0' . DS . 'foo',
            APP . 'Vendor' . DS . 'Acme' . DS. 'API-1.0' . DS . 'bar',
        )
    )
);
debug(App::objects('Vendor'));

... produces this output:

array(
    (int) 0 => 'Autoload',
    (int) 1 => 'ConstantsBase',
    (int) 2 => 'Foo',
    (int) 3 => 'Bar',
)

However, I can't do anything like this:

App::uses('Foo', 'Vendor');
new Foo();

... triggers:

Error: Class 'Foo' not found 

How comes CakePHP does know about the library classes but won't load them?

1
Are you using composer in your project and does the vendor libs support composer as well? - floriank
I see composer.json files all around but I'm not familiar with it. - Álvaro González
Are you familiar with other Package Managers like bower? Composer is pretty similar and is a common tool now in the php world. I would recommend you to use it because it comes with a standard autoloader and you can manage your dependencies through it as well. book.cakephp.org/2.0/en/installation/… - floriank
@burzum I've used Node's npm and Composer is definitively in my todo list. But this particular library is not Composer-friendly. - Álvaro González

1 Answers

0
votes

Apparently, directory paths need to have a trailing slash:

// Incorrect
APP . 'Vendor' . DS . 'Acme' . DS. 'API-1.0' . DS . 'base',

// Correct
APP . 'Vendor' . DS . 'Acme' . DS. 'API-1.0' . DS . 'base' . DS,

It's just mandatory, though its omission doesn't seem to trigger any error message.