コード例 #1
0
 /**
  * Set a given relationship on this relation.
  *
  * @param \Everyman\Neo4j\Relationship $relation
  */
 public function setRelation(Relationship $relation, $debug = false)
 {
     // Set the relation object.
     $this->relation = $relation;
     // Replace the attributes with those brought from the given relation.
     $this->attributes = $relation->getProperties();
     $this->setAttribute($this->primaryKey, $relation->getId());
     // Set the start and end nodes.
     $this->start = $relation->getStartNode();
     $this->end = $relation->getEndNode();
     // Instantiate and fill out the related model.
     $relatedNode = $this->isDirectionOut() ? $this->end : $this->start;
     $attributes = array_merge(['id' => $relatedNode->getId()], $relatedNode->getProperties());
     $this->related = $this->related->newFromBuilder($attributes, $exists = true);
     $this->related->setConnection($this->related->getConnection());
 }
コード例 #2
0
 /**
  * Bootstrap the application events.
  *
  * @return void
  */
 public function boot()
 {
     Model::setConnectionResolver($this->app['db']);
     Model::setEventDispatcher($this->app['events']);
     $this->package('vinelab/neoeloquent');
 }
コード例 #3
0
 /**
  * Add a relationship MATCH clause to the query.
  *
  * @param  \Vinelab\NeoEloquent\Eloquent\Model $parent       The parent model of the relationship
  * @param  \Vinelab\NeoEloquent\Eloquent\Model $related      The related model
  * @param  string $relatedNode  The related node' placeholder
  * @param  string $relationship The relationship title
  * @param  string $property     The parent's property we are matching against
  * @param  string $value
  * @param  string $direction Possible values are in, out and in-out
  * @return \Vinelab\NeoEloquent\Query\Builder|static
  */
 public function matchRelation($parent, $related, $relatedNode, $relationship, $property, $value = null, $direction = 'out')
 {
     $parentLabels = $parent->getTable();
     $relatedLabels = $related->getTable();
     $parentNode = $this->modelAsNode($parentLabels);
     $this->matches[] = array('type' => 'Relation', 'property' => $property, 'direction' => $direction, 'relationship' => $relationship, 'parent' => array('node' => $parentNode, 'labels' => $parentLabels), 'related' => array('node' => $relatedNode, 'labels' => $relatedLabels));
     $this->addBinding(array($this->wrap($property) => $value), 'matches');
     return $this;
 }
コード例 #4
0
 /**
  * Get the direction of a relationship out of a Relation instance.
  *
  * @param  \Everyman\Neo4j\Relationship $relation
  * @param  \Vinelab\NeoEloquent\Eloquent\Model        $parent
  * @param  \Vinelab\NeoEloquent\Eloquent\Model        $related
  * @return string Either 'in' or 'out'
  */
 public function directionFromRelation(Relationship $relation, Model $parent, Model $related)
 {
     // We will match the ids of the parent model and the start node of the relationship
     // and if they match we know that the direction is outgoing, incoming otherwise.
     $node = $relation->getStartNode();
     // We will start by considering the relationship direction to be 'incoming' until
     // we match and find otherwise.
     $direction = 'in';
     if ($node->getId() === $parent->getKey()) {
         $direction = 'out';
     }
     return $direction;
 }
コード例 #5
0
 /**
  * Get migration models label.
  *
  * @return string
  */
 public function getLabel()
 {
     return $this->model->getLabel();
 }
コード例 #6
0
 public static function boot()
 {
     parent::boot();
     // Mock a dispatcher
     $dispatcher = M::mock('OBEventDispatcher');
     $dispatcher->shouldReceive('listen')->andReturnUsing(function ($event, $callback) {
         static::$listenerStub[$event] = $callback;
     });
     $dispatcher->shouldReceive('until')->andReturnUsing(function ($event, $model) {
         if (isset(static::$listenerStub[$event]) and strpos(static::$listenerStub[$event], '@') !== false) {
             list($listener, $method) = explode('@', static::$listenerStub[$event]);
             if (isset(static::$listenerStub[$event])) {
                 call_user_func([$listener, $method], $model);
             }
         } elseif (isset(static::$listenerStub[$event])) {
             call_user_func(static::$listenerStub[$event], $model);
         }
     });
     $dispatcher->shouldReceive('fire')->andReturnUsing(function ($event, $model) {
         if (isset(static::$listenerStub[$event]) and strpos(static::$listenerStub[$event], '@') !== false) {
             list($listener, $method) = explode('@', static::$listenerStub[$event]);
             if (isset(static::$listenerStub[$event])) {
                 call_user_func([$listener, $method], $model);
             }
         } elseif (isset(static::$listenerStub[$event])) {
             call_user_func(static::$listenerStub[$event], $model);
         }
     });
     static::$dispatcher = $dispatcher;
 }
コード例 #7
0
ファイル: Delegate.php プロジェクト: bobflay/NeoEloquent
 /**
  * Convert a model to a Node object.
  *
  * @param  \Vinelab\NeoEloquent\Eloquent\Model $model
  * @return \Everyman\Neo4j\Node
  */
 public function asNode(Model $model)
 {
     $node = $this->client->makeNode();
     // If the key name of the model is 'id' we will need to set it properly with setId()
     // since setting it as a regular property with setProperty() won't cut it.
     if ($model->getKeyName() == 'id') {
         $node->setId($model->getKey());
     } else {
         $node->setProperty($model->getKeyName(), $model->getKey());
     }
     return $node;
 }
 /**
  * Bootstrap the application events.
  *
  * @return void
  */
 public function boot()
 {
     Model::setConnectionResolver($this->app['db']);
     Model::setEventDispatcher($this->app['events']);
 }