Noticed that the solution posted by Louis-Philippe, after a recent installation, failed to work because the triggerEvent method under the EntityManager class is calling array_shift on the arguments provided. This therefore led to the callback only receiving four of the five required parameters.
$em->registerEvent(HireVoice\Neo4j\EntityManager::RELATION_CREATE, function ($type, $relationName, $from, $to, $relation) {
// $relation is the Everyman\Neo4j\Relationship
if ($relationName === 'GOES_TO_MARKET') {
$relation->setProperty('foobar', 'baz')->save();
}
});
This was fixed by replacing the following: (Note that this hasn't been thoroughly tested and might impact some other parts of the code.)
private function triggerEvent($eventName, $data)
{
if (isset($this->eventHandlers[$eventName])) {
$args = func_get_args();
array_shift($args);
foreach ($this->eventHandlers[$eventName] as $callback) {
$clone = $args;
call_user_func_array($callback, $clone);
}
}
}
by:
private function triggerEvent($eventName, $data)
{
if (isset($this->eventHandlers[$eventName])) {
$args = func_get_args();
foreach ($this->eventHandlers[$eventName] as $callback) {
$clone = $args;
call_user_func_array($callback, $clone);
}
}
}