PHP code example of misteio / neo4j-bundle

1. Go to this page and download the library: Download misteio/neo4j-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

misteio / neo4j-bundle example snippets




namespace Name\NameBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity()
 */
class YourEntityClassName
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;


    /**
     * Set id
     *
     * @param integer $id
     * @return Id
     */
    public function setId($id)
    {
        $this->id = $id;

        return $this;
    }


    /**
     * @var string
     *
     * @ORM\Column(name="name", type="string", length=255)
     */
    protected $name;



    /**
     * Get id
     *
     * @return integer
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set name
     *
     * @param string $name
     * @return City
     */
    public function setName($name)
    {
        $this->name = $name;

        return $this;
    }

    /**
     * Get name
     *
     * @return string
     */
    public function getName()
    {
        return $this->name;
    }
}



    $client     = $this->getContainer()->get('misteio.neo4j.helper')->getClient('graphenedb');
    $result     = $client->run("Match (n:FakeEntity) RETURN n;");
    $nodes      = $result->getRecords();



namespace Name\NameBundle\EventListener;

use Misteio\Neo4jBundle\Event\Neo4jEvent;

class Neo4jListener
{
    /**
     * @param Neo4jEvent $event
     */
    public function onNeo4jEntityAction(Neo4jEvent $event)
    {
        //Action can be persist, update and delete
        $action = $event->getAction();
        //Your Doctrine Entity
        $entity = $event->getEntity();
    }
}
 php
public function registerBundles()
{
    return array(
        // ...
        new Misteio\Neo4jBundle\MisteioNeo4jBundle(),
        // ...
    );
}
 php

namespace Name\NameBundle\Entity\Transformer\EntityTransformer;
use Misteio\Neo4jBundle\Helper\Neo4jHelper;
use Name\NameBundle\Entity\YourEntityClassName;

class YourTransformerClassName
{
     /** @var  Neo4jHelper */
        private $neo4jHelper;
    
        /**
         * @param Neo4jHelper $neo4jHelper
         */
        public function setNeo4jHelper(Neo4jHelper $neo4jHelper)
        {
            $this->neo4jHelper = $neo4jHelper;
        }
    
        /**
         * @param FakeEntity $fake
         * @param $connectionName
         * @return bool
         */
        public function transform(FakeEntity $fake, $connectionName)
        {
            $this->neo4jHelper->getClient($connectionName)->run('CREATE (n:FakeEntity {id :{id}, name:{name}} )', ['id' => $fake->getId(), 'name' => $fake->getName()]);
    
            return true;
        }
}