1
votes

I am using an application that I downloaded using Composer.

The package has many classes that can be called and utilized. However, when I run the below code, I am getting the following error.

<?php
error_reporting(E_ALL);
ini_set('display_errors', 'On');

include 'vendor/autoload.php';

$clarifai = new \DarrynTen\Clarifai\Clarifai('CLARIFAI_API_KEY');

$input = new Input();
    $input->setImage('https://samples.clarifai.com/metro-north.jpg')->isUrl();
    $inputResult = $clarifai->getInputRepository()->add($input);

echo json_encode($inputResult);
?>

Error:

Warning: include(/var/www/html/vendor/darrynten/clarifai-php/src/Entity): failed to open stream: Not a directory in /var/www/html/ctest.php on line 7

Warning: include(): Failed opening '/var/www/html/vendor/darrynten/clarifai-php/src/Entity' for inclusion (include_path='.:/usr/share/php') in /var/www/html/ctest.php on line 7

Fatal error: Uncaught Error: Class 'Input' not found in /var/www/html/ctest.php:11 Stack trace: #0 {main} thrown in /var/www/html/ctest.php on line 11

The class Input is located at /var/www/html/vendor/darrynten/clarifai-php/src/Entity which I am including using the include keyword in PHP right after the first include, of no avail.

include 'vendor/autoload.php';
include '/var/www/html/vendor/darrynten/clarifai-php/src/Entity';

Later, I used the following code

$concept = new \DarrynTen\Clarifai\Entity\Concept();
$concept->setId('boscoe')->setValue(true);

$input = new \DarrynTen\Clarifai\Entity\Input();
$input->setImage('https://samples.clarifai.com/puppy.jpeg')->isUrl()
    ->setConcepts([$concept]);

$inputResult = $clarifai->getInputRepository()->add($input);

on the last line, I am getting this error. (Guzzle related)

Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error: POST https://api.clarifai.com/v2/inputs resulted in a 400 Bad Request response: {"status":{"code":10020,"description":"Failure"},"inputs":[{"id":"e25be6bf0a4a4090a774694c016202cb","data":{"image":{"ur (truncated...) in /var/www/html/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:111 Stack trace: #0 /var/www/html/vendor/guzzlehttp/guzzle/src/Middleware.php(65): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response)) #1

Is this also name space related?

2
looks like it thinks Entity is a folder, but you state it contains a class, so presumably it's a file? That would explain the "Not a directory" error. Can this file be renamed to, for example, Entity.php? If it's a PHP file, it would be better to give it the proper extension. AFAIK you can't use include to specify a whole directory either.ADyson
include '/var/www/html/vendor/darrynten/clarifai-php/src/Entity'; - what's this? You're using an autoloader, but you're including a directory. It looks like you mixed up what namespaces do and how autoloading works.Mjh
@Mjh To be honest yes. First time I am doing this.I appreciate honest feedback and any insight on what to dotony9099
Just to confirm, you want to use darrynten/clarafai-php package classes, right?Mjh
First line is fine, you included the autoloader. After that what you do is instantiating each class you need by referencing its namespace. Example: $clarafai = new DarrynTen\Clarifai\Clarafai; -> open the Clarafai.php and look for namespace keyword. When you specify this namespace, autoloader calculates where it is and includes the file(s) for you.Mjh

2 Answers

1
votes

I have found a new PHP library that seems to be compatible with new apps in Clarifai created with the new api_key version: phpfanatic/clarifai

You can easily try to install it via composer:

composer require phpfanatic/clarifai

As dependencies you need to have:

  • PHP - 5.6, 7.0 - May work with ealier version, untested at this time.
  • cURL - *
  • Clarifai API Key - clarifai
  • PHPUnit - to run tests (optional).

Here you can find the full documentation with quick tutorial or step by step explanation.

0
votes

Eddie from Clarifai here. Sorry you ran into an issue.

I see that you are using an API key. This community library currently only supports our old auth mechanism. All new "apps" in Clarifai are only created with an api_key as opposed to client_id and client_secret.

There's currently a PR open to add support for API keys.

We're hoping to have first class PHP support by the end of the year.