Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d28a7e2

Browse files
committed
Added support for Yaml
1 parent 0fe9da5 commit d28a7e2

File tree

1 file changed

+77
-1
lines changed

1 file changed

+77
-1
lines changed

src/Symfony/Component/Serializer/Mapping/Loader/YamlFileLoader.php

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ public function loadClassMetadata(ClassMetadataInterface $classMetadata)
5252
}
5353

5454
$yaml = $this->classes[$classMetadata->getName()];
55-
5655
if (isset($yaml['attributes']) && \is_array($yaml['attributes'])) {
5756
$attributesMetadata = $classMetadata->getAttributesMetadata();
5857

@@ -78,14 +77,91 @@ public function loadClassMetadata(ClassMetadataInterface $classMetadata)
7877
}
7978
}
8079

80+
if (isset($data['methods'])) {
81+
if (!\is_array($data['methods'])) {
82+
throw new MappingException(sprintf('The "methods" key must be an array in "%s" for the attribute "%s" of the class "%s".', $this->file, $attribute, $classMetadata->getName()));
83+
}
84+
85+
foreach ($data['methods'] as $methods) {
86+
if (isset($methods['accessor'])) {
87+
if (!\is_string($methods['accessor'])) {
88+
throw new MappingException(sprintf('The value of "methods.accessor" must be a in "%s" for the attribute "%s" of the class "%s".', $this->file, $attribute, $classMetadata->getName()));
89+
}
90+
$attributeMetadata->setMethodsAccessor($methods['accessor']);
91+
}
92+
93+
if (isset($methods['mutator'])) {
94+
if (!\is_string($methods['mutator'])) {
95+
throw new MappingException(sprintf('The value of "methods.mutator" must be a in "%s" for the attribute "%s" of the class "%s".', $this->file, $attribute, $classMetadata->getName()));
96+
}
97+
$attributeMetadata->setMethodsAccessor($methods['mutator']);
98+
}
99+
}
100+
}
101+
102+
if (isset($data['exclude'])) {
103+
if (!\is_bool($data['exclude'])) {
104+
throw new MappingException(sprintf('The "exclude" value must be a boolean in "%s" for the attribute "%s" of the class "%s".', $this->file, $attribute, $classMetadata->getName()));
105+
}
106+
107+
$attributeMetadata->setExclude($data['exclude']);
108+
}
109+
110+
if (isset($data['expose'])) {
111+
if (!\is_bool($data['expose'])) {
112+
throw new MappingException(sprintf('The "expose" value must be a boolean in "%s" for the attribute "%s" of the class "%s".', $this->file, $attribute, $classMetadata->getName()));
113+
}
114+
115+
$attributeMetadata->setExpose($data['expose']);
116+
}
117+
81118
if (isset($data['max_depth'])) {
82119
if (!\is_int($data['max_depth'])) {
83120
throw new MappingException(sprintf('The "max_depth" value must be an integer in "%s" for the attribute "%s" of the class "%s".', $this->file, $attribute, $classMetadata->getName()));
84121
}
85122

86123
$attributeMetadata->setMaxDepth($data['max_depth']);
87124
}
125+
126+
if (isset($data['read_only'])) {
127+
if (!\is_bool($data['read_only'])) {
128+
throw new MappingException(sprintf('The "read_only" value must be a boolean in "%s" for the attribute "%s" of the class "%s".', $this->file, $attribute, $classMetadata->getName()));
129+
}
130+
131+
$attributeMetadata->setReadOnly($data['read_only']);
132+
}
133+
134+
if (isset($data['serialized_name'])) {
135+
if (!\is_string($data['serialized_name'])) {
136+
throw new MappingException(sprintf('The "serialized_name" value must be a string in "%s" for the attribute "%s" of the class "%s".', $this->file, $attribute, $classMetadata->getName()));
137+
}
138+
139+
$attributeMetadata->setReadOnly($data['serialized_name']);
140+
}
141+
142+
if (isset($data['type'])) {
143+
if (!\is_string($data['type'])) {
144+
throw new MappingException(sprintf('The "type" value must be a string in "%s" for the attribute "%s" of the class "%s".', $this->file, $attribute, $classMetadata->getName()));
145+
}
146+
147+
$attributeMetadata->setReadOnly($data['type']);
148+
}
149+
}
150+
}
151+
152+
if (isset($yaml['exclusion_policy'])) {
153+
if (!\is_string($yaml['exclusion_policy'])) {
154+
throw new MappingException(sprintf('The "exclusion_policy" value must be a string in "%s" for the class "%s".', $this->file, $classMetadata->getName()));
88155
}
156+
157+
$classMetadata->setExclusionPolicy($yaml['exclusion_policy']);
158+
}
159+
if (isset($yaml['read_only'])) {
160+
if (!\is_bool($yaml['read_only'])) {
161+
throw new MappingException(sprintf('The "read_only" value must be a boolean in "%s" for the class "%s".', $this->file, $classMetadata->getName()));
162+
}
163+
164+
$classMetadata->setReadOnly($yaml['read_only']);
89165
}
90166

91167
if (isset($yaml['discriminator_map'])) {

0 commit comments

Comments
 (0)