Semantics3 / semantics3-php

DEPRECATED PHP library bindings for the Semantics3 APIs
MIT License
24 stars 21 forks source link

Class not found Exception: OAuthStore #28

Closed NourEldin275 closed 7 years ago

NourEldin275 commented 7 years ago

I'm getting the following exception:

Attempted to load class "OAuthStore" from the global namespace.
Did you forget a "use" statement?

The error is thrown from vendor/semantics3/semantics3-php/lib/Semantics3/ApiConnector.php at line 23:

OAuthStore::instance("2Leg", $options );

What I'm doing wrong here? I looked into the files of the library and it seems that the OAuthStore is already in the /lib/oauth-php/library/ directory which I think should work but for some reason it is trying to load that class from the global namespace!

Here is the code I've written:

use Semantics3_Products;

class Semantics3Service
{
    /** @var  string $apiKey */
    private $apiKey;

    /** @var  string $apiSecret */
    private $apiSecret;

    /** @var Semantics3_Products $semantic3Requestor */
    private $semantic3Requestor;

    /**
     * Semantics3Service constructor.
     * @param string $apiKey
     * @param string $apiSecret
     */
    public function __construct(string $apiKey, string $apiSecret)
    {
        $this->apiSecret = $apiSecret;
        $this->apiKey    = $apiKey;
        $this->semantic3Requestor = new Semantics3_Products($this->apiKey, $this->apiSecret);
    }

    /**
     * @return array
     */
    public function getProducts(){
        $this->semantic3Requestor->products_field("search", "iphone");
        return $this->semantic3Requestor->get_products();
    }
}
NourEldin275 commented 7 years ago

I was able to fix it by using require_once instead of use. Like so

//use Semantics3_Products;
require_once(__DIR__ . '/../../../../vendor/semantics3/semantics3-php/lib/Semantics3.php');
vinothgopi commented 7 years ago

@NourEldin275 require_once works best but I'd recommend using require if you know that you will not be referencing the library anywhere else. But both work the same.

Closing this issue for now.