Jump to content

Archived

This topic is now archived and is closed to further replies.

tarapage

Cakephp App::Import problem (strange behavior) - not loading file with $uses

Recommended Posts

I have an application that uses a PHP Library for FreshBooks which I added as a vendor file under the main vendor directory (not under app/vendor).  I have a method that will load my vendor files as required.  Here is the code:

 

private function __importLib($lib) {

    # Only import the file when it has not been imported already

    if (!isset($this->importedLibs->{$lib})) {

      $file = 'FreshBooks/'.$lib.'.php';

      $lib = strtolower($lib);

      App::import('Vendor', $lib, array('file'=>$file));

 

      # Flag that the library has been imported

      $this->importedLibs->{$lib} = $file;

    }

 

    # Initialize the connection to Fresbooks

    if(!isset($this->importedLibs->{'init'})) {

      $this->__init();

    }

  }

 

  private function __init()

  {

    FreshBooks_HttpClient::init($this->fb_url, $this->fb_token);

    $this->importedLibs->{'init'} = true;

  }

 

Problem

It WORKS if I do not have the $uses variable defined in the controller, but as soon as I add a $uses variable, the code stops working...

 

Fatal error: Class 'FreshBooks_HttpClient' not found in /var/www/streetscape123/app/controllers/components/freshbooks.php on line 435

 

My assumption is that the vendor files were not loaded properly, as it cannot find the call in the vendor file.  Very strange, I have no idea why introducing this variable causes this.  To make it more confusing, other classes in the same library can be loaded with the $uses being set, but this one in particular fails.  The difference here, is that Invoice.php is created based on BaseInvoice.php (and this is what includes the Elements.php file which includes the HttpClient).  The other classes include the Elements.php file directly in their definition class (which includes the HttpClient file).

 

Any ideas at all would be greatly appreciated.

Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.