Created
December 7, 2010 17:55
-
-
Save jwage/732140 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace Hydrators; | |
| use Doctrine\ODM\MongoDB\DocumentManager; | |
| use Doctrine\ODM\MongoDB\Mapping\ClassMetadata; | |
| use Doctrine\ODM\MongoDB\Hydrator\HydratorInterface; | |
| use Doctrine\ODM\MongoDB\UnitOfWork; | |
| /** | |
| * THIS CLASS WAS GENERATED BY THE DOCTRINE ODM. DO NOT EDIT THIS FILE. | |
| */ | |
| class DocumentsUserHydrator implements HydratorInterface | |
| { | |
| private $dm; | |
| private $unitOfWork; | |
| private $class; | |
| public function __construct(DocumentManager $dm, UnitOfWork $uow, ClassMetadata $class) | |
| { | |
| $this->dm = $dm; | |
| $this->unitOfWork = $uow; | |
| $this->class = $class; | |
| } | |
| public function hydrate($document, $data) | |
| { | |
| $hydratedData = array(); | |
| /** @Field(type="id") */ | |
| if (isset($data['_id'])) { | |
| $value = $data['_id']; | |
| $return = (string) $value; | |
| $this->class->reflFields['id']->setValue($document, $return); | |
| $hydratedData['id'] = $return; | |
| } | |
| /** @Field(type="string") */ | |
| if (isset($data['username'])) { | |
| $value = $data['username']; | |
| $return = (string) $value; | |
| $this->class->reflFields['username']->setValue($document, $return); | |
| $hydratedData['username'] = $return; | |
| } | |
| /** @Field(type="bin_md5") */ | |
| if (isset($data['password'])) { | |
| $value = $data['password']; | |
| $return = $value !== null ? $value->bin : null; | |
| $this->class->reflFields['password']->setValue($document, $return); | |
| $hydratedData['password'] = $return; | |
| } | |
| /** @Field(type="date") */ | |
| if (isset($data['createdAt'])) { | |
| $value = $data['createdAt']; | |
| if ($value === null) { return null; } if ($value instanceof \MongoDate) { $date = new \DateTime(); $date->setTimestamp($value->sec); $return = $date; } else { $return = new \DateTime($value); } | |
| $this->class->reflFields['createdAt']->setValue($document, $return); | |
| $hydratedData['createdAt'] = $return; | |
| } | |
| /** @EmbedOne */ | |
| if (isset($data['address'])) { | |
| $embeddedDocument = $data['address']; | |
| $className = $this->dm->getClassNameFromDiscriminatorValue($this->class->fieldMappings['address'], $embeddedDocument); | |
| $embeddedMetadata = $this->dm->getClassMetadata($className); | |
| $return = $embeddedMetadata->newInstance(); | |
| $embeddedData = $this->dm->getHydrator()->hydrate($return, $embeddedDocument); | |
| $this->unitOfWork->registerManaged($return, null, $embeddedData); | |
| $this->unitOfWork->setParentAssociation($return, $this->class->fieldMappings['address'], $document, 'address'); | |
| $this->class->reflFields['address']->setValue($document, $return); | |
| $hydratedData['address'] = $return; | |
| } | |
| /** @ReferenceOne */ | |
| if (isset($data['profile'])) { | |
| $reference = $data['profile']; | |
| $className = $this->dm->getClassNameFromDiscriminatorValue($this->class->fieldMappings['profile'], $reference); | |
| $targetMetadata = $this->dm->getClassMetadata($className); | |
| $id = $targetMetadata->getPHPIdentifierValue($reference['$id']); | |
| $return = $this->dm->getReference($className, $id); | |
| $this->class->reflFields['profile']->setValue($document, $return); | |
| $hydratedData['profile'] = $return; | |
| } | |
| /** @Many */ | |
| $mongoData = isset($data['phonenumbers']) ? $data['phonenumbers'] : null; | |
| $return = new \Doctrine\ODM\MongoDB\PersistentCollection(new \Doctrine\Common\Collections\ArrayCollection(), $this->dm, $this->unitOfWork, '$'); | |
| $return->setOwner($document, $this->class->fieldMappings['phonenumbers']); | |
| $return->setInitialized(false); | |
| if ($mongoData) { | |
| $return->setMongoData($mongoData); | |
| } | |
| $this->class->reflFields['phonenumbers']->setValue($document, $return); | |
| $hydratedData['phonenumbers'] = $return; | |
| /** @Many */ | |
| $mongoData = isset($data['groups']) ? $data['groups'] : null; | |
| $return = new \Doctrine\ODM\MongoDB\PersistentCollection(new \Doctrine\Common\Collections\ArrayCollection(), $this->dm, $this->unitOfWork, '$'); | |
| $return->setOwner($document, $this->class->fieldMappings['groups']); | |
| $return->setInitialized(false); | |
| if ($mongoData) { | |
| $return->setMongoData($mongoData); | |
| } | |
| $this->class->reflFields['groups']->setValue($document, $return); | |
| $hydratedData['groups'] = $return; | |
| /** @ReferenceOne */ | |
| if (isset($data['account'])) { | |
| $reference = $data['account']; | |
| $className = $this->dm->getClassNameFromDiscriminatorValue($this->class->fieldMappings['account'], $reference); | |
| $targetMetadata = $this->dm->getClassMetadata($className); | |
| $id = $targetMetadata->getPHPIdentifierValue($reference['$id']); | |
| $return = $this->dm->getReference($className, $id); | |
| $this->class->reflFields['account']->setValue($document, $return); | |
| $hydratedData['account'] = $return; | |
| } | |
| /** @Many */ | |
| $mongoData = isset($data['accounts']) ? $data['accounts'] : null; | |
| $return = new \Doctrine\ODM\MongoDB\PersistentCollection(new \Doctrine\Common\Collections\ArrayCollection(), $this->dm, $this->unitOfWork, '$'); | |
| $return->setOwner($document, $this->class->fieldMappings['accounts']); | |
| $return->setInitialized(false); | |
| if ($mongoData) { | |
| $return->setMongoData($mongoData); | |
| } | |
| $this->class->reflFields['accounts']->setValue($document, $return); | |
| $hydratedData['accounts'] = $return; | |
| /** @Field(type="int") */ | |
| if (isset($data['hits'])) { | |
| $value = $data['hits']; | |
| $return = (int) $value; | |
| $this->class->reflFields['hits']->setValue($document, $return); | |
| $hydratedData['hits'] = $return; | |
| } | |
| /** @Field(type="string") */ | |
| if (isset($data['nullTest'])) { | |
| $value = $data['nullTest']; | |
| $return = (string) $value; | |
| $this->class->reflFields['nullTest']->setValue($document, $return); | |
| $hydratedData['nullTest'] = $return; | |
| } | |
| /** @Field(type="increment") */ | |
| if (isset($data['count'])) { | |
| $value = $data['count']; | |
| $return = $value; | |
| $this->class->reflFields['count']->setValue($document, $return); | |
| $hydratedData['count'] = $return; | |
| } | |
| /** @Field(type="collection") */ | |
| if (isset($data['logs'])) { | |
| $value = $data['logs']; | |
| $return = $value; | |
| $this->class->reflFields['logs']->setValue($document, $return); | |
| $hydratedData['logs'] = $return; | |
| } | |
| /** @Field(type="string") */ | |
| if (isset($data['inheritedProperty'])) { | |
| $value = $data['inheritedProperty']; | |
| $return = (string) $value; | |
| $this->class->reflFields['inheritedProperty']->setValue($document, $return); | |
| $hydratedData['inheritedProperty'] = $return; | |
| } | |
| return $hydratedData; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment