示例#1
0
 /**
  * Extracts identifiers from object or proxy.
  *
  * @param \Doctrine\ODM\MongoDB\DocumentManager $dm
  * @param object $object
  * @param bool $single
  * @return mixed - array or single identifier
  */
 public function extractIdentifier(DocumentManager $dm, $object, $single = true)
 {
     $meta = $dm->getClassMetadata(get_class($object));
     if ($object instanceof Proxy) {
         $id = $dm->getUnitOfWork()->getDocumentIdentifier($object);
     } else {
         $id = ReflectionProperty::factory($meta->name, $meta->identifier)->getValue($object);
     }
     if ($single || !$id) {
         return $id;
     } else {
         return array($meta->identifier => $id);
     }
 }
示例#2
0
 /**
  * Extracts identifiers from object or proxy.
  *
  * @param \Doctrine\ORM\EntityManager $em
  * @param object $object
  * @param bool $single
  * @return mixed - array or single identifier
  */
 public function extractIdentifier(EntityManager $em, $object, $single = true)
 {
     if ($object instanceof Proxy) {
         $id = $em->getUnitOfWork()->getEntityIdentifier($object);
     } else {
         $meta = $em->getClassMetadata(get_class($object));
         $id = array();
         foreach ($meta->identifier as $name) {
             $id[$name] = ReflectionProperty::factory($meta->name, $name)->getValue($object);
             // return null if one of identifiers is missing
             if (!$id[$name]) {
                 return null;
             }
         }
     }
     if ($single) {
         $id = current($id);
     }
     return $id;
 }
示例#3
0
 public function testGetParentClassPropertiesAndMethods()
 {
     $publicProperty3 = ReflectionProperty::factory('FSi\\Component\\Reflection\\Tests\\Fixture\\ClassA', 'publicProperty3');
     $ClassAParent = ReflectionClass::factory('FSi\\Component\\Reflection\\Tests\\Fixture\\ClassAParent');
     $ClassAParentParent = ReflectionClass::factory('FSi\\Component\\Reflection\\Tests\\Fixture\\ClassAParentParent');
     $ClassAParentProperties = $ClassAParent->getProperties();
     $ClassAParentParentProperties = $ClassAParentParent->getProperties();
     $propertyExists = false;
     foreach ($ClassAParentProperties as $index => $parentProperty) {
         if ($parentProperty->name == $publicProperty3->name) {
             $this->assertSame($parentProperty, $publicProperty3);
             $propertyExists = true;
         }
     }
     $this->assertTrue($propertyExists);
     $propertyExists = false;
     foreach ($ClassAParentParentProperties as $index => $parentParentProperty) {
         if ($parentParentProperty->name == $publicProperty3->name) {
             $this->assertSame($parentParentProperty, $publicProperty3);
             $propertyExists = true;
         }
     }
     $this->assertTrue($propertyExists);
     $publicMethod3 = ReflectionMethod::factory('FSi\\Component\\Reflection\\Tests\\Fixture\\ClassA', 'publicMethod3');
     $ClassAParent = ReflectionClass::factory('FSi\\Component\\Reflection\\Tests\\Fixture\\ClassAParent');
     $ClassAParentParent = ReflectionClass::factory('FSi\\Component\\Reflection\\Tests\\Fixture\\ClassAParentParent');
     $ClassAParentMethods = $ClassAParent->getMethods();
     $ClassAParentParentMethods = $ClassAParentParent->getMethods();
     $methodExists = false;
     foreach ($ClassAParentMethods as $index => $parentMethod) {
         if ($parentMethod->name == $publicMethod3->name) {
             $this->assertSame($parentMethod, $publicMethod3);
             $methodExists = true;
         }
     }
     $this->assertTrue($methodExists);
     $methodExists = false;
     foreach ($ClassAParentParentMethods as $index => $parentParentMethod) {
         if ($parentParentMethod->name == $publicMethod3->name) {
             $this->assertSame($parentParentMethod, $publicMethod3);
             $methodExists = true;
         }
     }
     $this->assertTrue($methodExists);
 }