public function loadClassMetadata(ClassMetadata $metadata)
{
if (null === $this->classes) {
- // This method may throw an exception. Do not modify the class'
- // state before it completes
- $xml = $this->parseFile($this->file);
-
- $this->classes = array();
-
- foreach ($xml->namespace as $namespace) {
- $this->addNamespaceAlias((string) $namespace['prefix'], trim((string) $namespace));
- }
-
- foreach ($xml->class as $class) {
- $this->classes[(string) $class['name']] = $class;
- }
+ $this->loadClassesFromXml();
}
if (isset($this->classes[$metadata->getClassName()])) {
return false;
}
+ /**
+ * Return the names of the classes mapped in this file.
+ *
+ * @return string[] The classes names
+ */
+ public function getMappedClasses()
+ {
+ if (null === $this->classes) {
+ $this->loadClassesFromXml();
+ }
+
+ return array_keys($this->classes);
+ }
+
/**
* Parses a collection of "constraint" XML nodes.
*
$constraints = array();
foreach ($nodes as $node) {
- if (count($node) > 0) {
- if (count($node->value) > 0) {
+ if (\count($node) > 0) {
+ if (\count($node->value) > 0) {
$options = $this->parseValues($node->value);
- } elseif (count($node->constraint) > 0) {
+ } elseif (\count($node->constraint) > 0) {
$options = $this->parseConstraints($node->constraint);
- } elseif (count($node->option) > 0) {
+ } elseif (\count($node->option) > 0) {
$options = $this->parseOptions($node->option);
} else {
$options = array();
}
- } elseif (strlen((string) $node) > 0) {
+ } elseif (\strlen((string) $node) > 0) {
$options = XmlUtils::phpize(trim($node));
} else {
$options = null;
$values = array();
foreach ($nodes as $node) {
- if (count($node) > 0) {
- if (count($node->value) > 0) {
+ if (\count($node) > 0) {
+ if (\count($node->value) > 0) {
$value = $this->parseValues($node->value);
- } elseif (count($node->constraint) > 0) {
+ } elseif (\count($node->constraint) > 0) {
$value = $this->parseConstraints($node->constraint);
} else {
$value = array();
$options = array();
foreach ($nodes as $node) {
- if (count($node) > 0) {
- if (count($node->value) > 0) {
+ if (\count($node) > 0) {
+ if (\count($node->value) > 0) {
$value = $this->parseValues($node->value);
- } elseif (count($node->constraint) > 0) {
+ } elseif (\count($node->constraint) > 0) {
$value = $this->parseConstraints($node->constraint);
} else {
$value = array();
}
} else {
$value = XmlUtils::phpize($node);
- if (is_string($value)) {
+ if (\is_string($value)) {
$value = trim($value);
}
}
return simplexml_import_dom($dom);
}
+ private function loadClassesFromXml()
+ {
+ // This method may throw an exception. Do not modify the class'
+ // state before it completes
+ $xml = $this->parseFile($this->file);
+
+ $this->classes = array();
+
+ foreach ($xml->namespace as $namespace) {
+ $this->addNamespaceAlias((string) $namespace['prefix'], trim((string) $namespace));
+ }
+
+ foreach ($xml->class as $class) {
+ $this->classes[(string) $class['name']] = $class;
+ }
+ }
+
private function loadClassMetadataFromXml(ClassMetadata $metadata, \SimpleXMLElement $classDescription)
{
- if (count($classDescription->{'group-sequence-provider'}) > 0) {
+ if (\count($classDescription->{'group-sequence-provider'}) > 0) {
$metadata->setGroupSequenceProvider(true);
}
foreach ($classDescription->{'group-sequence'} as $groupSequence) {
- if (count($groupSequence->value) > 0) {
+ if (\count($groupSequence->value) > 0) {
$metadata->setGroupSequence($this->parseValues($groupSequence[0]->value));
}
}