Olivier
Olivier

Reputation: 3471

Autoload a namespaced (PSR-0) directory of classes in CakePHP?

I'm trying to import Assetic (https://github.com/kriswallsmith/assetic) classes.

Managed to do the ugly :

App::import('Vendor', 'LessphpFilter', array('file' => 'assetic' . DS . 'src' . DS . 'Assetic' . DS . 'Filter' . DS . 'LessphpFilter.php'));

But it crashes on a sub-required file.

Any idea how to do achieve this in a clean way?

Upvotes: 2

Views: 366

Answers (1)

daniel.auener
daniel.auener

Reputation: 1294

I had similar issues a couple of weeks ago and haven't found a really clean/satisfying way to do this. But I managed to solve problems with sub-required files by adding paths to the include path before the import. Like so:

$pathExtra = APP.'Vendor'.DS.PATH_SEPARATOR.APP.'Vendor'.DS.'pear'.DS;
$path = ini_get('include_path');
$path = $pathExtra . PATH_SEPARATOR . $path;
ini_set('include_path', $path);
App::import('Vendor', 'consumer', array('file' => 'Auth'.DS.'OpenID'.DS.'Consumer.php'));

Upvotes: 1

Related Questions