Actualización

This commit is contained in:
Xes
2025-04-10 12:24:57 +02:00
parent 8969cc929d
commit 45420b6f0d
39760 changed files with 4303286 additions and 0 deletions

View File

@@ -0,0 +1,184 @@
<?php
namespace Gedmo\Mapping\Event\Adapter;
use Gedmo\Mapping\Event\AdapterInterface;
use Gedmo\Exception\RuntimeException;
use Doctrine\Common\EventArgs;
use Doctrine\ODM\MongoDB\DocumentManager;
use Doctrine\ODM\MongoDB\Event\LifecycleEventArgs;
/**
* Doctrine event adapter for ODM specific
* event arguments
*
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
class ODM implements AdapterInterface
{
/**
* @var \Doctrine\Common\EventArgs
*/
private $args;
/**
* @var \Doctrine\ODM\MongoDB\DocumentManager
*/
private $dm;
/**
* {@inheritdoc}
*/
public function setEventArgs(EventArgs $args)
{
$this->args = $args;
}
/**
* {@inheritdoc}
*/
public function getDomainObjectName()
{
return 'Document';
}
/**
* {@inheritdoc}
*/
public function getManagerName()
{
return 'ODM';
}
/**
* {@inheritdoc}
*/
public function getRootObjectClass($meta)
{
return $meta->rootDocumentName;
}
/**
* Set the document manager
*
* @param \Doctrine\ODM\MongoDB\DocumentManager $dm
*/
public function setDocumentManager(DocumentManager $dm)
{
$this->dm = $dm;
}
/**
* {@inheritdoc}
*/
public function getObjectManager()
{
if (!is_null($this->dm)) {
return $this->dm;
}
return $this->__call('getDocumentManager', array());
}
/**
* {@inheritdoc}
*/
public function getObjectState($uow, $object)
{
return $uow->getDocumentState($object);
}
/**
* {@inheritdoc}
*/
public function __call($method, $args)
{
if (is_null($this->args)) {
throw new RuntimeException("Event args must be set before calling its methods");
}
$method = str_replace('Object', $this->getDomainObjectName(), $method);
return call_user_func_array(array($this->args, $method), $args);
}
/**
* {@inheritdoc}
*/
public function getObjectChangeSet($uow, $object)
{
return $uow->getDocumentChangeSet($object);
}
/**
* {@inheritdoc}
*/
public function getSingleIdentifierFieldName($meta)
{
return $meta->identifier;
}
/**
* {@inheritdoc}
*/
public function recomputeSingleObjectChangeSet($uow, $meta, $object)
{
$uow->recomputeSingleDocumentChangeSet($meta, $object);
}
/**
* {@inheritdoc}
*/
public function getScheduledObjectUpdates($uow)
{
$updates = $uow->getScheduledDocumentUpdates();
$upserts = $uow->getScheduledDocumentUpserts();
return array_merge($updates, $upserts);
}
/**
* {@inheritdoc}
*/
public function getScheduledObjectInsertions($uow)
{
return $uow->getScheduledDocumentInsertions();
}
/**
* {@inheritdoc}
*/
public function getScheduledObjectDeletions($uow)
{
return $uow->getScheduledDocumentDeletions();
}
/**
* {@inheritdoc}
*/
public function setOriginalObjectProperty($uow, $oid, $property, $value)
{
$uow->setOriginalDocumentProperty($oid, $property, $value);
}
/**
* {@inheritdoc}
*/
public function clearObjectChangeSet($uow, $oid)
{
$uow->clearDocumentChangeSet($oid);
}
/**
* Creates a ODM specific LifecycleEventArgs.
*
* @param object $document
* @param \Doctrine\ODM\MongoDB\DocumentManager $documentManager
*
* @return \Doctrine\ODM\MongoDB\Event\LifecycleEventArgs
*/
public function createLifecycleEventArgsInstance($document, $documentManager)
{
return new LifecycleEventArgs($document, $documentManager);
}
}

View File

@@ -0,0 +1,181 @@
<?php
namespace Gedmo\Mapping\Event\Adapter;
use Doctrine\ORM\EntityManagerInterface;
use Gedmo\Mapping\Event\AdapterInterface;
use Gedmo\Exception\RuntimeException;
use Doctrine\Common\EventArgs;
use Doctrine\ORM\Event\LifecycleEventArgs;
/**
* Doctrine event adapter for ORM specific
* event arguments
*
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
class ORM implements AdapterInterface
{
/**
* @var \Doctrine\Common\EventArgs
*/
private $args;
/**
* @var \Doctrine\ORM\EntityManagerInterface
*/
private $em;
/**
* {@inheritdoc}
*/
public function setEventArgs(EventArgs $args)
{
$this->args = $args;
}
/**
* {@inheritdoc}
*/
public function getDomainObjectName()
{
return 'Entity';
}
/**
* {@inheritdoc}
*/
public function getManagerName()
{
return 'ORM';
}
/**
* {@inheritdoc}
*/
public function getRootObjectClass($meta)
{
return $meta->rootEntityName;
}
/**
* {@inheritdoc}
*/
public function __call($method, $args)
{
if (is_null($this->args)) {
throw new RuntimeException("Event args must be set before calling its methods");
}
$method = str_replace('Object', $this->getDomainObjectName(), $method);
return call_user_func_array(array($this->args, $method), $args);
}
/**
* Set the entity manager
*
* @param \Doctrine\ORM\EntityManagerInterface $em
*/
public function setEntityManager(EntityManagerInterface $em)
{
$this->em = $em;
}
/**
* {@inheritdoc}
*/
public function getObjectManager()
{
if (!is_null($this->em)) {
return $this->em;
}
return $this->__call('getEntityManager', array());
}
/**
* {@inheritdoc}
*/
public function getObjectState($uow, $object)
{
return $uow->getEntityState($object);
}
/**
* {@inheritdoc}
*/
public function getObjectChangeSet($uow, $object)
{
return $uow->getEntityChangeSet($object);
}
/**
* {@inheritdoc}
*/
public function getSingleIdentifierFieldName($meta)
{
return $meta->getSingleIdentifierFieldName();
}
/**
* {@inheritdoc}
*/
public function recomputeSingleObjectChangeSet($uow, $meta, $object)
{
$uow->recomputeSingleEntityChangeSet($meta, $object);
}
/**
* {@inheritdoc}
*/
public function getScheduledObjectUpdates($uow)
{
return $uow->getScheduledEntityUpdates();
}
/**
* {@inheritdoc}
*/
public function getScheduledObjectInsertions($uow)
{
return $uow->getScheduledEntityInsertions();
}
/**
* {@inheritdoc}
*/
public function getScheduledObjectDeletions($uow)
{
return $uow->getScheduledEntityDeletions();
}
/**
* {@inheritdoc}
*/
public function setOriginalObjectProperty($uow, $oid, $property, $value)
{
$uow->setOriginalEntityProperty($oid, $property, $value);
}
/**
* {@inheritdoc}
*/
public function clearObjectChangeSet($uow, $oid)
{
$uow->clearEntityChangeSet($oid);
}
/**
* Creates a ORM specific LifecycleEventArgs.
*
* @param object $document
* @param \Doctrine\ODM\MongoDB\DocumentManager $documentManager
*
* @return \Doctrine\ODM\MongoDB\Event\LifecycleEventArgs
*/
public function createLifecycleEventArgsInstance($document, $documentManager)
{
return new LifecycleEventArgs($document, $documentManager);
}
}

View File

@@ -0,0 +1,152 @@
<?php
namespace Gedmo\Mapping\Event;
use Doctrine\Common\EventArgs;
use Doctrine\ORM\UnitOfWork;
/**
* Doctrine event adapter interface is used
* to retrieve common functionality for Doctrine
* events
*
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
interface AdapterInterface
{
/**
* Set the eventargs
*
* @param \Doctrine\Common\EventArgs $args
*/
public function setEventArgs(EventArgs $args);
/**
* Call specific method on event args
*
* @param string $method
* @param array $args
*
* @return mixed
*/
public function __call($method, $args);
/**
* Get the name of domain object
*
* @return string
*/
public function getDomainObjectName();
/**
* Get the name of used manager for this
* event adapter
*
* @return string
*/
public function getManagerName();
/**
* Get the root object class, handles inheritance
*
* @param \Doctrine\Common\Persistence\Mapping\ClassMetadata $meta
*
* @return string
*/
public function getRootObjectClass($meta);
/**
* Get used object manager
*
* @return \Doctrine\Common\Persistence\ObjectManager
*/
public function getObjectManager();
/**
* Get object state
*
* @param UnitOfWork $uow
* @param object $object
*
* @return int The document state.
*/
public function getObjectState($uow, $object);
/**
* Get the object changeset from a UnitOfWork
*
* @param UnitOfWork $uow
* @param object $object
*
* @return array
*/
public function getObjectChangeSet($uow, $object);
/**
* Get the single identifier field name
*
* @param \Doctrine\Common\Persistence\Mapping\ClassMetadata $meta
*
* @return string
*/
public function getSingleIdentifierFieldName($meta);
/**
* Recompute the single object changeset from a UnitOfWork
*
* @param UnitOfWork $uow
* @param \Doctrine\Common\Persistence\Mapping\ClassMetadata $meta
* @param object $object
*
* @return void
*/
public function recomputeSingleObjectChangeSet($uow, $meta, $object);
/**
* Get the scheduled object updates from a UnitOfWork
*
* @param UnitOfWork $uow
*
* @return array
*/
public function getScheduledObjectUpdates($uow);
/**
* Get the scheduled object insertions from a UnitOfWork
*
* @param UnitOfWork $uow
*
* @return array
*/
public function getScheduledObjectInsertions($uow);
/**
* Get the scheduled object deletions from a UnitOfWork
*
* @param UnitOfWork $uow
*
* @return array
*/
public function getScheduledObjectDeletions($uow);
/**
* Sets a property value of the original data array of an object
*
* @param UnitOfWork $uow
* @param string $oid
* @param string $property
* @param mixed $value
*
* @return void
*/
public function setOriginalObjectProperty($uow, $oid, $property, $value);
/**
* Clears the property changeset of the object with the given OID.
*
* @param UnitOfWork $uow
* @param string $oid The object's OID.
*/
public function clearObjectChangeSet($uow, $oid);
}