Skip to content

Commit

Permalink
Merge pull request #1331 from malarzm/lifecycle-manager
Browse files Browse the repository at this point in the history
Moved lifecycle callbacks/events logic
  • Loading branch information
malarzm committed Jan 7, 2016
2 parents 2568633 + cd58ce3 commit b12c33d
Show file tree
Hide file tree
Showing 5 changed files with 297 additions and 229 deletions.
5 changes: 3 additions & 2 deletions lib/Doctrine/ODM/MongoDB/Event/PreUpdateEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ class PreUpdateEventArgs extends LifecycleEventArgs
* @param DocumentManager $dm
* @param array $changeSet
*/
public function __construct($document, DocumentManager $dm, array &$changeSet)
public function __construct($document, DocumentManager $dm, array $changeSet)
{
parent::__construct($document, $dm);
$this->documentChangeSet = &$changeSet;
$this->documentChangeSet = $changeSet;
}

/**
Expand Down Expand Up @@ -105,6 +105,7 @@ public function setNewValue($field, $value)
$this->assertValidField($field);

$this->documentChangeSet[$field][1] = $value;
$this->getDocumentManager()->getUnitOfWork()->setDocumentChangeSet($this->getDocument(), $this->documentChangeSet);
}

/**
Expand Down
19 changes: 18 additions & 1 deletion lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadataInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -539,10 +539,14 @@ public function setCustomRepositoryClass($repositoryClassName)
*/
public function invokeLifecycleCallbacks($event, $document, array $arguments = null)
{
if (!$document instanceof $this->name) {
if ( ! $document instanceof $this->name) {
throw new \InvalidArgumentException(sprintf('Expected document class "%s"; found: "%s"', $this->name, get_class($document)));
}

if (empty($this->lifecycleCallbacks[$event])) {
return;
}

foreach ($this->lifecycleCallbacks[$event] as $callback) {
if ($arguments !== null) {
call_user_func_array(array($document, $callback), $arguments);
Expand Down Expand Up @@ -1559,6 +1563,19 @@ public function getFieldMapping($fieldName)
return $this->fieldMappings[$fieldName];
}

/**
* Gets mappings of fields holding embedded document(s).
*
* @return array of field mappings
*/
public function getEmbeddedFieldsMappings()
{
return array_filter(
$this->associationMappings,
function($assoc) { return ! empty($assoc['embedded']); }
);
}

/**
* Check if the field is not null.
*
Expand Down
Loading

0 comments on commit b12c33d

Please sign in to comment.