neo4jphp:无法实例化抽象类Everyman \ Neo4j \ Transport [英] neo4jphp: Cannot instantiate abstract class Everyman\Neo4j\Transport

查看:74
本文介绍了neo4jphp:无法实例化抽象类Everyman \ Neo4j \ Transport的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

也许是一个简单的问题,但是对我来说,作为Neo4j的入门者是一个障碍.我在应用程序所在的目录中安装了带有composer的neo4jphp.供应商子文件夹已创建,并且下面的everyman/neo4j文件夹可用.对于第一次测试,我使用了示例中的以下代码片段:

maybe a simple question but for me as starter with Neo4j a hurdle. I installed the neo4jphp with composer in the same directory as my application. Vendor-Subfolder has been created and the everyman/neo4j folder below is available. For a first test I used this code snippet from the examples:

spl_autoload_register(function ($className) {

  $libPath = 'vendor\\';  
  $classFile = $className.'.php';
  $classPath = $libPath.$classFile;
  if (file_exists($classPath)) {
    require($classPath);
  }
});

require('vendor/autoload.php'); 

use everyman\Neo4j\Client,
    everyman\Neo4j\Transport;

$client = new Client(new Transport('localhost', 7474));
print_r($client->getServerInfo()); 

我总是对错误error之以鼻

I always stumple upon the error

致命错误:无法实例化抽象类Everyman \ Neo4j \ Transport

Fatal error: Cannot instantiate abstract class Everyman\Neo4j\Transport

Google搜索使我对Josh Adell的评论说

Googling brought me to a comment from Josh Adell stating

您不能实例化Everyman \ Neo4j \ Transport,因为它是一个抽象类.您必须根据需要实例化Everyman \ Neo4j \ Transport \ Curl或Everyman \ Neo4j \ Transport \ Stream

You can't instantiate Everyman\Neo4j\Transport, since it is an abstract class. You must instantiate Everyman\Neo4j\Transport\Curl or Everyman\Neo4j\Transport\Stream depending on your needs

所以我想我只需要将使用声明更改为

So I thought I just need to alter the use-statements to

use everyman\Neo4j\Client,
    everyman\Neo4j\Transport\Curl;

但这无法正常工作,调试表明,自动加载器仅获取"Transport.php",而不是"everyman \ Neo4j \ Transport \ Curl.php".对于"Client.php",它仍然可以正常工作("vendor \ everyman \ Neo4j \ Client.php"),因此我猜测使用说明错误或代码无法处理其他子文件夹结构.

but this doesnt work, debugging shows, that the autoloader only get "Transport.php" instead of "everyman\Neo4j\Transport\Curl.php". For "Client.php" its still working ("vendor\everyman\Neo4j\Client.php") so I am guessing that the use-statement is wrong or the code is not able to handle an additional subfolder-structure.

使用

require('phar://neo4jphp.phar');

require('phar://neo4jphp.phar');

工作正常,但我读到它已被弃用,应该由composer/autoload代替.

works fine but I read that this is deprecated and should be replaced by composer / autoload.

有人提示要更改什么或遇到相同的问题吗?

Anyone has a hint what to change or had the same problem?

感谢您的宝贵时间,Balael

Thanks for your time, Balael

推荐答案

感谢乔希,我正在尝试,但看来我仍然停留在某个地方.我可以使用默认的CURL很好-因此我将代码缩小到了

Thanks Josh, I was trying but it seems I still stuck somewhere. I am fine with using the default CURL - so I shrinked the code down to

require('vendor/autoload.php'); 
   use everyman\Neo4j\Client;
    $client = new Everyman\Neo4j\Client('localhost', 7474);
    print_r($client->getServerInfo());` 

文件夹结构是主要的(这里是文件和内容为composer.json的

The folder structure is main (here are the files and the composer.json with the content

{
   "require": {
      "everyman/Neo4j": "dev-master"
    }
}

,在子文件夹"vendor"中,我们有"autoload.php"和子文件夹Everyman及其相关内容.当我运行文件时,出现

and in the subfolder "vendor" we have the "autoload.php" and the subfolder everyman with the related content. When I run the file I come out with

Fatal error: Class 'Everyman\Neo4j\Client' not found 

当我具有自动加载功能时不会发生.我想我在某个地方犯了一个错误-您能给我一个提示吗?非常感谢,B

which does not happen when I have the autoloadfunction. I guess I made a mistake somewehere - can you give me a hint? Thanks a lot, B

这篇关于neo4jphp:无法实例化抽象类Everyman \ Neo4j \ Transport的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆