加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

php – 使用“Neoxygen / Neoclient”作为ServiceProvider Facad

发布时间:2020-12-14 19:36:48 所属栏目:大数据 来源:网络整理
导读:[编辑]:好的,我在测试期间多次更新了这篇文章,现在它正在运行……我在下面给出了正确的代码… [/ EDIT] 从今天早上起,我正在尝试使用“Neoxygen / Neoclient”作为ServiceProvider和Facade进入Laravel 5.1的全新安装 为此,我在composer.json中需要“neoxyge
[编辑]:好的,我在测试期间多次更新了这篇文章,现在它正在运行……我在下面给出了正确的代码… [/ EDIT]

从今天早上起,我正在尝试使用“Neoxygen / Neoclient”作为ServiceProvider和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();
    });
}

接下来,我通过在我的提供程序中包含Full Class并设置别名,在“config / app.php”中注册了ServiceProvider:

'providers' => [ 
...
AppProvidersNeoClientServiceProvider::class
...
],'aliases' => [
...
'NeoClient' => AppNeoClient::class
...
]

我还创建了一个NeoClient类,它扩展了Facade,如下所示:

<?php namespace App;

use IlluminateSupportFacadesFacade;

class NeoClient extends Facade
{
/**
 * Get the registered name of the component.
 *
 * @return string
 */
protected static function getFacadeAccessor() { return 'neoclient'; }
}

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

<?php namespace AppHttpControllers;

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读