4
votes

Short version

Where does the Client class look for the DispatchableInterface interface?

class Client implements Libraries\Stdlib\DispatchableInterface

I'm trying to add the ZF2 libraries to a CodeIgniter installation. The whole Zend folder sits in:

 /Users/stef/Sites/site_name/application/libraries/

In my CI controller I have

public function run()
{
    $CI =& get_instance();
    $CI->load->library('Zend');
    $CI->load->library('Zend/Http/Client');
    $client = new Client($url);

    //Do stuff
}

When I access the run() method I get a fatal error:

Fatal error: Interface 'Zend\Stdlib\DispatchableInterface' not found in /Users/stef/Sites/site_name/application/libraries/Zend/Http/Client.php on line 27

In libraries/Zend.php (a file I added, not part of the ZF) I have

function __construct($class = NULL)
{
    // include path for Zend Framework
    // alter it accordingly if you have put the 'Zend' folder elsewhere
    ini_set('include_path',ini_get('include_path') . PATH_SEPARATOR . APPPATH . 'libraries/Zend/');
    }

It doesn't seem to matter what I set the include_path to be, even when I put bogus values the fatal error stays the same. So it seems that the loading of the interface DispatchableInterface doesn't make use of the include_path.

How can I get Client.php to "find" the interface, which it tries to do so here:

class Client implements Libraries\Stdlib\DispatchableInterface
1

1 Answers

3
votes

Least difficult solution is probably:

set_include_path(get_include_path() . PATH_SEPARATOR . '/Users/stef/Sites/site_name/application/libraries/');
require_once 'Zend/Loader/StandardAutoloader.php';
$loader = new Zend\Loader\StandardAutoloader(array('autoregister_zf' => true));
$loader->register();

Then skip the CI->load part. And just use new Zend\Http\Client. Also make sure that the dispatchable interface is in /Users/stef/Sites/site_name/application/libraries/Zend/Stdlib/DispatchableInterface.php

Update: I noticed just now:

class Client implements Libraries\Stdlib\DispatchableInterface

What class is this? Is it Zend's class? I guess it's some class of yours. And you're adding wrongly namespaced interface. IMO it should be \Zend\Stdlib\DispatchableInterface