Using Zend Library in a Package

Permalink
I'm building a Concrete5 package from scratch to try and learn the in's and out's of Concrete5 - doing has always been the best way for me to learn - and I have run into a problem with including the GData portion of the Zend Framework in my package.

I have added the library here following Concrete5's folder convention: /packages/my_package/libraries/3rdparty/Zend/...

I call the library from my model using: Loader::library('3rdparty/Zend/Gdata', 'my_package');

This results in an include within Gdata.app producing an error stating that an internal Zend/Gdata/App include failed because the Zend/Gdata/App.php file could not be found. Preceding my first load-library call with another one to include the App.php file results in a similar error looking for the Zend/Gdata/Feed.php file and upon also pre-pending that load-library call with one to load the Feed.php file I get another error looking from the Gdata.php file from the Feed.php file.

So if you follow all that, you will notice that I will never actually be able to manually pre-load all the required Gdata files, as an infinite loop of references is encountered that can't be solved using the above method of manually pre-loading all required Zend library files.

My guess is that because each of these internal includes is using a standard php include, the custom package is not being searched for the files as they obviously don't have the ability to specify a Concrete5 package file like the Loader::library() method call.

If I move the zend library to the root library folder of the Concrete5 installation, everything works fine leading me to believe that either Concrete5 is able to somehow direct standard include files to that directory, or the root library folder has been placed in the php include path.

So, finally for my questions:

Am I missing something in my understanding/implementation of the Loader::library() call?

Is there a way within Concrete to handle a situation where a 3rd party library has internal includes pointing to 'itself' using standard PHP includes?

Should I just try adding the package/library/3rdparty/ folder to the PHP include path?

Any other answers to questions I didn't think to ask?

Thanks so much in advance for any help rendered!

dwhillier
 
Remo replied on at Permalink Reply
Remo
try to avoid using the zend loader, it's already included in c5 but since parts of the zend library are in the core and some in your package things can get messed up very quickly.

I always loaded each file I needed from the zend library manually. You'll need to specify a few Loader::library statements..
dwhillier replied on at Permalink Best Answer Reply
dwhillier
Thanks for the response Remo!

I managed to figure out how to get it to work.

I was initially trying to load all the necessary components up front, but it wasn't working for some reason - I kept getting circular include reference errors from Zend internal includes (difficult to explain)

Turns out I had to do the following (I imagine there are other ways):

- add the libraries folder of my package to the php class path from my model class that retrieves google data using the Zend gData package
- only include the extra Zend packages/files not already included by concrete in the core
- put my Zend package folder directly in the libraries folder (everything in my package is technically 3rd party anyway) so that php doesn't get messed up searching for the files in the concrete5 root or core library 3rd party folders since my package library folder is added to the php include path after the concrete5 root and core library 3rd party folders (don't exactly understand the why behind this)

So the path to the Zend package folder in my package is now: ~/packages/my_package/libraries/Zend

And the code I am using to successfully invoke the calendar library (for instance) is:

// add my_package libraries folder to the include path so Zend internal includes can resolve correctly
      ini_set("include_path", get_include_path() . ':' . DIR_PACKAGES . '/my_package/libraries');
      // load the initial google calendar library from my package
      Loader::library('Zend/Gdata/Calendar', 'my_package');


So I now have what I need working solely from within my package without having to rely on files in the root libraries folder.