Security update for Core, with self-updated composer
[yaffs-website] / vendor / symfony / serializer / Mapping / Loader / XmlFileLoader.php
index 0da2f7d690ff668a8773208deae31162e4f87c23..76d064326f168b59197d96da802d9ccca9203bb8 100644 (file)
@@ -36,12 +36,11 @@ class XmlFileLoader extends FileLoader
     public function loadClassMetadata(ClassMetadataInterface $classMetadata)
     {
         if (null === $this->classes) {
-            $this->classes = array();
-            $xml = $this->parseFile($this->file);
+            $this->classes = $this->getClassesFromXml();
+        }
 
-            foreach ($xml->class as $class) {
-                $this->classes[(string) $class['name']] = $class;
-            }
+        if (!$this->classes) {
+            return false;
         }
 
         $attributesMetadata = $classMetadata->getAttributesMetadata();
@@ -62,6 +61,10 @@ class XmlFileLoader extends FileLoader
                 foreach ($attribute->group as $group) {
                     $attributeMetadata->addGroup((string) $group);
                 }
+
+                if (isset($attribute['max-depth'])) {
+                    $attributeMetadata->setMaxDepth((int) $attribute['max-depth']);
+                }
             }
 
             return true;
@@ -70,6 +73,20 @@ class XmlFileLoader extends FileLoader
         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->classes = $this->getClassesFromXml();
+        }
+
+        return array_keys($this->classes);
+    }
+
     /**
      * Parses a XML File.
      *
@@ -89,4 +106,16 @@ class XmlFileLoader extends FileLoader
 
         return simplexml_import_dom($dom);
     }
+
+    private function getClassesFromXml()
+    {
+        $xml = $this->parseFile($this->file);
+        $classes = array();
+
+        foreach ($xml->class as $class) {
+            $classes[(string) $class['name']] = $class;
+        }
+
+        return $classes;
+    }
 }