使用"Neoxygen/Neoclient".作为ServiceProvider + Facade进入Laravel 5.1 [英] Use of "Neoxygen/Neoclient" as a ServiceProvider+Facade into Laravel 5.1

查看:112
本文介绍了使用"Neoxygen/Neoclient".作为ServiceProvider + Facade进入Laravel 5.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

:好的,我在测试过程中多次更新了此帖子,现在它可以正常工作了……我在下面输入了正确的代码... [/EDIT]

从今天早上开始,我一直在尝试使用"Neoxygen/Neoclient"作为服务提供商和Facade,将其安装到新的Laravel 5.1新安装中.

为此,我在composer.json中需要"neoxygen/neoclient":"^ 3.0"

然后,我在"app/Providers"中创建了一个名为"NeoClientServiceProvider"的新ServiceProvider.

在其注册方法中;我已实例化连接:

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

接下来,我通过在我的提供程序中包括完整类并设置别名来在"config/app.php"中注册ServiceProvider:

'providers' => [ 
...
App\Providers\NeoClientServiceProvider::class
...
],
'aliases' => [
...
'NeoClient' => App\NeoClient::class
...
]

我还创建了一个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'; }
}

最后我有一个像这样的控制器:

<?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:我知道"NeoEloquent"存在,但我不想使用它……

++

弗雷德.

解决方案

当然可以!这是客户端的链接:

https://github.com/graphaware/neo4j-php-client

++

[EDIT] : OK, i updated this post several times during my tests and now it's working... I let the correct code here below... [/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

For this, I've required "neoxygen/neoclient": "^3.0" in my composer.json

Then I've created a new ServiceProvider into "app/Providers" called "NeoClientServiceProvider".

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 :

'providers' => [ 
...
App\Providers\NeoClientServiceProvider::class
...
],
'aliases' => [
...
'NeoClient' => App\NeoClient::class
...
]

I also created a NeoClient Class who extends Facade like this :

<?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...

++

Fred.

解决方案

Off course You can ! Here's the link of the client :

https://github.com/graphaware/neo4j-php-client

++

这篇关于使用"Neoxygen/Neoclient".作为ServiceProvider + Facade进入Laravel 5.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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