Use of “Neoxygen/Neoclient” as a ServiceProvider+Facade into Laravel 5.1

為{幸葍}努か 提交于 2019-12-06 05:20:37

问题


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


回答1:


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

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

++



来源:https://stackoverflow.com/questions/31452932/use-of-neoxygen-neoclient-as-a-serviceproviderfacade-into-laravel-5-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!