[英]Use of “Neoxygen/Neoclient” as a ServiceProvider+Facade into Laravel 5.1
[EDIT] : OK, i updated this post several times during my tests and now it's working... I let the correct code here below... [/EDIT] [编辑]:好的,我在测试期间多次更新了这篇文章,现在它正在运行......我在下面给出了正确的代码... [/ EDIT]
Since this morning, i'm trying to use "Neoxygen/Neoclient" as a ServiceProvider and a Facade into a new fresh installation of Laravel 5.1 从今天早上起,我正在尝试使用“Neoxygen / Neoclient”作为ServiceProvider和Facade进入Laravel 5.1的全新安装
For this, I've required "neoxygen/neoclient": "^3.0" in my composer.json 为此,我在composer.json中需要“neoxygen / neoclient”:“^ 3.0”
Then I've created a new ServiceProvider into "app/Providers" called "NeoClientServiceProvider". 然后我在“app / Providers”中创建了一个名为“NeoClientServiceProvider”的新ServiceProvider。
In its register method; 在其登记方法; I've instantiated the connection : 我已经实例化了连接:
public function register()
{
$this->app->singleton('neoclient', function ($app) {
return ClientBuilder::create()
->addConnection('default', 'http', env('NEO4J_HOST'), intval(env('NEO4J_PORT')), true, env('NEO4J_USER'), env('NEO4J_PASSWORD'))
->setDefaultTimeout( intval(env('NEO4J_TIMEOUT')) )
->setAutoFormatResponse(true)
->build();
});
}
Next, I've registered the ServiceProvider in "config/app.php" by including the Full Class in my providers and by setting an alias : 接下来,我通过在我的提供程序中包含Full Class并设置别名,在“config / app.php”中注册了ServiceProvider:
'providers' => [
...
App\Providers\NeoClientServiceProvider::class
...
],
'aliases' => [
...
'NeoClient' => App\NeoClient::class
...
]
I also created a NeoClient Class who extends Facade like this : 我还创建了一个NeoClient类,它扩展了Facade,如下所示:
<?php namespace App;
use \Illuminate\Support\Facades\Facade;
class NeoClient extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor() { return 'neoclient'; }
}
And Finally I have a Controller like this : 最后我有一个像这样的控制器:
<?php namespace App\Http\Controllers;
use NeoClient;
class GenreController extends Controller
{
public function __construct()
{
// needed authentication
//$this->middleware('oauth');
}
public function create()
{
$data = NeoClient::sendCypherQuery("MATCH (g:Genre) RETURN COUNT(g) AS total")->getRows();
return response()->json($data);
}
}
PS : I know "NeoEloquent" exists but I don't want to use this one... PS:我知道“NeoEloquent”存在,但我不想使用这个......
++ ++
Fred. 弗雷德。
Off course You can ! 当然你可以! Here's the link of the client : 这是客户的链接:
https://github.com/graphaware/neo4j-php-client https://github.com/graphaware/neo4j-php-client
++ ++
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.