2014-10-26 47 views
0

也許是一個簡單的問題,但對於我來說,作爲Neo4j的首發者,一個障礙。我使用作曲家將neo4jphp安裝在與我的應用程序相同的目錄中。供應商子文件夾已創建,下面的everyman/neo4j文件夾可用。對於第一次測試我使用的例子此代碼段:neo4jphp:無法實例化抽象類Everyman Neo4j Transport

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()); 

我總是stumple一旦誤差

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

谷歌搜索給我帶來了喬什Adell的評論指出

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

所以我想我只需要改變使用說明

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

但這不起作用,調試顯示,自動裝載機只獲得「Transport.php」而不是「everyman \ Neo4j \ Transport \ Curl.php」。對於「Client.php」它仍然在工作(「vendor \ everyman \ Neo4j \ Client.php」),所以我猜測use-statement是錯誤的或代碼無法處理額外的子文件夾結構。

使用

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

工作正常,但我讀了不贊成這種方式,應該由作曲家/自動加載所取代。

任何人都有一個提示什麼改變或有同樣的問題?

感謝您的時間, Balael

回答

1

謝謝喬希,我試圖,但似乎我仍然卡在某個地方。我很好的使用默認的捲曲 - 所以我收縮的代碼到

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

的文件夾結構是主要的(這裏的文件和作曲家。JSON與內容

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

和子文件夾「供應商」,我們有「autoload.php」,並與相關內容的子文件夾普通人。當我運行文件我出來

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

當我有自動加載功能,這不會發生。我想我在某個地方犯了一個錯誤 - 你能給我一個提示嗎? 非常感謝,B

+0

啊,似乎我的作曲家設置不正確,我已經重做了設置,現在它的工作正常。 – Balael 2014-10-27 16:44:13

0

嗯...我只是想周圍,似乎不需要在使用語句和類的實例化的交通運輸類。這似乎工作:

require('vendor/autoload.php'); 

    use everyman\Neo4j\Client; 

$client = new Client(); 
print_r($client->getServerInfo()); 

也適用於具有專用的服務器/端口:

$client = new Everyman\Neo4j\Client('localhost', 7474); 

如果您有更多的投入我會很樂意瞭解更多 - 感謝,所有的輸入&的想法是非常讚賞。

Balael

1

Curl是默認傳輸。如果您想使用Stream而不是Curl,則只需實例化自己的Transport對象。如果你真的想要實例自己捲曲運輸,以現有的代碼最簡單的變化是修改使用的語句是:

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

而且,你並不需要,如果你是註冊自己的自動加載功能使用Composer軟件包。 vendor/autoload.php是爲你做的。