frinux
frinux

Reputation: 2092

How to use an external lib? (PclZip)

I'd like to use the PclZip lib in a Magento module. I installed it through my package manager (libphp-pclzip) but I'm not able to use it directly in my module, the Magento autoloader tries to get the class and fails:

Warning: include(PclZip.php): failed to open stream: No such file or directory in /home/frleq/Dev/projets/Compario/magento-community-1.4.2.0/lib/Varien/Autoload.php on line 93

#0 /home/frleq/Dev/projets/Compario/magento-community-1.4.2.0/lib/Varien/Autoload.php(93): mageCoreErrorHandler(2, 'include(PclZip....', '/home/frleq/Dev...', 93, Array)
#1 /home/frleq/Dev/projets/Compario/magento-community-1.4.2.0/lib/Varien/Autoload.php(93): Varien_Autoload::autoload()
#2 [internal function]: Varien_Autoload->autoload('PclZip')
#3 [internal function]: spl_autoload_call('PclZip')
#4 /home/frleq/Dev/projets/Compario/magento-community-1.4.2.0/app/code/community/Compario/Connector/Helper/Data.php(8): class_exists('PclZip')

How can I manage to disable the autoload or make it find my lib?

Thanks!

Upvotes: 2

Views: 5351

Answers (2)

Alana Storm
Alana Storm

Reputation: 166066

See this answer for some ideas on setting up a custom autoloader in Magento that won't conflict with the built in.

Upvotes: 1

Eugene Tulika
Eugene Tulika

Reputation: 713

The quick solution is to add directory with your library to include path:

$includePath = 'path/to/lib';
set_include_path(get_include_path() . PS . $includePath);

One more quick solution:

require_once  'path/to/lib/PclZip.php';

But better solution is to change the name of your lib to be visible to autoloader. It should be inside lib directory, the name of class should consists of words which starts from capital letter and separated by "_". These words should match directory structure of file with class. For example:

'path/to/lib/PclZip.php' => Path_To_Lib_PclZip'

Upvotes: 3

Related Questions