2

I have som legacy code that broke after an update of a dependency class of my ex colleague's Handler class of the Cosenary Instagram Class using composer.

The former reference to include the class in the handler class was this:

namespace Acme\Instagram;
class Handler
{ 

/* GOT SOME USEFUL VARS HERE */

const API_URL = 'https://api.instagram.com/v1';

/**
 * Initialize the library
 *
 * @param array  $settings Contains our ClientId and upload dir
 * @param string $root_dir The root of our application
 */
public function __construct( $settings, $root_dir = __DIR__ )
{
    include_once  $root_dir . '/vendor/cosenary/instagram/instagram.class.php'; //HERE WAS THE INCLUDE BEFORE


    // THROW SOME EXCEPTIONS HERE IF SETTINGS MISSING ETC...

    // New instance of the instagram class
    $this->_instagram = new \Instagram($this->_clientId);
}

/* HANDLE SOM FUNCTIONS HERE */

}

And if I change the include_once to:

    require_once $root_dir . '/vendor/cosenary/instagram/src/Instagram.php';

Then I get:

Fatal error: Class 'Acme\Instagram\Instagram' not found in

I guess I need to pass it in as a reference in the constructor but that means I need to rewrite a lot of code and there is probably 5-10 other projects that is depending on this Hanlder class. Is there a way to use the instagram class in this other class?

Tried moving out the include_once and:

use MetzWeb\Instagram\Instagram;

But no luck, any help or pointers i greatly appreciated.

1 Answer 1

1

I'm not sure how is Your app's structure looks. But try this:

namespace Acme\Instagram;

require_once $root_dir.'/vendor/autoload.php';

use MetzWeb\Instagram\Instagram AS InstagramClient;

class Handler
{ 

/* GOT SOME USEFUL VARS HERE */

const API_URL = 'https://api.instagram.com/v1';

/**
 * Initialize the library
 *
 * @param array  $settings Contains our ClientId and upload dir
 * @param string $root_dir The root of our application
 */
public function __construct( $settings, $root_dir = __DIR__ )
{
    // New instance of the instagram class
    $this->_instagram = new InstagramClient($this->_clientId);
}

/* HANDLE SOM FUNCTIONS HERE */
Sign up to request clarification or add additional context in comments.

2 Comments

I get Fatal error: Namespace declaration statement has to be the very first statement in the script in... If I use it before the namespace declaration.
Nice, got it working again. With some other issues though. But seems to be another problem. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.