Download the PHP package giudicelli/neo4j-php-ogm without Composer

On this page you can find all versions of the php package giudicelli/neo4j-php-ogm. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package neo4j-php-ogm

Tests

Neo4j PHP OGM

This a complete redevelopment of a Neo4j PHP OGM. It was inspired by GraphAware Neo4j PHP OGM, although it doesn't support nearly as many features as Graphaware's OGM does. Redeveloping a full Doctrine compatible OGM would be too much work. But as features are added it will come close to it.

A few features from Doctrine are being used, such as parsing and caching annotations.

It uses Laudis Neo4j PHP Client which is the only PHP client recommended by Neo4j.

This bundle supports lazy loading for entities and collections.

Table of Contents

  1. Installation
  2. Example
  3. Documentation
    1. Model
    2. Annotations
      1. @OGM/Entity
      2. @OGM/Relationship
      3. @OGM/Id
      4. @OGM/StartEntity
      5. @OGM/EndEntity
      6. @OGM/Property
      7. @OGM/Convert
      8. @OGM/QueryResult
      9. @OGM/Relation
    3. Repository
    4. Events
      1. NodeCreatedEvent
      2. NodeUpdatedEvent
      3. NodeDeletedEvent
      4. NodeLoadedEvent
  4. FAQ
    1. How do I query a node by its Neo4j id?
    2. Can I filter nodes by their relations?
    3. Can I run custom queries?
    4. Can I run custom queries and get hydrated objects ?
  5. License

Installation

Install with composer

Example

For more complete examples, please check the examples directory.

Documentation

Model

An entity node must implement the \Neo4j\OGM\Model\EntityInterface interface.

A relationship node must implement the \Neo4j\OGM\Model\RelationshipInterface interface.

If you want the OGM to automatically handle the created and updated time for the nodes, you need to implement:

Annotations

@OGM/Entity

Allows to declare an entity.

Option Description Required Value
label The Neo4j node label yes The label
repository Specify a custom repository to handle this entity no The class name of the custom repository

@OGM/Relationship

Allows to declare a relationship.

Option Description Required Value
type The Neo4j relationship type yes
unique Is this relationship unique between the two entities no true/false (default true)
repository Specify a custom repository to handle this entity no The class name of the custom repository

@OGM/Id

The propery that holds the id generated by Neo4j. Both @OGM\Entity and @OGM\Relationship require the presence of this annotation.

@OGM/StartEntity

Allows to declare the start node of a relationship. @OGM/Relationship requires the presence of this annotation.

Option Description Required
target The entity class yes

@OGM/EndEntity

Allows to declare the end node of a relationship. @OGM/Relationship requires the presence of this annotation.

Option Description Required
target The entity class yes

@OGM/Property

Allows to declare a property to store in Neo4j. It applies to both @OGM/Entity and @OGM/Relationship.

Option Description Required Value
type Enforce the type no One of "string", "boolean", "array", "int", "double"
nullable Can this field be null no true/false (default is true)
key Use this key as the property name on Neo4j no

@OGM/Convert

Convert an @OGM/Property before storing it in Neo4j or when retrieving it from Neo4j. It applies to both @OGM/Entity and @OGM/Relationship.

Option Description Required Value
type The type of conversion yes "datetime" The value will be converted to and from a PHP's DateTime. "datetime_immutable" The value will be converted to and from a PHP's DateTimeImmutable. "json" The value will be converted to and from JSON.
options The options to pass to the converter no See below

Options for "datetime" or "datetime_immutable"

Option Description Required Value
format The storing formate no "timestamp" to store as a unix timestamp, "long_timestamp" to store as unix timestamp but to keep the milliseconds precision, or any valid format
timezone The timezone to apply when loading the value no A valid PHP timezone

@OGM/QueryResult

Run a sub-query and return its result. It only applies to @OGM/Entity.

Option Description Required Value
query The sub query to run yes The query must contain an "{ENTRY}" and an "{OUTPUT}", these two values will be automatically populated at run time
collection The returned value is a collection no true/false (default false)
orderBy How to order the results no An array of fields with the sorting order (ASC/DESC) (See below for details)
limit Limit the results to this number of items no A number (will be forced to 1 when collection is false)

Explanation on "orderBy"

By default orderBy is applied to {OUTPUT}:

@OGM\QueryResult(query="MATCH ({ENTRY})<-[r:ACTED_IN]-(actor:Person) RETURN actor AS {OUTPUT}", collection=true, orderBy={"born"="ASC"})

born is a property of the Person entity identified by actor which is returned as {OUTPUT}.

If you want it to be applied to an intermediate value, you simply need to specify it:

@OGM\QueryResult(query="MATCH ({ENTRY})<-[r:ACTED_IN]-(actor:Person) RETURN actor.name AS {OUTPUT}", collection=true, orderBy={"r.onSetDate"="ASC"})

onSetDate is a property of the ACTED_IN relationship.

@OGM/Relation

Get the associated other entities in a relationship with the entity. It only applies to @OGM/Entity.

Option Description Required Value
relationship The relationship yes The class name of the relationship
direction The direction of the relationship concerning the current entity yes INCOMING when the relationship's @OGM/EndEntity is this entity. OUTGOING when the relationship's @OGM/StartEntity is this entity. BOTH when the relationship goes both ways.
collection The returned value is a collection no true/false (default false)
orderBy How to order the results no An array of fields with the sorting order (ASC/DESC) (See below for details)
limit Limit the results to this number of items no A number (will be forced to 1 when collection is false)
fetch How the relations should be fetched no EAGER to force the loading. LAZY to lazy load (default when collection is false). EXTRA_LAZY to lazy load the whole collection (default when collection is true) (See below for details)
filters Apply basic filters no An array of fields with their expected value (See below for details)

Explanation on "fetch"

  1. EAGER means that all data is queried and loaded. This is very resources consuming, so unless you're absolutely sure you will need the data, avoid using it.

  2. LAZY means only the ids are fetched. The actual real content is loaded the first time you try to access a property. When collection is true, the whole collection is built by the query but only the relations'id are returned. If your collection contains thousands of relations you do not want to use this as it would be very resources consuming.

  3. EXTRA_LAZY only applies when collection is true. The collection is not built by the query, it only gets loaded the first time you try accessing it. When the collection is fetched, the relations it contains are LAZY.

Explanation on "orderBy"

By default orderBy is applied to the other end of the relationship:

@OGM\Relation(relationship=ActedIn::class,direction=Direction::INCOMING,collection=true,limit=2,orderBy={"born"="ASC"})

born is a property of the other end of the ActedIn relationship.

If you want it to be applied to a property of the ActedIn relationship:

@OGM\Relation(relationship=ActedIn::class,direction=Direction::INCOMING,collection=true,limit=2,orderBy={"{RELATIONSHIP}.onSetDate"="ASC"})

onSetDate is a property of the ActedIn relationship.

Explanation on "filters"

Applies basic filters on either the relationsip or on the other end of the relationship.

By default, the filters are applied the other end of the relationship:

@OGM\Relation(relationship=ActedIn::class,direction=Direction::INCOMING,collection=true,limit=2,filters={"gender"="FEMALE"})

gender is a property of the other end of the ActedIn relationship.

If you want a filter to be applied to a property of the ActedIn relationship:

@OGM\Relation(relationship=ActedIn::class,direction=Direction::INCOMING,collection=true,limit=2,filters={"{RELATIONSHIP}.Lorem"="IPSUM"})

Lorem is a property of the ActedIn relationship.

Repository

The default node repository is Neo4j\OGM\Repository\BaseRepository. If you create a custom repository, you either need to extend Neo4j\OGM\Repository\BaseRepository or to implement Neo4j\OGM\Repository\RepositoryInterface.

Events

NodeCreatedEvent

The \Neo4j\OGM\Event\NodeCreatedEvent event is dispatched after a node (@OGM\Entity or @OGM\Relationship) has been created.

NodeUpdatedEvent

The \Neo4j\OGM\Event\NodeUpdatedEvent event is dispatched after a node (@OGM\Entity or @OGM\Relationship) has been updated.

NodeDeletedEvent

The \Neo4j\OGM\Event\NodeDeletedEvent event is dispatched after a node (@OGM\Entity or @OGM\Relationship) has been deleted.

NodeLoadedEvent

The \Neo4j\OGM\Event\NodeLoadedEvent event is dispatched after a node (@OGM\Entity or @OGM\Relationship) has been fully loaded, not its eventual lazy instance.

FAQ

How do I query a node by its Neo4j id?

We've introduced a special operator id() which allows you to query a node by its id.

Can I filter nodes by their relations?

In Doctrine you can easily filter results by their relation, which ends up creating a join for you. Using OGM it's not possible at the time. But we're planning on adding this feature.

Can I run custom queries?

Yes you can. The Neo4j client can be accessed through the NodeManagerInterface::getClient method.

Can I run custom queries and get hydrated objects?

Yes you can. You need to use Neo4j\OGM\Repository\BaseRepository's findByQuery or findOneByQuery method.

License

The library is released under the MIT License, refer to the LICENSE file bundled with this package.


All versions of neo4j-php-ogm with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4
ext-ds Version *
doctrine/common Version ^3.1
laudis/neo4j-php-client Version ^1.3
psr/event-dispatcher Version ^1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package giudicelli/neo4j-php-ogm contains the following files

Loading the files please wait ....