/** * Tries to identify the class of an rid by matching it against * the clusters in the database * * @param string $rid * * @throws MappingException * @return string */ public function identifyClass($rid) { $map = $this->getMap(); $splitRid = explode(':', ltrim($rid, '#')); $clusterId = $splitRid[0]; foreach ($map as $class => $clusters) { if (in_array($clusterId, $clusters)) { return $class; } } throw MappingException::noClusterForRid($rid); }
/** * Lookup the document class to find methods that match to event lifecycle names * * @param ClassMetadata $metadata The document metadata. * @param string $className The listener class name. * * @throws MappingException When the listener class not found. */ public static function bindDocumentListener(ClassMetadata $metadata, $className) { $class = $metadata->fullyQualifiedClassName($className); if (!class_exists($class)) { throw MappingException::documentListenerClassNotFound($class, $className); } foreach (get_class_methods($class) as $method) { if (!isset(self::$events[$method])) { continue; } $metadata->addDocumentListener($method, $class, $method); } }
/** * Overrides an already defined type to use a different implementation. * * @static * * @param string $name * @param string $className * * @throws MappingException */ public static final function overrideType($name, $className) { if (!isset(self::$typesMap[$name])) { throw MappingException::typeNotFound($name); } self::$typesMap[$name] = $className; }
/** * @param string $className * @param ClassMetadata $metadata * @param DocumentListeners $annot * * @throws MappingException */ private function mapDocumentListeners($className, ClassMetadata $metadata, DocumentListeners $annot) { foreach ($annot->value as $item) { $listenerClassName = $metadata->fullyQualifiedClassName($item); if (!class_exists($listenerClassName)) { throw MappingException::documentListenerClassNotFound($listenerClassName, $className); } $hasMapping = false; $listenerClass = new \ReflectionClass($listenerClassName); /* @var $method \ReflectionMethod */ foreach ($listenerClass->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) { // find method callbacks. $callbacks = $this->getMethodCallbacks($method); $hasMapping = $hasMapping ?: !empty($callbacks); foreach ($callbacks as $value) { $metadata->addDocumentListener($value[1], $listenerClassName, $value[0]); } } // Evaluate the listener using naming convention. if (!$hasMapping) { DocumentListenerBuilder::bindDocumentListener($metadata, $listenerClassName); } } }
/** * @param array $mapping * * @throws MappingException */ private function _validateFieldMapping(array &$mapping) { if (!isset($mapping['fieldName'])) { throw MappingException::missingFieldName($this->name); } if (isset($this->fieldMappings[$mapping['fieldName']])) { throw MappingException::duplicateFieldMapping($this->name, $mapping['fieldName']); } }
/** * Validate runtime metadata is correctly defined. * * @param ClassMetadata $class * @param ClassMetadata|null $parent * * @return void * * @throws MappingException */ protected function validateRuntimeMetadata($class, $parent) { $className = $class->getName(); if ($this->isEntity($class) && empty($class->identifier)) { throw MappingException::missingRidProperty($className); } if ($class->isDocument() && !isset($class->orientClass)) { throw MappingException::missingOClass($className); } }
private function addLinkMapping(ClassMetadata $class, \SimpleXMLElement $embed, $type) { $attributes = $embed->attributes(); $mapping = ['cascade' => isset($embed->cascade) ? $this->_getCascadeMappings($embed->cascade) : []]; $this->_copyCommonPropertyAttributesToMapping($attributes, $mapping); if (isset($attributes['orphan-removal'])) { $mapping['orphanRemoval'] = (string) $attributes['orphan-removal'] === 'true'; } if (isset($attributes['parent-property'])) { $mapping['parentProperty'] = (string) $attributes['parent-property']; } if (isset($attributes['child-property'])) { $mapping['childProperty'] = (string) $attributes['child-property']; } switch ($type) { case 'one': $class->mapLink($mapping); break; case 'list': $class->mapLinkList($mapping); break; case 'set': $class->mapLinkSet($mapping); break; case 'map': $class->mapLinkMap($mapping); break; default: throw MappingException::invalidCollectionType($class->name, $type); } }