Skip to content

Commit 37c0bf7

Browse files
committed
[FrameworkBundle] Introduce a cache warmer for Serializer based on PhpArrayAdapter
1 parent 62206e0 commit 37c0bf7

File tree

2 files changed

+71
-24
lines changed

2 files changed

+71
-24
lines changed

Mapping/Loader/XmlFileLoader.php

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,11 @@ class XmlFileLoader extends FileLoader
3636
public function loadClassMetadata(ClassMetadataInterface $classMetadata)
3737
{
3838
if (null === $this->classes) {
39-
$this->classes = array();
40-
$xml = $this->parseFile($this->file);
39+
$this->classes = $this->getClassesFromXml();
40+
}
4141

42-
foreach ($xml->class as $class) {
43-
$this->classes[(string) $class['name']] = $class;
44-
}
42+
if (!$this->classes) {
43+
return false;
4544
}
4645

4746
$attributesMetadata = $classMetadata->getAttributesMetadata();
@@ -74,6 +73,20 @@ public function loadClassMetadata(ClassMetadataInterface $classMetadata)
7473
return false;
7574
}
7675

76+
/**
77+
* Return the names of the classes mapped in this file.
78+
*
79+
* @return string[] The classes names
80+
*/
81+
public function getMappedClasses()
82+
{
83+
if (null === $this->classes) {
84+
$this->classes = $this->getClassesFromXml();
85+
}
86+
87+
return array_keys($this->classes);
88+
}
89+
7790
/**
7891
* Parses a XML File.
7992
*
@@ -93,4 +106,16 @@ private function parseFile($file)
93106

94107
return simplexml_import_dom($dom);
95108
}
109+
110+
private function getClassesFromXml()
111+
{
112+
$xml = $this->parseFile($this->file);
113+
$classes = array();
114+
115+
foreach ($xml->class as $class) {
116+
$classes[(string) $class['name']] = $class;
117+
}
118+
119+
return $classes;
120+
}
96121
}

Mapping/Loader/YamlFileLoader.php

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,26 +38,11 @@ class YamlFileLoader extends FileLoader
3838
public function loadClassMetadata(ClassMetadataInterface $classMetadata)
3939
{
4040
if (null === $this->classes) {
41-
if (!stream_is_local($this->file)) {
42-
throw new MappingException(sprintf('This is not a local file "%s".', $this->file));
43-
}
44-
45-
if (null === $this->yamlParser) {
46-
$this->yamlParser = new Parser();
47-
}
48-
49-
$classes = $this->yamlParser->parse(file_get_contents($this->file));
50-
51-
if (empty($classes)) {
52-
return false;
53-
}
54-
55-
// not an array
56-
if (!is_array($classes)) {
57-
throw new MappingException(sprintf('The file "%s" must contain a YAML array.', $this->file));
58-
}
41+
$this->classes = $this->getClassesFromYaml();
42+
}
5943

60-
$this->classes = $classes;
44+
if (!$this->classes) {
45+
return false;
6146
}
6247

6348
if (isset($this->classes[$classMetadata->getName()])) {
@@ -103,4 +88,41 @@ public function loadClassMetadata(ClassMetadataInterface $classMetadata)
10388

10489
return false;
10590
}
91+
92+
/**
93+
* Return the names of the classes mapped in this file.
94+
*
95+
* @return string[] The classes names
96+
*/
97+
public function getMappedClasses()
98+
{
99+
if (null === $this->classes) {
100+
$this->classes = $this->getClassesFromYaml();
101+
}
102+
103+
return array_keys($this->classes);
104+
}
105+
106+
private function getClassesFromYaml()
107+
{
108+
if (!stream_is_local($this->file)) {
109+
throw new MappingException(sprintf('This is not a local file "%s".', $this->file));
110+
}
111+
112+
if (null === $this->yamlParser) {
113+
$this->yamlParser = new Parser();
114+
}
115+
116+
$classes = $this->yamlParser->parse(file_get_contents($this->file));
117+
118+
if (empty($classes)) {
119+
return array();
120+
}
121+
122+
if (!is_array($classes)) {
123+
throw new MappingException(sprintf('The file "%s" must contain a YAML array.', $this->file));
124+
}
125+
126+
return $classes;
127+
}
106128
}

0 commit comments

Comments
 (0)