├── .gitignore ├── .travis.yml ├── README.md ├── composer.json ├── phpunit.xml ├── public └── .gitkeep ├── src ├── Artdarek │ └── Neo4j │ │ ├── Facades │ │ └── Neo4j.php │ │ └── Neo4jServiceProvider.php ├── config │ ├── .gitkeep │ └── config.php ├── lang │ └── .gitkeep ├── migrations │ └── .gitkeep └── views │ └── .gitkeep └── tests └── .gitkeep /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | composer.phar 3 | composer.lock 4 | .DS_Store -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | php: 4 | - 5.3 5 | - 5.4 6 | - 5.5 7 | 8 | before_script: 9 | - curl -s http://getcomposer.org/installer | php 10 | - php composer.phar install --dev 11 | 12 | script: phpunit -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Neo4j Service Provider for Laravel 4 2 | 3 | Neo4j-4-laravel is a simple Neo4j service provider for Laravel 4. It is based on [Neo4jPHP](https://github.com/jadell/neo4jphp) 4 | witch is a PHP library wrapping the Neo4j graph database. The goal of Neo4jPHP is to provide you with access to all the functionality 5 | of the Neo4j REST API via PHP. The goal of Neo4j-4-laravel is to ensure you Neo4jPHP easy integration with Laravel 4. 6 | 7 | --- 8 | 9 | - [Installation](#installation) 10 | - [Registering the Package](#registering-the-package) 11 | - [Configuration](#Configuration) 12 | - [Usage](#usage) 13 | - [More usage examples](#more-usage-examples) 14 | 15 | ## Installation 16 | 17 | Use [composer](http://getcomposer.org) to install this package. 18 | 19 | ``` 20 | $ composer require artdarek/neo4j-4-laravel 21 | ``` 22 | 23 | ### Registering the Package 24 | 25 | Add the Neo4j-4-laravel Service Provider to your config in ``app/config/app.php``: 26 | 27 | ```php 28 | 'providers' => array( 29 | 'Artdarek\Neo4j\Neo4jServiceProvider' 30 | ), 31 | ``` 32 | 33 | ### Configuration 34 | 35 | There are two ways to configure neo4j-4-laravel. You can choose the most convenient way for you. You can put your Neo4j credentials into ``app/config/database.php`` (option 1) file or use package config file which you can be generated through command line by artisan (option 2). 36 | 37 | #### Option 1: Configure neo4j using ``app/config/database.php`` file 38 | 39 | Simply add this code at the end of your ``app/config/database.php`` file: 40 | 41 | ```php 42 | /* 43 | |-------------------------------------------------------------------------- 44 | | Neo4j Databases 45 | |-------------------------------------------------------------------------- 46 | */ 47 | 48 | 'neo4j' => [ 49 | 'default' => [ 50 | 'host' => 'localhost', 51 | 'port' => 7474, 52 | 'username' => null, 53 | 'password' => null, 54 | ], 55 | ], 56 | 57 | ``` 58 | #### Option 2: Configure neo4j using package config file 59 | 60 | Run on the command line from the root of your project: 61 | 62 | ``` 63 | $ php artisan config:publish artdarek/neo4j-4-laravel 64 | ``` 65 | 66 | Set your neo4j-4-laravel credentials in ``app/config/packages/artdarek/neo4j-4-laravel/config.php`` 67 | 68 | ```php 69 | return array( 70 | 71 | /* 72 | |-------------------------------------------------------------------------- 73 | | Neo4j Config 74 | |-------------------------------------------------------------------------- 75 | */ 76 | 'default' => array( 77 | 78 | /** 79 | * Host 80 | */ 81 | 'host' => 'localhost', 82 | 83 | /** 84 | * Port 85 | */ 86 | 'port' => 7474, 87 | 88 | /** 89 | * Credentials 90 | */ 91 | 'username' => null, 92 | 'password' => null 93 | 94 | ), 95 | ); 96 | ``` 97 | 98 | ## Usage 99 | 100 | Nodes are the first of the two major entity types in a graph database. 101 | A node is a collection of zero or more key-value pairs. 102 | Neo4jPHP makes it very easy to create and work with nodes. 103 | 104 | ### Creating new node 105 | 106 | The following code snippet creates some nodes, sets some properties on each, and saves the nodes to the server. 107 | 108 | ```php 109 | 110 | $arthur = Neo4j::makeNode(); 111 | $arthur->setProperty('name', 'Arthur Dent') 112 | ->setProperty('mood', 'nervous') 113 | ->setProperty('home', 'small cottage') 114 | ->save(); 115 | 116 | $ford = Neo4j::makeNode(); 117 | $ford->setProperty('name', 'Ford Prefect') 118 | ->setProperty('occupation', 'travel writer') 119 | ->save(); 120 | 121 | $arthurId = $arthur->getId(); 122 | 123 | ``` 124 | 125 | ### Retrieve a Node by ID and Update 126 | 127 | Now that the node has been created, the node's id can be used to retrieve the node from the server later. 128 | The following code retrieves the node and prints its properties: 129 | 130 | ```php 131 | 132 | $character = Neo4j::getNode($arthurId); 133 | 134 | foreach ($character->getProperties() as $key => $value) { 135 | echo "$key: $value\n"; 136 | } 137 | 138 | // prints: 139 | // name: Arthur Dent 140 | // mood: nervous 141 | // home: small cottage 142 | 143 | $character->removeProperty('mood') 144 | ->setProperty('home', 'demolished') 145 | ->save(); 146 | 147 | foreach ($character->getProperties() as $key => $value) { 148 | echo "$key: $value\n"; 149 | } 150 | 151 | // prints: 152 | // name: Arthur Dent 153 | // home: demolished 154 | 155 | ``` 156 | 157 | ### Delete a Node 158 | 159 | A node can be deleted as long as its ID has been set. 160 | Also note that a node cannot be deleted if it is the start or end point of any relationship. 161 | 162 | ```php 163 | 164 | $earth = Neo4j::getNode(123); 165 | $earth->delete(); 166 | 167 | ``` 168 | 169 | ### More usage examples 170 | 171 | Go to [Neo4jPHP Wiki](https://github.com/jadell/neo4jphp/wiki) to find more usage examples. 172 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "artdarek/neo4j-4-laravel", 3 | "type": "library", 4 | "description": "Neo4j for Laravel 4.", 5 | "keywords": ["Neo4j","Database","laravel","laravel4","Service provider","neo4jphp"], 6 | "homepage": "https://github.com/artdarek/neo4j-4-laravel", 7 | "license": "MIT", 8 | "authors": [ 9 | { 10 | "name": "Artdarek", 11 | "email": "artdarek@gmail.com", 12 | "role": "Developer" 13 | } 14 | ], 15 | "require": { 16 | "php": ">=5.3.0", 17 | "everyman/neo4jphp":"dev-master" 18 | }, 19 | "require-dev": { 20 | "illuminate/support": "4.0.*" 21 | }, 22 | "autoload": { 23 | "classmap": [ 24 | "src/migrations" 25 | ], 26 | "psr-0": { 27 | "Artdarek\\Neo4j": "src/" 28 | } 29 | }, 30 | "minimum-stability": "dev" 31 | } -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 15 | ./tests/ 16 | 17 | 18 | -------------------------------------------------------------------------------- /public/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/artdarek/neo4j-4-laravel/c3b257002b02235f21be1dd83d59f5895f1b85a3/public/.gitkeep -------------------------------------------------------------------------------- /src/Artdarek/Neo4j/Facades/Neo4j.php: -------------------------------------------------------------------------------- 1 | package('artdarek/neo4j-4-laravel'); 25 | } 26 | 27 | /** 28 | * Register the service provider. 29 | * 30 | * @return void 31 | */ 32 | public function register() 33 | { 34 | // Register 'neo4j' instance container to our 'neo4j' object 35 | $this->app['neo4j'] = $this->app->share(function($app) 36 | { 37 | 38 | // connection credentials loaded from config 39 | 40 | // if neo4j key exists in database.php config use this one 41 | if ( Config::get('database.neo4j') != null ) { 42 | $host = Config::get('database.neo4j.default.host'); 43 | $port = Config::get('database.neo4j.default.port'); 44 | $username = Config::get('database.neo4j.default.username'); 45 | $password = Config::get('database.neo4j.default.password'); 46 | 47 | // esle try to find config in packages configs 48 | } else { 49 | $host = Config::get('neo4j-4-laravel::default.host'); 50 | $port = Config::get('neo4j-4-laravel::default.port'); 51 | $username = Config::get('neo4j-4-laravel::default.username'); 52 | $password = Config::get('neo4j-4-laravel::default.password'); 53 | } 54 | 55 | // create mew neo4j node 56 | $neo4j = new Client($host,$port); 57 | $neo4j->getTransport()->setAuth($username, $password); 58 | 59 | // return pusher 60 | return $neo4j; 61 | 62 | }); 63 | 64 | 65 | // Shortcut so developers don't need to add an Alias in app/config/app.php 66 | $this->app->booting(function() 67 | { 68 | $loader = AliasLoader::getInstance(); 69 | $loader->alias('Neo4j', 'Artdarek\Neo4j\Facades\Neo4j'); 70 | }); 71 | 72 | } 73 | 74 | /** 75 | * Get the services provided by the provider. 76 | * 77 | * @return array 78 | */ 79 | public function provides() 80 | { 81 | return array(); 82 | } 83 | 84 | } -------------------------------------------------------------------------------- /src/config/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/artdarek/neo4j-4-laravel/c3b257002b02235f21be1dd83d59f5895f1b85a3/src/config/.gitkeep -------------------------------------------------------------------------------- /src/config/config.php: -------------------------------------------------------------------------------- 1 | array( 11 | 12 | /** 13 | * Host 14 | */ 15 | 'host' => 'localhost', 16 | 17 | /** 18 | * Port 19 | */ 20 | 'port' => 7474, 21 | 22 | /** 23 | * Credentials 24 | */ 25 | 'username' => null, 26 | 'password' => null 27 | 28 | ), 29 | 30 | ); -------------------------------------------------------------------------------- /src/lang/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/artdarek/neo4j-4-laravel/c3b257002b02235f21be1dd83d59f5895f1b85a3/src/lang/.gitkeep -------------------------------------------------------------------------------- /src/migrations/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/artdarek/neo4j-4-laravel/c3b257002b02235f21be1dd83d59f5895f1b85a3/src/migrations/.gitkeep -------------------------------------------------------------------------------- /src/views/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/artdarek/neo4j-4-laravel/c3b257002b02235f21be1dd83d59f5895f1b85a3/src/views/.gitkeep -------------------------------------------------------------------------------- /tests/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/artdarek/neo4j-4-laravel/c3b257002b02235f21be1dd83d59f5895f1b85a3/tests/.gitkeep --------------------------------------------------------------------------------