Closed vzenix closed 5 years ago
At the end i solve it apply decorators to the services for do the connection, i put the example if someone have the same problem.
Add to [root symfony]/config/services.yaml
Neo4j\Neo4jBundle\Factory\ClientFactory:
alias: neo4j.factory.client
public: true
neo4j.connection.custom:
decorates: neo4j.connection.default
class: GraphAware\Neo4j\Client\Connection\Connection
public: true
arguments:
- 'default'
- '%env(NEO4J_CONNECTION)%'
neo4j.client.custom:
decorates: neo4j.client
class: GraphAware\Neo4j\Client\Client
public: true
# pass the old service as an argument
arguments: ['@neo4j.connection_manager']
Add to [root symfony]/.env and [root symfony]/.env.dist
NEO4J_CONNECTION="http://<username>:<password>@localhost:7474"
Then you need use the new service for clients
/**
* @return \GraphAware\Neo4j\Client\Client
*/
private function getNeo4jClient()
{
return $this->container->get('neo4j.client.custom');
}
You should not do $this->get('neo4j.client');
You should never access the container like this. Use dependency injection instead.
for my part I managed to create a service and that's how I did
src/Service/Antispam
<?php
namespace App\Service\Antispam;
class OCAntispam{
private $text;
public function getText(){
return $this->text;
}
public function setText($text){
if(is_string($text)){
$this->text = $text;
}
}
public function isSpam($text){
return strlen($this->text) < 50;
}
}
config/service.yaml
# add more service definitions when explicit configuration is needed
# please note that last definitions always *replace* previous ones
advert_antispam.antispam:
class: App\Service\Antispam\OCAntispam
public: true
my controller must inherit controller and not AbstractController
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
AdvertController extends Controller{
$antispams = $this->container->get('advert_antispam.antispam');
//$antispam = new OCAntispam;
$text = 'fjfj';
if($antispams->isSpam($text)){
throw new \Exception('Votre texte à été détecté comme un spam');
}
$content = $twig->render('adverter/add.html.twig');
return new Response($content);
}
I hope it will help a person
For me here is how I did
src/Service/Antispam
`<?php
namespace App\Service\Antispam;
class OCAntispam{
private $text;
public function getText(){
return $this->text;
}
public function setText($text){
if(is_string($text)){
$this->text = $text;
}
}
public function isSpam($text){
return strlen($this->text) < 50;
}
}`
services.yaml
`
advert_antispam.antispam: class: App\Service\Antispam\OCAntispam public: true `
in the controller you have to put
$antispams = $this->container->get('advert_antispam.antispam');
Our controller must inherit Controller and not AbstractController.
I hope it will help a person
ServiceNotFoundException
The "neo4j.client" service or alias has been removed or inlined when the container was compiled. You should either make it public, or stop using the container directly and use dependency injection instead.
My composer.json is it:
And my code is it: