/** * 获取元信息 * @param object|class $inst * @param boolean $record_doc 是否加载注释文本, 如果是 * @param array $select, 只取选中的几个 * @return array */ static function get($inst, $record_doc = false, $select = null) { $reflection = new \ReflectionClass($inst); $reader = new AnnotationReader($reflection); $info = array(); if ($record_doc) { if (false !== ($doc = $reflection->getDocComment())) { $info['doc'] = $doc; } } if ($select !== null) { $select = array_flip($select); } foreach ($reader->getClassAnnotations($reflection, $record_doc) as $id => $ann) { if ($select !== null && !array_key_exists($id, $select)) { continue; } $ann = $ann[0]; //可能有多个重名的, 只取第一个 $info[$id] = $ann; } foreach ($reflection->getMethods() as $method) { foreach ($reader->getMethodAnnotations($method, $record_doc) as $id => $ann) { if ($select !== null && !array_key_exists($id, $select)) { continue; } $ann = $ann[0]; //可能有多个重名的, 只取第一个 $info += array($id => array()); $info[$id][$method->getName()] = $ann; } } foreach ($reflection->getProperties() as $property) { foreach ($reader->getPropertyAnnotations($property, $record_doc) as $id => $ann) { if ($select !== null && !array_key_exists($id, $select)) { continue; } $ann = $ann[0]; //可能有多个重名的, 只取第一个 $info += array($id => array()); $info[$id][$property->getName()] = $ann; } } return $info; }
/** * Whether the class with the specified name is transient. Only non-transient * classes, that is entities and mapped superclasses, should have their metadata loaded. * A class is non-transient if it is annotated with either @Entity or * @MappedSuperclass in the class doc block. * * @param string $className * @return boolean */ public function isTransient($className) { $classAnnotations = $this->reader->getClassAnnotations(new \ReflectionClass($className)); foreach ($classAnnotations as $classAnnotation) { if ($classAnnotation instanceof \Doctrine\ODM\CouchDB\Mapping\Annotations\Document) { return false; } else { if ($classAnnotation instanceof \Doctrine\ODM\CouchDB\Mapping\Annotations\MappedSuperclass) { return false; } else { if ($classAnnotation instanceof \Doctrine\ODM\CouchDB\Mapping\Annotations\EmbeddedDocument) { return false; } } } } return true; }