semsol / arc2

ARC RDF Classes for PHP
Other
331 stars 92 forks source link

Problem finding AbstractAdapter in mysqliAdapter #140

Closed samuell closed 4 years ago

samuell commented 4 years ago

I get a strange class loading problem.

System info

How to reproduce:

Install ARC2 2.5.0 with composer (e.g.) with:

composer require semsol/arc2 2.5.0 --update-no-dev

Create a database and a user, and give the user privileges to the database:

sudo mysql
> CREATE DATABASE smw;
> CREATE USER smw@localhost IDENTIFIED BY '*******';
> GRANT ALL ON smw.* TO smw@localhost;

Create a test file arc2test.php:

<?php
include_once("vendor/semsol/arc2/ARC2.php");
$store = ARC2::getStore(array(
    'db_host' => '127.0.0.1',
        'db_name' => 'smw',
        'db_user' => 'smw',
        'db_pwd'  => '*******',
        'db_adapter' => 'mysqli',
));
$store->createDBCon();

$isSetUp = $store->isSetUp();

echo "Is set up: " . $isSetUp;

echo "<pre>";
print_r($store);
echo "</pre>";

if ( !$isSetUp ) {
        $store->setUp();
}

(Adapt the database details to details of the database you created earlier).

Run the file in the web browser.

Expected behaviour

The web browser should show a functioning page, with the structure of the store object. The error log should not be populated.

Actual behavior.

The web browser gives a HTTP Error 500.

The error log of Nginx shows:

$ sudo tail -n 0 -f /var/log/nginx/error.log 
2020/03/19 19:03:02 [error] 892#892: *91 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Class 'ARC2\Store\Adapter\AbstractAdapter' not found in /var/www/html/w/vendor/semsol/arc2/src/ARC2/Store/Adapter/mysqliAdapter.php on line 17
PHP message: PHP Stack trace:
PHP message: PHP   1. {main}() /var/www/html/w/arc2test.php:0
PHP message: PHP   2. ARC2_Store->createDBCon() /var/www/html/w/arc2test.php:12
PHP message: PHP   3. ARC2\Store\Adapter\AdapterFactory->getInstanceFor() /var/www/html/w/vendor/semsol/arc2/store/ARC2_Store.php:88
PHP message: PHP   4. require_once() /var/www/html/w/vendor/semsol/arc2/src/ARC2/Store/Adapter/AdapterFactory.php:29" while reading response header from upstream, client: ::1, server: _, request: "GET /w/arc2test.php HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.2-fpm.sock:", host: "localhost"
samuell commented 4 years ago

Closing as duplicate of #132.

One should do:

include_once("vendor/autoload.php"); // CORRECT!

... NOT like the following, as I did above:

include_once("vendor/semsol/arc2/ARC2.php"); // WRONG!
k00ni commented 4 years ago

Hi @samuell, its good that you found a solution to your problem. I am wondering if our documentation about ARC2 setup needs more information about that?

samuell commented 4 years ago

Hi @k00ni , foremost I think the README is missing a link to the documentation in the GitHub wiki. It was only after a while I realized I should check the Wiki for the docs. I think a lot of people will not check the wiki, as most projects are using other ways to host the documentation.

Then, there is the question about whether the classical way should be mentioned, like here. Maybe with a caveat that some classes are not properly loaded that way?